2020-11-10 17:16:06 +05:00
|
|
|
import React, {useEffect} from 'react';
|
2020-09-27 10:15:19 +05:00
|
|
|
import {Text} from 'react-native';
|
2020-11-10 17:16:06 +05:00
|
|
|
import Animated from 'react-native-reanimated';
|
2020-09-27 10:15:19 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2020-11-10 17:16:06 +05:00
|
|
|
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
|
|
|
|
|
import {eScrollEvent} from '../../utils/Events';
|
2020-11-04 17:35:24 +05:00
|
|
|
import Heading from '../Typography/Heading';
|
2020-05-10 22:17:14 +05:00
|
|
|
|
2020-11-10 17:16:06 +05:00
|
|
|
const opacity = new Animated.Value(0);
|
|
|
|
|
|
2020-11-14 10:09:28 +05:00
|
|
|
let scrollPostions = {};
|
|
|
|
|
|
2020-11-04 09:55:55 +05:00
|
|
|
export const HeaderTitle = () => {
|
2020-11-04 17:35:24 +05:00
|
|
|
const [state] = useTracked();
|
2020-09-27 10:15:19 +05:00
|
|
|
const {colors, headerTextState} = state;
|
|
|
|
|
|
2020-11-10 17:16:06 +05:00
|
|
|
const onScroll = async (y) => {
|
2020-11-14 10:09:28 +05:00
|
|
|
if (typeof y !== 'number') {
|
|
|
|
|
if (y.type === 'back') {
|
|
|
|
|
scrollPostions[y.name] = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (scrollPostions[y.name]) {
|
|
|
|
|
if (scrollPostions[y.name] > 200) {
|
|
|
|
|
opacity.setValue(1);
|
|
|
|
|
} else {
|
|
|
|
|
scrollPostions[y.name] = 0;
|
|
|
|
|
opacity.setValue(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
scrollPostions[y.name] = 0;
|
|
|
|
|
opacity.setValue(0);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 17:16:06 +05:00
|
|
|
if (y > 75) {
|
|
|
|
|
let yVal = y - 75;
|
|
|
|
|
o = yVal / 75;
|
|
|
|
|
opacity.setValue(o);
|
|
|
|
|
} else {
|
|
|
|
|
opacity.setValue(0);
|
|
|
|
|
}
|
2020-11-14 10:09:28 +05:00
|
|
|
scrollPostions[headerTextState.heading] = y;
|
|
|
|
|
|
2020-11-10 17:16:06 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
};
|
2020-11-14 10:09:28 +05:00
|
|
|
}, [headerTextState.heading]);
|
2020-11-10 17:16:06 +05:00
|
|
|
|
2020-05-10 22:17:14 +05:00
|
|
|
return (
|
2020-11-10 17:16:06 +05:00
|
|
|
<Animated.View
|
|
|
|
|
style={{
|
|
|
|
|
opacity: opacity,
|
|
|
|
|
}}>
|
2020-11-04 17:35:24 +05:00
|
|
|
<Heading color={headerTextState.color}>
|
2020-09-09 22:09:57 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
|
|
|
|
}}>
|
|
|
|
|
{headerTextState.heading.slice(0, 1) === '#' ? '#' : null}
|
|
|
|
|
</Text>
|
2020-05-10 22:17:14 +05:00
|
|
|
|
2020-09-09 22:09:57 +05:00
|
|
|
{headerTextState.heading.slice(0, 1) === '#'
|
|
|
|
|
? headerTextState.heading.slice(1)
|
|
|
|
|
: headerTextState.heading}
|
2020-11-04 17:35:24 +05:00
|
|
|
</Heading>
|
2020-11-10 17:16:06 +05:00
|
|
|
</Animated.View>
|
2020-05-10 22:17:14 +05:00
|
|
|
);
|
|
|
|
|
};
|