2021-04-11 14:04:14 +05:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import Animated, { useValue } from 'react-native-reanimated';
|
2020-12-01 22:52:01 +05:00
|
|
|
import { useTracked } from '../../provider';
|
2021-06-15 23:57:38 +05:00
|
|
|
import { useSettingStore } from '../../provider/stores';
|
2020-12-01 22:52:01 +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
|
|
|
|
2021-06-15 23:57:38 +05:00
|
|
|
export const Title = ({heading,headerColor,screen}) => {
|
2020-11-04 17:35:24 +05:00
|
|
|
const [state] = useTracked();
|
2021-01-12 22:05:28 +05:00
|
|
|
const {colors} = state;
|
2021-06-15 23:57:38 +05:00
|
|
|
const deviceMode = useSettingStore(state => state.deviceMode);
|
2021-07-08 14:21:34 +05:00
|
|
|
const opacity = useValue(deviceMode !== "mobile" || screen === "Settings" ? 1 : 0)
|
2020-09-27 10:15:19 +05:00
|
|
|
|
2021-04-11 14:04:14 +05:00
|
|
|
const onScroll = async (data) => {
|
2021-07-08 14:21:34 +05:00
|
|
|
if (data.screen === "Settings") return;
|
2021-04-11 14:04:14 +05:00
|
|
|
if (data.screen !== screen) return;
|
2021-06-15 23:57:38 +05:00
|
|
|
if (deviceMode !== "mobile") return;
|
2021-04-11 14:04:14 +05:00
|
|
|
if (data.y > 75) {
|
|
|
|
|
let yVal = data.y - 75;
|
2020-11-10 17:16:06 +05:00
|
|
|
o = yVal / 75;
|
|
|
|
|
opacity.setValue(o);
|
|
|
|
|
} else {
|
|
|
|
|
opacity.setValue(0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
};
|
2021-04-09 10:27:46 +05:00
|
|
|
}, [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-06-15 23:57:38 +05:00
|
|
|
opacity: deviceMode !== "mobile" ? 1 : opacity,
|
2020-11-10 17:16:06 +05:00
|
|
|
}}>
|
2021-04-09 10:27:46 +05:00
|
|
|
<Heading color={headerColor}>
|
2020-11-20 01:23:05 +05:00
|
|
|
<Heading color={colors.accent}>
|
2021-04-09 10:27:46 +05:00
|
|
|
{heading.slice(0, 1) === '#' ? '#' : null}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Heading>
|
2020-05-10 22:17:14 +05:00
|
|
|
|
2021-04-09 10:27:46 +05:00
|
|
|
{heading.slice(0, 1) === '#'
|
|
|
|
|
? heading.slice(1)
|
|
|
|
|
: 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
|
|
|
);
|
|
|
|
|
};
|