import React, { useMemo } from 'react'
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native'
import Modal from './Modal'
import { Icon } from '@/components/common/Icon'
import { useGetter } from '@/store'
import { useKeyboard } from '@/utils/hooks'
import StatusBar from '@/components/common/StatusBar'
const styles = StyleSheet.create({
centeredView: {
flex: 1,
// justifyContent: 'flex-end',
// alignItems: 'center',
},
modalView: {
elevation: 6,
flexGrow: 0,
flexShrink: 1,
},
header: {
flex: 0,
flexDirection: 'row',
borderTopLeftRadius: 8,
borderTopRightRadius: 8,
},
title: {
fontSize: 13,
paddingLeft: 10,
paddingRight: 25,
paddingTop: 10,
paddingBottom: 10,
// lineHeight: 20,
},
closeBtn: {
position: 'absolute',
right: 0,
// borderTopRightRadius: 8,
flexGrow: 0,
flexShrink: 0,
height: 30,
width: 30,
justifyContent: 'center',
alignItems: 'center',
// backgroundColor: '#eee',
},
})
export default ({
visible = false,
hide = () => {},
keyHide = true,
bgHide = true,
closeBtn = true,
position = 'bottom',
title = '',
children,
}) => {
const theme = useGetter('common', 'theme')
const { keyboardShown, keyboardHeight } = useKeyboard()
const closeBtnComponent = useMemo(() => closeBtn ? : null, [closeBtn, hide, theme])
const [centeredViewStyle, modalViewStyle] = useMemo(() => {
switch (position) {
case 'top':
return [
{ justifyContent: 'flex-start' },
{
width: '100%',
maxHeight: '78%',
minHeight: '20%',
backgroundColor: 'white',
paddingTop: StatusBar.currentHeight,
},
]
case 'left':
return [
{ flexDirection: 'row', justifyContent: 'flex-start' },
{
minWidth: '45%',
maxWidth: '78%',
height: '100%',
backgroundColor: 'white',
paddingTop: StatusBar.currentHeight,
},
]
case 'right':
return [
{ flexDirection: 'row', justifyContent: 'flex-end' },
{
minWidth: '45%',
maxWidth: '78%',
height: '100%',
backgroundColor: 'white',
paddingTop: StatusBar.currentHeight,
},
]
case 'bottom':
default:
return [
{ justifyContent: 'flex-end' },
{
width: '100%',
maxHeight: '78%',
minHeight: '20%',
backgroundColor: 'white',
borderTopLeftRadius: 8,
borderTopRightRadius: 8,
},
]
}
}, [position])
return (
true}>
{title}
{closeBtnComponent}
{children}
)
}