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

82 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-01-22 12:57:05 +05:00
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
2022-02-28 23:25:18 +05:00
import { useThemeStore } from '../../stores/theme';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
2022-02-28 13:48:59 +05:00
import { eOnNewTopicAdded, eScrollEvent } from '../../utils/events';
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-01-22 12:57:05 +05:00
export const Title = ({ heading, headerColor, screen, notebook }) => {
2022-02-28 23:25:18 +05:00
const colors = useThemeStore(state => state.colors);
const [hide, setHide] = useState(screen === 'Notebook' ? true : false);
const onScroll = data => {
if (screen !== 'Notebook') {
setHide(false);
return;
}
if (data.y > 150) {
setHide(false);
} else {
setHide(true);
}
};
useEffect(() => {
eSubscribeEvent(eScrollEvent, onScroll);
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
};
}, []);
function navigateToNotebook() {
if (!notebook) return;
let routeName = 'Notebook';
let params = {
menu: false,
notebook: notebook,
title: notebook.title
};
let headerState = {
heading: notebook.title,
id: notebook.id,
type: notebook.type
};
eSendEvent(eOnNewTopicAdded, params);
Navigation.navigate(routeName, params, headerState);
}
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,
2021-07-28 14:15:20 +05:00
flexDirection: 'row'
2022-01-22 12:57:05 +05:00
}}
>
{!hide ? (
<Heading
onPress={navigateToNotebook}
numberOfLines={notebook ? 2 : 1}
size={notebook ? SIZE.md + 2 : SIZE.xl}
style={{
flexWrap: 'wrap'
}}
2022-01-22 12:57:05 +05:00
color={headerColor}
>
2021-12-03 09:34:44 +05:00
{notebook ? (
2021-12-16 10:20:34 +05:00
<Paragraph numberOfLines={1} size={SIZE.xs + 1}>
{notebook?.title}
{'\n'}
</Paragraph>
2021-12-03 09:34:44 +05:00
) : null}
2022-01-22 12:57:05 +05:00
<Heading color={colors.accent}>{heading.slice(0, 1) === '#' ? '#' : null}</Heading>
{heading.slice(0, 1) === '#' ? heading.slice(1) : heading}
2020-11-20 01:23:05 +05:00
</Heading>
) : null}
2021-07-09 12:15:06 +05:00
</View>
2020-05-10 22:17:14 +05:00
);
};