2020-11-14 10:42:48 +05:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import { Keyboard, Platform, View } from 'react-native';
|
|
|
|
|
import Animated, { Easing } from 'react-native-reanimated';
|
|
|
|
|
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-11-14 10:42:48 +05:00
|
|
|
import { useTracked } from '../../provider';
|
|
|
|
|
import { DDS } from '../../services/DeviceDetection';
|
|
|
|
|
import { getElevation, showContext } from '../../utils';
|
|
|
|
|
import { normalize, SIZE } from '../../utils/SizeUtils';
|
|
|
|
|
import { PressableButton } from '../PressableButton';
|
2020-05-10 22:14:34 +05:00
|
|
|
|
2020-11-09 17:32:31 +05:00
|
|
|
const translateY = new Animated.Value(0);
|
2020-10-03 12:03:15 +05:00
|
|
|
export const ContainerBottomButton = ({title, onPress, color}) => {
|
2020-11-04 20:29:45 +05:00
|
|
|
const [state] = useTracked();
|
|
|
|
|
const {colors} = state;
|
|
|
|
|
const insets = useSafeAreaInsets();
|
2020-09-27 10:15:19 +05:00
|
|
|
|
2020-11-09 17:32:31 +05:00
|
|
|
function animate(translate) {
|
|
|
|
|
Animated.timing(translateY, {
|
|
|
|
|
toValue: translate,
|
|
|
|
|
duration: 250,
|
|
|
|
|
easing: Easing.elastic(1),
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onKeyboardHide = async () => {
|
2020-11-04 20:29:45 +05:00
|
|
|
if (DDS.isTab) return;
|
2020-11-09 17:32:31 +05:00
|
|
|
animate(0);
|
2020-11-04 20:29:45 +05:00
|
|
|
};
|
2020-11-03 10:02:09 +05:00
|
|
|
|
2020-11-09 17:32:31 +05:00
|
|
|
const onKeyboardShow = async () => {
|
2020-11-04 20:29:45 +05:00
|
|
|
if (DDS.isTab) return;
|
2020-11-09 17:32:31 +05:00
|
|
|
animate(150);
|
2020-11-04 20:29:45 +05:00
|
|
|
};
|
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 (
|
2020-11-09 17:32:31 +05:00
|
|
|
<Animated.View
|
2020-11-04 20:29:45 +05:00
|
|
|
style={{
|
|
|
|
|
position: 'absolute',
|
2020-11-09 17:32:31 +05:00
|
|
|
right: 12,
|
|
|
|
|
bottom: Platform.OS === 'ios' ? insets.bottom - 10 : insets.bottom + 12,
|
2020-11-04 20:29:45 +05:00
|
|
|
zIndex: 10,
|
|
|
|
|
transform: [
|
|
|
|
|
{
|
2020-11-09 17:32:31 +05:00
|
|
|
translateY: translateY,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
translateX: translateY,
|
2020-11-04 20:29:45 +05:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}}>
|
|
|
|
|
<PressableButton
|
|
|
|
|
testID={'container_bottom_btn'}
|
|
|
|
|
color={color || colors.accent}
|
|
|
|
|
selectedColor={color || colors.accent}
|
|
|
|
|
customStyle={{
|
|
|
|
|
...getElevation(5),
|
2020-11-14 10:05:21 +05:00
|
|
|
borderRadius: 100,
|
2020-11-04 20:29:45 +05:00
|
|
|
}}
|
2020-11-14 10:05:21 +05:00
|
|
|
onLongPress={(event) => {
|
|
|
|
|
console.log(event);
|
|
|
|
|
showContext(event, title);
|
2020-11-09 17:32:31 +05:00
|
|
|
}}
|
2020-11-04 20:29:45 +05:00
|
|
|
onPress={onPress}>
|
2020-05-10 22:14:34 +05:00
|
|
|
<View
|
2020-11-04 20:29:45 +05:00
|
|
|
style={{
|
|
|
|
|
alignItems: 'center',
|
2020-11-09 17:32:31 +05:00
|
|
|
justifyContent: 'center',
|
2020-11-04 20:29:45 +05:00
|
|
|
width: '100%',
|
|
|
|
|
height: normalize(60),
|
2020-11-09 17:32:31 +05:00
|
|
|
width: normalize(60),
|
2020-11-04 20:29:45 +05:00
|
|
|
}}>
|
|
|
|
|
<Icon
|
|
|
|
|
name={title === 'Clear all trash' ? 'delete' : 'plus'}
|
|
|
|
|
color="white"
|
2020-11-10 17:18:19 +05:00
|
|
|
size={SIZE.xxl}
|
2020-11-04 20:29:45 +05:00
|
|
|
/>
|
2020-05-10 22:14:34 +05:00
|
|
|
</View>
|
2020-11-04 20:29:45 +05:00
|
|
|
</PressableButton>
|
2020-11-09 17:32:31 +05:00
|
|
|
</Animated.View>
|
2020-11-04 20:29:45 +05:00
|
|
|
);
|
2020-05-10 22:14:34 +05:00
|
|
|
};
|