2021-12-27 18:09:00 +05:00
|
|
|
import React, { useEffect } from 'react';
|
2020-09-30 15:58:19 +05:00
|
|
|
import {
|
2020-11-17 20:17:50 +05:00
|
|
|
KeyboardAvoidingView,
|
2020-09-30 15:58:19 +05:00
|
|
|
Modal,
|
2020-11-17 20:17:50 +05:00
|
|
|
Platform,
|
|
|
|
|
SafeAreaView,
|
2020-09-30 15:58:19 +05:00
|
|
|
StyleSheet,
|
2021-06-07 11:53:27 +05:00
|
|
|
TouchableOpacity
|
2020-09-30 15:58:19 +05:00
|
|
|
} from 'react-native';
|
2021-12-27 18:09:00 +05:00
|
|
|
import {useSettingStore} from '../../provider/stores';
|
2021-04-21 12:30:58 +05:00
|
|
|
import useIsFloatingKeyboard from '../../utils/use-is-floating-keyboard';
|
2021-12-27 18:09:00 +05:00
|
|
|
import {BouncingView} from '../Transitions/bouncing-view';
|
2020-09-27 13:05:26 +05:00
|
|
|
|
2020-09-30 15:58:19 +05:00
|
|
|
const BaseDialog = ({
|
|
|
|
|
visible,
|
|
|
|
|
onRequestClose,
|
|
|
|
|
children,
|
|
|
|
|
onShow,
|
|
|
|
|
animation = 'fade',
|
2020-11-17 20:17:50 +05:00
|
|
|
premium,
|
2021-01-14 18:58:29 +05:00
|
|
|
statusBarTranslucent = true,
|
|
|
|
|
transparent,
|
2021-04-21 12:30:58 +05:00
|
|
|
centered = true,
|
2021-07-19 09:44:02 +05:00
|
|
|
bottom = false,
|
2021-11-22 15:12:26 +05:00
|
|
|
background = null,
|
2021-12-31 15:05:30 +05:00
|
|
|
animated = true,
|
|
|
|
|
bounce
|
2020-09-30 15:58:19 +05:00
|
|
|
}) => {
|
2021-04-21 12:30:58 +05:00
|
|
|
const floating = useIsFloatingKeyboard();
|
2021-11-08 15:06:46 +05:00
|
|
|
|
2021-12-27 18:09:00 +05:00
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
useSettingStore.getState().setSheetKeyboardHandler(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},[])
|
|
|
|
|
|
2020-09-27 13:05:26 +05:00
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
visible={visible}
|
|
|
|
|
transparent={true}
|
|
|
|
|
animated
|
2020-11-25 11:46:44 +05:00
|
|
|
statusBarTranslucent={statusBarTranslucent}
|
2020-09-30 15:58:19 +05:00
|
|
|
onShow={() => {
|
|
|
|
|
if (onShow) {
|
|
|
|
|
onShow();
|
2021-12-27 18:09:00 +05:00
|
|
|
useSettingStore.getState().setSheetKeyboardHandler(false);
|
2020-09-30 15:58:19 +05:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
animationType={animation}
|
2021-12-27 18:09:00 +05:00
|
|
|
onRequestClose={() => {
|
|
|
|
|
useSettingStore.getState().setSheetKeyboardHandler(true);
|
|
|
|
|
onRequestClose && onRequestClose();
|
|
|
|
|
}}>
|
2021-04-08 10:27:47 +05:00
|
|
|
<SafeAreaView
|
2021-04-21 12:30:58 +05:00
|
|
|
style={{
|
2021-11-08 15:06:46 +05:00
|
|
|
backgroundColor: background
|
|
|
|
|
? background
|
|
|
|
|
: transparent
|
2021-04-08 10:27:47 +05:00
|
|
|
? 'transparent'
|
2021-11-08 15:06:46 +05:00
|
|
|
: 'rgba(0,0,0,0.3)'
|
2021-04-21 12:30:58 +05:00
|
|
|
}}>
|
2020-11-17 20:17:50 +05:00
|
|
|
<KeyboardAvoidingView
|
2021-04-21 12:30:58 +05:00
|
|
|
enabled={!floating && Platform.OS === 'ios'}
|
2021-11-08 15:06:46 +05:00
|
|
|
behavior="padding">
|
|
|
|
|
<BouncingView
|
2021-11-11 13:08:39 +05:00
|
|
|
duration={400}
|
2021-11-22 15:12:26 +05:00
|
|
|
animated={animated}
|
2021-12-31 15:05:30 +05:00
|
|
|
initialScale={bounce ? 0.9 : 1}
|
2021-11-08 15:06:46 +05:00
|
|
|
style={[
|
|
|
|
|
styles.backdrop,
|
|
|
|
|
{
|
|
|
|
|
justifyContent: centered
|
|
|
|
|
? 'center'
|
|
|
|
|
: bottom
|
|
|
|
|
? 'flex-end'
|
|
|
|
|
: 'flex-start'
|
|
|
|
|
}
|
|
|
|
|
]}>
|
2021-11-11 13:08:39 +05:00
|
|
|
<TouchableOpacity
|
|
|
|
|
onPress={onRequestClose}
|
|
|
|
|
style={styles.overlayButton}
|
|
|
|
|
/>
|
|
|
|
|
{premium}
|
2021-11-08 15:06:46 +05:00
|
|
|
{children}
|
|
|
|
|
</BouncingView>
|
2020-11-17 20:17:50 +05:00
|
|
|
</KeyboardAvoidingView>
|
|
|
|
|
</SafeAreaView>
|
2020-09-27 13:05:26 +05:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
backdrop: {
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
justifyContent: 'center',
|
2021-11-08 15:06:46 +05:00
|
|
|
alignItems: 'center'
|
2020-09-27 13:05:26 +05:00
|
|
|
},
|
|
|
|
|
overlayButton: {
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2021-11-11 13:08:39 +05:00
|
|
|
position: 'absolute'
|
2021-11-08 15:06:46 +05:00
|
|
|
}
|
2020-09-27 13:05:26 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default BaseDialog;
|