Files
notesnook/apps/mobile/src/components/Container/ContainerBottomButton.js

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-09-13 09:57:54 +05:00
import React, {useEffect, useState} from 'react';
2020-10-12 11:23:10 +05:00
import {Keyboard, Platform, Text, View} from 'react-native';
2020-09-27 10:15:19 +05:00
import {useSafeAreaInsets} from 'react-native-safe-area-context';
2020-05-10 22:14:34 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-09-13 09:57:54 +05:00
import {useTracked} from '../../provider';
2020-10-13 17:02:14 +05:00
import {getElevation} from '../../utils';
2020-09-13 09:57:54 +05:00
import {PressableButton} from '../PressableButton';
2020-11-04 20:29:45 +05:00
import {normalize, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
import {DDS} from '../../services/DeviceDetection';
2020-05-10 22:14:34 +05:00
export const ContainerBottomButton = ({title, onPress, color}) => {
2020-11-04 20:29:45 +05:00
const [state] = useTracked();
const {colors} = state;
const [buttonHide, setButtonHide] = useState(false);
const insets = useSafeAreaInsets();
2020-09-27 10:15:19 +05:00
2020-11-04 20:29:45 +05:00
const onKeyboardHide = () => {
if (DDS.isTab) return;
setButtonHide(false);
};
2020-11-03 10:02:09 +05:00
2020-11-04 20:29:45 +05:00
const onKeyboardShow = () => {
if (DDS.isTab) return;
setButtonHide(true);
};
2020-11-03 10:02:09 +05:00
2020-11-04 20:29:45 +05:00
useEffect(() => {
Keyboard.addListener('keyboardDidShow', onKeyboardShow);
Keyboard.addListener('keyboardDidHide', onKeyboardHide);
return () => {
Keyboard.removeListener('keyboardDidShow', onKeyboardShow);
Keyboard.removeListener('keyboardDidHide', onKeyboardHide);
};
}, []);
2020-05-10 22:14:34 +05:00
2020-11-04 20:29:45 +05:00
return (
<View
style={{
width: '100%',
opacity: buttonHide ? 0 : 1,
position: 'absolute',
paddingHorizontal: 12,
bottom: Platform.OS === 'ios' ? insets.bottom - 10 : insets.bottom + 20,
zIndex: 10,
transform: [
{
translateY: buttonHide ? 200 : 0,
},
],
}}>
<PressableButton
testID={'container_bottom_btn'}
color={color || colors.accent}
selectedColor={color || colors.accent}
customStyle={{
...getElevation(5),
}}
onPress={onPress}>
2020-05-10 22:14:34 +05:00
<View
2020-11-04 20:29:45 +05:00
style={{
justifyContent: 'flex-start',
alignItems: 'center',
flexDirection: 'row',
width: '100%',
padding: pv,
borderRadius: 5,
height: normalize(60),
}}>
<Icon
name={title === 'Clear all trash' ? 'delete' : 'plus'}
color="white"
size={SIZE.xl}
/>
<Text
testID="container_bottom_btn_text"
2020-05-10 22:14:34 +05:00
style={{
2020-11-04 20:29:45 +05:00
fontSize: SIZE.md,
color: 'white',
fontFamily: WEIGHT.regular,
textAlignVertical: 'center',
2020-05-10 22:14:34 +05:00
}}>
2020-11-04 20:29:45 +05:00
{' ' + title}
</Text>
2020-05-10 22:14:34 +05:00
</View>
2020-11-04 20:29:45 +05:00
</PressableButton>
</View>
);
2020-05-10 22:14:34 +05:00
};