2021-01-12 22:05:28 +05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-11-10 17:16:06 +05:00
|
|
|
import Animated from 'react-native-reanimated';
|
2020-12-01 22:52:01 +05:00
|
|
|
import { useTracked } from '../../provider';
|
|
|
|
|
import { DDS } from '../../services/DeviceDetection';
|
|
|
|
|
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
|
2021-01-12 22:05:28 +05:00
|
|
|
import Navigation from '../../services/Navigation';
|
2020-12-01 22:52:01 +05:00
|
|
|
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-20 01:23:05 +05:00
|
|
|
const opacity = new Animated.Value(DDS.isLargeTablet() ? 1 : 0);
|
2020-11-10 17:16:06 +05:00
|
|
|
|
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();
|
2021-01-12 22:05:28 +05:00
|
|
|
const {colors} = state;
|
|
|
|
|
const [headerTextState, setHeaderTextState] = useState(Navigation.getHeaderState());
|
|
|
|
|
|
|
|
|
|
const onHeaderStateChange = (event) => {
|
2021-02-20 14:52:12 +05:00
|
|
|
setHeaderTextState(event);
|
2021-01-12 22:05:28 +05:00
|
|
|
};
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2020-09-27 10:15:19 +05:00
|
|
|
|
2020-11-10 17:16:06 +05:00
|
|
|
const onScroll = async (y) => {
|
2021-02-23 10:58:16 +05:00
|
|
|
if (DDS.isTab) return;
|
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);
|
|
|
|
|
}
|
2021-01-12 22:05:28 +05:00
|
|
|
scrollPostions[headerTextState?.heading] = y;
|
2020-11-10 17:16:06 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
};
|
2021-01-12 22:05:28 +05:00
|
|
|
}, [headerTextState?.heading]);
|
2021-01-10 10:31:16 +05:00
|
|
|
|
2020-05-10 22:17:14 +05:00
|
|
|
return (
|
2020-11-10 17:16:06 +05:00
|
|
|
<Animated.View
|
|
|
|
|
style={{
|
2021-02-23 00:57:03 +05:00
|
|
|
opacity: DDS.isTab ? 1 : opacity,
|
2020-11-10 17:16:06 +05:00
|
|
|
}}>
|
2021-02-08 14:06:57 +05:00
|
|
|
<Heading color={headerTextState?.color}>
|
2020-11-20 01:23:05 +05:00
|
|
|
<Heading color={colors.accent}>
|
2021-02-08 14:06:57 +05:00
|
|
|
{headerTextState?.heading.slice(0, 1) === '#' ? '#' : null}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Heading>
|
2020-05-10 22:17:14 +05:00
|
|
|
|
2021-02-08 14:06: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
|
|
|
);
|
|
|
|
|
};
|