Files
notesnook/apps/mobile/src/components/Header/HeaderTitle.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

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-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) => {
if (y > 75) {
let yVal = y - 75;
o = yVal / 75;
opacity.setValue(o);
} else {
opacity.setValue(0);
}
};
useEffect(() => {
eSubscribeEvent(eScrollEvent, onScroll);
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
};
}, []);
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
);
};