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

87 lines
2.2 KiB
JavaScript
Raw Normal View History

import React, {useEffect, useState} from 'react';
2021-07-09 12:15:06 +05:00
import {View} from 'react-native';
import {useTracked} from '../../provider';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent
} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {eOnNewTopicAdded, eScrollEvent} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
2020-11-04 17:35:24 +05:00
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
2020-05-10 22:17:14 +05:00
export const Title = ({heading, headerColor, screen, notebook}) => {
2020-11-04 17:35:24 +05:00
const [state] = useTracked();
2021-01-12 22:05:28 +05:00
const {colors} = state;
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'
2020-11-10 17:16:06 +05:00
}}>
{!hide ? (
<Heading
onPress={navigateToNotebook}
numberOfLines={notebook ? 2 : 1}
size={notebook ? SIZE.md + 2 : SIZE.xl}
style={{
flexWrap: 'wrap'
}}
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}
<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
);
};