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

164 lines
4.6 KiB
JavaScript
Raw Normal View History

2020-01-18 01:04:33 +05:00
import React from 'react';
2020-01-25 23:24:01 +05:00
import {Platform, StatusBar, Text, TouchableOpacity, View} from 'react-native';
2020-01-18 01:04:33 +05:00
import * as Animatable from 'react-native-animatable';
2020-01-25 23:24:01 +05:00
import {DDS} from '../../../App';
2019-11-29 11:31:43 +05:00
import {SIZE, WEIGHT} from '../../common/common';
2020-01-17 21:26:01 +05:00
import {useTracked} from '../../provider';
2020-01-25 23:24:01 +05:00
import {eSendEvent} from '../../services/eventManager';
import {eCloseLoginDialog} from '../../services/events';
2020-01-18 01:04:33 +05:00
import NavigationService from '../../services/NavigationService';
import {SideMenuEvent} from '../../utils/utils';
2020-01-18 18:14:57 +05:00
import {moveNoteHideEvent} from '../DialogManager';
2020-02-11 20:07:36 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-01-27 00:25:19 +05:00
2019-12-06 18:13:15 +05:00
export const Header = ({
heading,
canGoBack = true,
hide,
showSearch,
2019-12-11 15:20:18 +05:00
menu,
2020-01-01 01:26:23 +05:00
verticalMenu = false,
2020-01-18 18:14:57 +05:00
preventDefaultMargins,
navigation = null,
2020-01-23 23:19:47 +05:00
isLoginNavigator,
2020-02-07 00:26:44 +05:00
headerColor,
2019-12-06 18:13:15 +05:00
}) => {
2020-01-17 21:26:01 +05:00
const [state, dispatch] = useTracked();
const {colors} = state;
2019-12-14 16:00:16 +05:00
2019-11-29 11:31:43 +05:00
return (
2020-01-27 14:01:24 +05:00
<View
2019-11-29 11:31:43 +05:00
style={{
flexDirection: 'row',
2019-12-06 18:13:15 +05:00
zIndex: 10,
2019-12-21 09:46:08 +05:00
height: 50,
2020-01-18 18:14:57 +05:00
marginTop:
Platform.OS === 'ios'
? 0
2020-01-23 23:19:47 +05:00
: preventDefaultMargins || isLoginNavigator
2020-01-18 18:14:57 +05:00
? 0
: StatusBar.currentHeight,
2019-12-21 09:46:08 +05:00
marginBottom: 10,
2019-12-06 18:13:15 +05:00
justifyContent: 'space-between',
2019-11-29 11:31:43 +05:00
alignItems: 'center',
2020-01-08 11:25:26 +05:00
paddingHorizontal: 12,
width: '100%',
2019-11-29 11:31:43 +05:00
}}>
2019-12-06 18:13:15 +05:00
<View
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
}}>
{canGoBack ? (
<TouchableOpacity
2019-12-11 15:20:18 +05:00
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
onPress={() => {
2020-01-18 18:14:57 +05:00
if (navigation && preventDefaultMargins) {
if (navigation.state.routeName === 'Folders') {
moveNoteHideEvent();
} else {
navigation.goBack();
}
2020-01-23 23:19:47 +05:00
} else if (navigation && isLoginNavigator) {
if (navigation.state.routeName === 'Login') {
2020-01-25 23:24:01 +05:00
eSendEvent(eCloseLoginDialog);
2020-01-23 23:19:47 +05:00
} else {
navigation.goBack();
}
2020-01-18 18:14:57 +05:00
} else {
NavigationService.goBack();
}
2019-12-11 15:20:18 +05:00
}}
2019-12-06 18:13:15 +05:00
style={{
2020-01-07 16:26:30 +05:00
justifyContent: 'center',
2019-12-11 15:20:18 +05:00
alignItems: 'flex-start',
2019-12-07 12:05:15 +05:00
height: 40,
2020-01-07 16:26:30 +05:00
width: 50,
2019-12-06 18:13:15 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Icon
2019-12-11 15:20:18 +05:00
style={{
2020-01-08 11:31:43 +05:00
marginLeft: -5,
2019-12-11 15:20:18 +05:00
}}
2019-12-07 12:05:15 +05:00
color={colors.pri}
name={'chevron-left'}
2020-01-07 16:26:30 +05:00
size={SIZE.xxxl - 3}
2019-12-07 12:05:15 +05:00
/>
2019-12-06 18:13:15 +05:00
</TouchableOpacity>
) : (
undefined
)}
2020-01-22 02:51:24 +05:00
{menu && !DDS.isTab ? (
2019-12-11 15:20:18 +05:00
<TouchableOpacity
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
onPress={() => {
2020-01-14 17:33:48 +05:00
SideMenuEvent.open();
2019-12-11 15:20:18 +05:00
}}
style={{
2019-12-14 16:00:16 +05:00
justifyContent: 'center',
2019-12-11 15:20:18 +05:00
alignItems: 'flex-start',
height: 40,
2020-01-01 00:04:59 +05:00
width: 60,
2019-12-11 15:20:18 +05:00
}}>
2020-02-11 20:07:36 +05:00
<Icon color={colors.pri} name={'menu'} size={SIZE.xxxl} />
2019-12-11 15:20:18 +05:00
</TouchableOpacity>
) : (
undefined
)}
2019-12-06 18:13:15 +05:00
2019-12-21 09:46:08 +05:00
<Text
2019-12-06 18:13:15 +05:00
style={{
2019-12-21 09:46:08 +05:00
fontSize: SIZE.xl,
2020-02-07 00:26:44 +05:00
color: headerColor ? headerColor : colors.pri,
2019-12-06 18:13:15 +05:00
fontFamily: WEIGHT.bold,
}}>
2020-02-03 12:31:18 +05:00
<Text
style={{
color: colors.accent,
}}>
{heading.slice(0, 1) === '#' ? '#' : null}
</Text>
{heading.slice(0, 1) === '#' ? heading.slice(1) : heading}
2019-12-21 09:46:08 +05:00
</Text>
2019-12-06 18:13:15 +05:00
</View>
2020-01-01 00:04:59 +05:00
<View
2019-12-06 18:13:15 +05:00
style={{
2020-01-01 00:04:59 +05:00
flexDirection: 'row',
alignItems: 'center',
2019-12-06 18:13:15 +05:00
}}>
2020-01-01 00:04:59 +05:00
<Animatable.View
transition="opacity"
useNativeDriver={true}
2020-01-01 00:04:59 +05:00
duration={500}
style={{
opacity: hide ? 1 : 0,
}}>
<TouchableOpacity
onPress={() => showSearch()}
style={{
justifyContent: 'center',
alignItems: 'flex-end',
height: 40,
width: 60,
paddingRight: 0,
}}>
2020-02-11 20:07:36 +05:00
<Icon name={'magnify'} size={SIZE.xl} color={colors.icon} />
2020-01-01 00:04:59 +05:00
</TouchableOpacity>
</Animatable.View>
2020-01-01 01:26:23 +05:00
{verticalMenu ? (
<TouchableOpacity
style={{
justifyContent: 'center',
alignItems: 'flex-end',
height: 40,
width: 60,
}}>
2020-02-11 20:07:36 +05:00
<Icon name="sort" size={SIZE.xl} color={colors.icon} />
2020-01-01 01:26:23 +05:00
</TouchableOpacity>
) : null}
2020-01-01 00:04:59 +05:00
</View>
2020-01-27 14:01:24 +05:00
</View>
2019-11-29 11:31:43 +05:00
);
};