Files
notesnook/apps/mobile/src/components/Dialog/BaseDialog.js

86 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-09-27 13:05:26 +05:00
import React 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-06-07 11:53:27 +05:00
import { useTracked } from '../../provider';
import useIsFloatingKeyboard from '../../utils/use-is-floating-keyboard';
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,
centered = true,
2021-06-16 11:40:09 +05:00
background = null
2020-09-30 15:58:19 +05:00
}) => {
2020-09-27 13:05:26 +05:00
const [state, dispatch] = useTracked();
2021-06-05 21:10:20 +05:00
const floating = useIsFloatingKeyboard();
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();
}
}}
animationType={animation}
2020-09-27 13:05:26 +05:00
onRequestClose={onRequestClose}>
2021-04-08 10:27:47 +05:00
<SafeAreaView
style={{
2021-06-16 11:40:09 +05:00
backgroundColor:background? background : transparent
2021-04-08 10:27:47 +05:00
? 'transparent'
: state.colors.night
? 'rgba(255,255,255,0.15)'
: 'rgba(0,0,0,0.3)',
}}>
2020-11-17 20:17:50 +05:00
<KeyboardAvoidingView
enabled={!floating && Platform.OS === 'ios'}
2021-05-15 10:11:00 +05:00
behavior="padding"
2020-11-17 20:17:50 +05:00
style={[
styles.backdrop,
2021-04-06 13:26:26 +05:00
{
justifyContent: centered ? 'center' : 'flex-start',
},
2020-11-17 20:17:50 +05:00
]}>
<TouchableOpacity
onPress={onRequestClose}
style={styles.overlayButton}
/>
{premium}
2020-09-30 15:58:19 +05:00
2020-11-17 20:17:50 +05:00
{children}
</KeyboardAvoidingView>
</SafeAreaView>
2020-09-27 13:05:26 +05:00
</Modal>
);
};
const styles = StyleSheet.create({
backdrop: {
width: '100%',
height: '100%',
justifyContent: 'center',
alignItems: 'center',
},
overlayButton: {
width: '100%',
height: '100%',
position: 'absolute',
},
});
export default BaseDialog;