2022-01-22 12:57:05 +05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-07-09 16:02:44 +05:00
|
|
|
import { Platform, View } from 'react-native';
|
2022-04-24 05:59:14 +05:00
|
|
|
import Animated, { Layout } from 'react-native-reanimated';
|
2022-04-24 16:49:33 +05:00
|
|
|
import Notebook from '../../screens/notebook';
|
2022-04-24 05:59:14 +05:00
|
|
|
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
|
2022-02-28 23:25:18 +05:00
|
|
|
import Navigation from '../../services/navigation';
|
2022-04-24 05:59:14 +05:00
|
|
|
import useNavigationStore from '../../stores/use-navigation-store';
|
|
|
|
|
import { useThemeStore } from '../../stores/use-theme-store';
|
2022-07-10 01:10:41 +05:00
|
|
|
import { COLORS_NOTE } from '../../utils/color-scheme';
|
2022-04-24 05:59:14 +05:00
|
|
|
import { db } from '../../utils/database';
|
|
|
|
|
import { eScrollEvent } from '../../utils/events';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { SIZE } from '../../utils/size';
|
|
|
|
|
import Heading from '../ui/typography/heading';
|
|
|
|
|
import Paragraph from '../ui/typography/paragraph';
|
2020-05-10 22:17:14 +05:00
|
|
|
|
2022-04-24 05:59:14 +05:00
|
|
|
const titleState = {};
|
|
|
|
|
|
|
|
|
|
export const Title = () => {
|
2022-02-28 23:25:18 +05:00
|
|
|
const colors = useThemeStore(state => state.colors);
|
2022-04-24 05:59:14 +05:00
|
|
|
const currentScreen = useNavigationStore(state => state.currentScreen);
|
2022-07-08 18:28:32 +05:00
|
|
|
const isTopic = currentScreen?.name === 'TopicNotes';
|
2022-04-24 05:59:14 +05:00
|
|
|
const [hide, setHide] = useState(isTopic ? true : false);
|
|
|
|
|
const isHidden = titleState[currentScreen.id];
|
2022-07-08 18:28:32 +05:00
|
|
|
console.log(currentScreen, 'header');
|
|
|
|
|
const notebook =
|
|
|
|
|
isTopic && currentScreen.notebookId
|
|
|
|
|
? db.notebooks?.notebook(currentScreen.notebookId)?.data
|
|
|
|
|
: null;
|
2022-04-24 05:59:14 +05:00
|
|
|
const title = currentScreen.title;
|
2022-07-08 19:01:51 +05:00
|
|
|
const isTag = currentScreen?.name === 'TaggedNotes';
|
2021-11-30 13:29:33 +05:00
|
|
|
|
|
|
|
|
const onScroll = data => {
|
2022-04-24 05:59:14 +05:00
|
|
|
if (currentScreen.name !== 'Notebook') {
|
2021-11-30 13:29:33 +05:00
|
|
|
setHide(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (data.y > 150) {
|
2022-04-24 05:59:14 +05:00
|
|
|
if (!hide) return;
|
2021-11-30 13:29:33 +05:00
|
|
|
setHide(false);
|
|
|
|
|
} else {
|
2022-04-24 05:59:14 +05:00
|
|
|
if (hide) return;
|
2021-11-30 13:29:33 +05:00
|
|
|
setHide(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-24 05:59:14 +05:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (currentScreen.name === 'Notebook') {
|
|
|
|
|
let value =
|
|
|
|
|
typeof titleState[currentScreen.id] === 'boolean' ? titleState[currentScreen.id] : true;
|
|
|
|
|
setHide(value);
|
|
|
|
|
} else {
|
|
|
|
|
setHide(titleState[currentScreen.id]);
|
|
|
|
|
}
|
|
|
|
|
}, [currentScreen.id]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
titleState[currentScreen.id] = hide;
|
|
|
|
|
}, [hide]);
|
|
|
|
|
|
2021-11-30 13:29:33 +05:00
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
};
|
2022-04-24 05:59:14 +05:00
|
|
|
}, [hide]);
|
2021-11-30 13:29:33 +05:00
|
|
|
|
|
|
|
|
function navigateToNotebook() {
|
2022-04-24 05:59:14 +05:00
|
|
|
if (!isTopic) return;
|
2022-04-24 16:49:33 +05:00
|
|
|
Notebook.navigate(notebook, true);
|
2021-11-30 13:29:33 +05:00
|
|
|
}
|
2022-07-10 01:10:41 +05:00
|
|
|
console.log('color', currentScreen.color);
|
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,
|
2021-07-28 14:15:20 +05:00
|
|
|
flexDirection: 'row'
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-04-24 05:59:14 +05:00
|
|
|
{!hide && !isHidden ? (
|
2021-11-30 13:29:33 +05:00
|
|
|
<Heading
|
|
|
|
|
onPress={navigateToNotebook}
|
2022-04-24 05:59:14 +05:00
|
|
|
numberOfLines={isTopic ? 2 : 1}
|
|
|
|
|
size={isTopic ? SIZE.md + 2 : SIZE.xl}
|
2021-11-30 13:29:33 +05:00
|
|
|
style={{
|
2022-07-09 16:02:44 +05:00
|
|
|
flexWrap: 'wrap',
|
|
|
|
|
marginTop: Platform.OS === 'ios' ? -1 : 0
|
2021-11-30 13:29:33 +05:00
|
|
|
}}
|
2022-07-10 01:10:41 +05:00
|
|
|
color={currentScreen.color || colors.heading}
|
2022-01-22 12:57:05 +05:00
|
|
|
>
|
2022-04-24 05:59:14 +05:00
|
|
|
{isTopic ? (
|
2021-12-16 10:20:34 +05:00
|
|
|
<Paragraph numberOfLines={1} size={SIZE.xs + 1}>
|
2021-11-30 13:29:33 +05:00
|
|
|
{notebook?.title}
|
|
|
|
|
{'\n'}
|
|
|
|
|
</Paragraph>
|
2021-12-03 09:34:44 +05:00
|
|
|
) : null}
|
2022-04-24 05:59:14 +05:00
|
|
|
{isTag ? (
|
|
|
|
|
<Heading size={isTopic ? SIZE.md + 2 : SIZE.xl} color={colors.accent}>
|
|
|
|
|
#
|
|
|
|
|
</Heading>
|
|
|
|
|
) : null}
|
2022-07-08 19:01:51 +05:00
|
|
|
{title}
|
2020-11-20 01:23:05 +05:00
|
|
|
</Heading>
|
2021-11-30 13:29:33 +05:00
|
|
|
) : null}
|
2021-07-09 12:15:06 +05:00
|
|
|
</View>
|
2020-05-10 22:17:14 +05:00
|
|
|
);
|
|
|
|
|
};
|