2022-08-29 16:19:17 +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,
|
2022-02-07 14:44:48 +05:00
|
|
|
TouchableOpacity,
|
|
|
|
|
View
|
2022-08-26 16:19:39 +05:00
|
|
|
} from "react-native";
|
|
|
|
|
import useIsFloatingKeyboard from "../../hooks/use-is-floating-keyboard";
|
2022-08-29 16:19:17 +05:00
|
|
|
import { useSettingStore } from "../../stores/use-setting-store";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { BouncingView } from "../ui/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,
|
2022-08-26 16:19:39 +05:00
|
|
|
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,
|
2022-01-08 00:35:52 +05:00
|
|
|
bounce = true,
|
2022-02-07 14:44:48 +05:00
|
|
|
closeOnTouch = true,
|
|
|
|
|
useSafeArea = true
|
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);
|
2022-01-02 02:05:09 +05:00
|
|
|
};
|
|
|
|
|
}, []);
|
2021-12-27 18:09:00 +05:00
|
|
|
|
2022-02-07 14:44:48 +05:00
|
|
|
const Wrapper = useSafeArea ? SafeAreaView : View;
|
|
|
|
|
|
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}
|
2022-01-12 21:41:44 +05:00
|
|
|
supportedOrientations={[
|
2022-08-26 16:19:39 +05:00
|
|
|
"portrait",
|
|
|
|
|
"portrait-upside-down",
|
|
|
|
|
"landscape",
|
|
|
|
|
"landscape-left",
|
|
|
|
|
"landscape-right"
|
2022-01-12 21:41:44 +05:00
|
|
|
]}
|
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={() => {
|
2022-01-02 02:05:09 +05:00
|
|
|
if (!closeOnTouch) return null;
|
2021-12-27 18:09:00 +05:00
|
|
|
useSettingStore.getState().setSheetKeyboardHandler(true);
|
|
|
|
|
onRequestClose && onRequestClose();
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-02-07 14:44:48 +05:00
|
|
|
<Wrapper
|
2021-04-21 12:30:58 +05:00
|
|
|
style={{
|
2022-08-26 16:19:39 +05:00
|
|
|
backgroundColor: background
|
|
|
|
|
? background
|
|
|
|
|
: transparent
|
|
|
|
|
? "transparent"
|
|
|
|
|
: "rgba(0,0,0,0.3)"
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-08-26 16:19:39 +05:00
|
|
|
<KeyboardAvoidingView
|
|
|
|
|
enabled={!floating && Platform.OS === "ios"}
|
|
|
|
|
behavior="padding"
|
|
|
|
|
>
|
2021-11-08 15:06:46 +05:00
|
|
|
<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,
|
|
|
|
|
{
|
2022-08-26 16:19:39 +05:00
|
|
|
justifyContent: centered
|
|
|
|
|
? "center"
|
|
|
|
|
: bottom
|
|
|
|
|
? "flex-end"
|
|
|
|
|
: "flex-start"
|
2021-11-08 15:06:46 +05:00
|
|
|
}
|
2022-01-22 12:57:05 +05:00
|
|
|
]}
|
|
|
|
|
>
|
2021-11-11 13:08:39 +05:00
|
|
|
<TouchableOpacity
|
2022-01-02 02:02:18 +05:00
|
|
|
onPress={closeOnTouch ? onRequestClose : null}
|
2021-11-11 13:08:39 +05:00
|
|
|
style={styles.overlayButton}
|
|
|
|
|
/>
|
|
|
|
|
{premium}
|
2021-11-08 15:06:46 +05:00
|
|
|
{children}
|
|
|
|
|
</BouncingView>
|
2020-11-17 20:17:50 +05:00
|
|
|
</KeyboardAvoidingView>
|
2022-02-07 14:44:48 +05:00
|
|
|
</Wrapper>
|
2020-09-27 13:05:26 +05:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
backdrop: {
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center"
|
2020-09-27 13:05:26 +05:00
|
|
|
},
|
|
|
|
|
overlayButton: {
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
position: "absolute"
|
2021-11-08 15:06:46 +05:00
|
|
|
}
|
2020-09-27 13:05:26 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default BaseDialog;
|