2020-09-12 14:32:06 +05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { Keyboard, Text, View } from 'react-native';
|
|
|
|
|
import { useSafeArea } from 'react-native-safe-area-context';
|
2020-05-10 22:14:34 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-09-12 14:32:06 +05:00
|
|
|
import { pv, SIZE, WEIGHT } from '../../common/common';
|
|
|
|
|
import { useTracked } from '../../provider';
|
2020-09-08 22:22:33 +05:00
|
|
|
import {
|
|
|
|
|
DDS,
|
2020-09-12 14:32:06 +05:00
|
|
|
getElevation
|
2020-09-08 22:22:33 +05:00
|
|
|
} from '../../utils/utils';
|
2020-09-12 14:32:06 +05:00
|
|
|
import { PressableButton } from '../PressableButton';
|
2020-05-10 22:14:34 +05:00
|
|
|
|
|
|
|
|
export const ContainerBottomButton = ({root}) => {
|
|
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const {colors} = state;
|
|
|
|
|
const [buttonHide, setButtonHide] = useState(false);
|
|
|
|
|
const insets = useSafeArea();
|
|
|
|
|
let containerBottomButton = root
|
|
|
|
|
? state.containerBottomButton
|
|
|
|
|
: state.indContainerBottomButton;
|
|
|
|
|
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 !containerBottomButton.visible ? null : (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
opacity: buttonHide ? 0 : 1,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
bottom: insets.bottom + 20,
|
|
|
|
|
zIndex: 10,
|
|
|
|
|
transform: [
|
|
|
|
|
{
|
|
|
|
|
translateY: buttonHide ? 200 : 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}}>
|
2020-09-08 22:22:33 +05:00
|
|
|
<PressableButton
|
2020-09-10 10:19:36 +05:00
|
|
|
color={containerBottomButton.color? containerBottomButton.color : colors.accent}
|
|
|
|
|
selectedColor={containerBottomButton.color? containerBottomButton.color : colors.accent}
|
2020-09-08 23:22:30 +05:00
|
|
|
onPress={containerBottomButton.bottomButtonOnPress}>
|
2020-05-10 22:14:34 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-09-06 10:34:54 +05:00
|
|
|
...getElevation(5),
|
2020-05-10 22:14:34 +05:00
|
|
|
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={
|
|
|
|
|
containerBottomButton.bottomButtonText === 'Clear all trash'
|
|
|
|
|
? 'delete'
|
|
|
|
|
: 'plus'
|
|
|
|
|
}
|
|
|
|
|
color="white"
|
|
|
|
|
size={SIZE.xl}
|
|
|
|
|
/>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontSize: SIZE.md,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
textAlignVertical: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
{' ' + containerBottomButton.bottomButtonText}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
2020-09-08 22:22:33 +05:00
|
|
|
</PressableButton>
|
2020-05-10 22:14:34 +05:00
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
};
|