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

92 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-09-13 09:57:54 +05:00
import React, {useEffect, useState} from 'react';
2020-11-09 17:32:31 +05:00
import {Keyboard, Platform, Text, UIManager, 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-11-09 17:32:31 +05:00
import {getElevation, showContext} 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-11-09 17:32:31 +05:00
import {sleep} from '../../utils/TimeUtils';
import Animated, {Easing} from 'react-native-reanimated';
2020-05-10 22:14:34 +05:00
2020-11-09 17:32:31 +05:00
const translateY = new Animated.Value(0);
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-09 17:32:31 +05:00
onLongPress={event => {
console.log(event)
showContext(event,title);
}}
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
};