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

98 lines
2.7 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 {pv, SIZE, WEIGHT} from '../../common/common';
import {useTracked} from '../../provider';
import {DDS, getElevation} from '../../utils/utils';
import {PressableButton} from '../PressableButton';
2020-05-10 22:14:34 +05:00
export const ContainerBottomButton = ({title, onPress, color}) => {
2020-05-10 22:14:34 +05:00
const [state, dispatch] = useTracked();
const {colors} = state;
2020-05-10 22:14:34 +05:00
const [buttonHide, setButtonHide] = useState(false);
2020-09-27 10:15:19 +05:00
const insets = useSafeAreaInsets();
2020-05-10 22:14:34 +05:00
useEffect(() => {
Keyboard.addListener('keyboardDidShow', () => {
setTimeout(() => {
if (DDS.isTab) return;
setButtonHide(true);
}, 300);
});
Keyboard.addListener('keyboardDidHide', () => {
setTimeout(() => {
if (DDS.isTab) return;
setButtonHide(false);
}, 0);
});
return () => {
Keyboard.removeListener('keyboardDidShow', () => {
setTimeout(() => {
if (DDS.isTab) return;
setButtonHide(true);
}, 300);
});
Keyboard.removeListener('keyboardDidHide', () => {
setTimeout(() => {
if (DDS.isTab) return;
setButtonHide(false);
}, 0);
});
};
}, []);
return (
2020-05-10 22:14:34 +05:00
<View
style={{
width: '100%',
opacity: buttonHide ? 0 : 1,
position: 'absolute',
paddingHorizontal: 12,
2020-10-12 11:23:10 +05:00
bottom: Platform.OS === 'ios' ? insets.bottom - 10 : insets.bottom + 20,
2020-05-10 22:14:34 +05:00
zIndex: 10,
transform: [
{
translateY: buttonHide ? 200 : 0,
},
],
}}>
2020-09-08 22:22:33 +05:00
<PressableButton
testID={'container_bottom_btn'}
color={color || colors.accent}
selectedColor={color || colors.accent}
2020-09-13 09:57:54 +05:00
customStyle={{
...getElevation(5),
}}
onPress={onPress}>
2020-05-10 22:14:34 +05:00
<View
style={{
justifyContent: 'flex-start',
alignItems: 'center',
flexDirection: 'row',
width: '100%',
padding: pv,
2020-09-08 22:22:33 +05:00
borderRadius: 5,
2020-05-10 22:14:34 +05:00
paddingVertical: pv + 5,
}}>
<Icon
name={title === 'Clear all trash' ? 'delete' : 'plus'}
2020-05-10 22:14:34 +05:00
color="white"
size={SIZE.xl}
/>
<Text
2020-09-28 09:50:12 +05:00
testID="container_bottom_btn_text"
2020-05-10 22:14:34 +05:00
style={{
fontSize: SIZE.md,
color: 'white',
fontFamily: WEIGHT.regular,
textAlignVertical: 'center',
}}>
{' ' + title}
2020-05-10 22:14:34 +05:00
</Text>
</View>
2020-09-08 22:22:33 +05:00
</PressableButton>
2020-05-10 22:14:34 +05:00
</View>
);
};