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

106 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-11-20 01:20:59 +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-12-01 17:51:39 +05:00
import {notesnook} from '../../../e2e/test.ids';
2020-11-20 01:20:59 +05:00
import {useTracked} from '../../provider';
import {DDS} from '../../services/DeviceDetection';
2021-06-05 01:35:58 +05:00
import {editing, getElevation, showContext, showTooltip, TOOLTIP_POSITIONS} from '../../utils';
2020-11-20 01:20:59 +05:00
import {normalize, SIZE} from '../../utils/SizeUtils';
import {PressableButton} from '../PressableButton';
2020-12-29 11:49:41 +05:00
import RNTooltips from 'react-native-tooltips';
2021-06-08 12:26:55 +05:00
import { useSettingStore } from '../../provider/stores';
2020-05-10 22:14:34 +05:00
2021-03-06 14:35:37 +05:00
const translateY = new Animated.Value(0);
2020-12-01 17:51:39 +05:00
export const ContainerBottomButton = ({
title,
onPress,
color = 'accent',
shouldShow = false,
}) => {
2020-11-04 20:29:45 +05:00
const insets = useSafeAreaInsets();
2021-06-08 12:26:55 +05:00
const deviceMode = useSettingStore(state => state.deviceMode)
2021-03-06 14:35:37 +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 () => {
2021-06-05 01:35:58 +05:00
console.log('called hide')
editing.keyboardState = false;
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 () => {
2021-06-05 01:35:58 +05:00
console.log('called show');
editing.keyboardState = true;
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);
};
}, []);
2021-03-06 14:35:37 +05:00
2021-06-08 12:26:55 +05:00
return deviceMode !== "mobile" && !shouldShow ? null : (
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 !== 0
2021-04-09 10:27:46 +05:00
? Platform.isPad ? insets.bottom - 12 : insets.bottom - 24
: insets.bottom + 12,
2020-11-04 20:29:45 +05:00
zIndex: 10,
2021-03-06 14:35:37 +05:00
transform: [
2020-11-04 20:29:45 +05:00
{
2020-11-09 17:32:31 +05:00
translateY: translateY,
},
{
translateX: translateY,
2020-11-04 20:29:45 +05:00
},
2021-03-06 14:35:37 +05:00
],
2020-11-04 20:29:45 +05:00
}}>
<PressableButton
2020-12-01 17:51:39 +05:00
testID={notesnook.ids.default.addBtn}
type="accent"
accentColor={color || 'accent'}
accentText="light"
2020-11-04 20:29:45 +05:00
customStyle={{
...getElevation(5),
2020-11-14 10:05:21 +05:00
borderRadius: 100,
2020-11-04 20:29:45 +05:00
}}
2020-12-29 11:49:41 +05:00
onLongPress={(event) => {
showTooltip(event,title,TOOLTIP_POSITIONS.LEFT)
}}
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
};