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

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-07-09 12:15:06 +05:00
import React, {useEffect} from 'react';
import {View} from 'react-native';
import {useValue} from 'react-native-reanimated';
import {useTracked} from '../../provider';
import {useSettingStore} from '../../provider/stores';
2020-11-04 17:35:24 +05:00
import Heading from '../Typography/Heading';
2020-05-10 22:17:14 +05:00
2021-07-09 12:15:06 +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-09 12:15:06 +05:00
const opacity = useValue(1);
2020-09-27 10:15:19 +05:00
2021-07-09 12:15:06 +05:00
const onScroll = async data => {
if (data.screen === 'Settings') return;
2021-04-11 14:04:14 +05:00
if (data.screen !== screen) return;
2021-07-09 12:15:06 +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(() => {
2021-07-09 12:15:06 +05:00
//eSubscribeEvent(eScrollEvent, onScroll);
2020-11-10 17:16:06 +05:00
return () => {
2021-07-09 12:15:06 +05:00
//eUnSubscribeEvent(eScrollEvent, onScroll);
2020-11-10 17:16:06 +05:00
};
2021-07-09 12:15:06 +05:00
}, []);
2020-05-10 22:17:14 +05:00
return (
2021-07-09 12:15:06 +05:00
<View
2020-11-10 17:16:06 +05:00
style={{
2021-07-09 12:15:06 +05:00
opacity: 1,
flexShrink: 1,
flexDirection: 'row',
2020-11-10 17:16:06 +05:00
}}>
2021-07-09 12:15:06 +05:00
<Heading
numberOfLines={1}
style={{
flexWrap: 'wrap',
}}
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>
2021-07-09 12:15:06 +05:00
{heading.slice(0, 1) === '#' ? heading.slice(1) : heading}
2020-11-04 17:35:24 +05:00
</Heading>
2021-07-09 12:15:06 +05:00
</View>
2020-05-10 22:17:14 +05:00
);
};