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-10-13 17:02:14 +05:00
|
|
|
import {pv, SIZE, WEIGHT} from "../../utils/SizeUtils";
|
|
|
|
|
import {DDS} from "../../services/DeviceDetection";
|
2020-05-10 22:14:34 +05:00
|
|
|
|
2020-10-03 12:03:15 +05:00
|
|
|
export const ContainerBottomButton = ({title, onPress, color}) => {
|
2020-05-10 22:14:34 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
2020-10-03 12:03:15 +05:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2020-10-03 12:03:15 +05:00
|
|
|
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
|
2020-10-03 12:03:15 +05:00
|
|
|
testID={'container_bottom_btn'}
|
|
|
|
|
color={color || colors.accent}
|
|
|
|
|
selectedColor={color || colors.accent}
|
2020-09-13 09:57:54 +05:00
|
|
|
customStyle={{
|
|
|
|
|
...getElevation(5),
|
|
|
|
|
}}
|
2020-10-03 12:03:15 +05:00
|
|
|
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
|
2020-10-03 12:03:15 +05:00
|
|
|
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',
|
|
|
|
|
}}>
|
2020-10-03 12:03:15 +05:00
|
|
|
{' ' + 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>
|
|
|
|
|
);
|
|
|
|
|
};
|