2020-12-19 13:15:34 +05:00
|
|
|
import React from 'react';
|
2020-12-29 11:24:00 +05:00
|
|
|
import {Platform} from 'react-native';
|
|
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {DDS} from '../../services/DeviceDetection';
|
|
|
|
|
import {hexToRGBA} from '../../utils/ColorUtils';
|
|
|
|
|
import ActionSheet from 'react-native-actions-sheet';
|
|
|
|
|
import {GetPremium} from './GetPremium';
|
2021-01-09 11:14:55 +05:00
|
|
|
import { editing } from '../../utils';
|
|
|
|
|
import { post } from '../../views/Editor/Functions';
|
2020-12-19 13:15:34 +05:00
|
|
|
|
|
|
|
|
const ActionSheetWrapper = ({
|
|
|
|
|
children,
|
|
|
|
|
fwdRef,
|
2020-12-19 13:59:41 +05:00
|
|
|
gestureEnabled = true,
|
2020-12-19 13:15:34 +05:00
|
|
|
onClose,
|
|
|
|
|
onOpen,
|
2020-12-19 13:59:41 +05:00
|
|
|
closeOnTouchBackdrop = true,
|
2020-12-19 13:15:34 +05:00
|
|
|
}) => {
|
|
|
|
|
const [state] = useTracked();
|
|
|
|
|
const {colors} = state;
|
|
|
|
|
const largeTablet = DDS.isLargeTablet();
|
2020-12-19 14:26:44 +05:00
|
|
|
const smallTablet = DDS.isTab;
|
2020-12-19 13:15:34 +05:00
|
|
|
|
|
|
|
|
const style = React.useMemo(() => {
|
|
|
|
|
return {
|
2020-12-19 14:26:44 +05:00
|
|
|
width: largeTablet || smallTablet ? 500 : '100%',
|
|
|
|
|
maxHeight: largeTablet ? 500 : '100%',
|
2020-12-19 13:15:34 +05:00
|
|
|
borderTopRightRadius: 10,
|
|
|
|
|
borderTopLeftRadius: 10,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
padding: largeTablet ? 8 : 0,
|
|
|
|
|
zIndex: 10,
|
|
|
|
|
paddingVertical: 12,
|
|
|
|
|
borderBottomRightRadius: largeTablet ? 10 : 1,
|
|
|
|
|
borderBottomLeftRadius: largeTablet ? 10 : 1,
|
|
|
|
|
marginBottom: largeTablet ? 50 : 0,
|
|
|
|
|
alignSelf: 'center',
|
2020-12-29 11:24:00 +05:00
|
|
|
paddingTop: gestureEnabled ? 8 : 18,
|
2020-12-19 13:15:34 +05:00
|
|
|
};
|
2020-12-29 11:24:00 +05:00
|
|
|
}, [colors.bg, gestureEnabled]);
|
2020-12-19 13:15:34 +05:00
|
|
|
|
2021-01-09 11:14:55 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-19 13:15:34 +05:00
|
|
|
return (
|
|
|
|
|
<ActionSheet
|
|
|
|
|
ref={fwdRef}
|
2020-12-29 17:18:44 +05:00
|
|
|
hideUnderlay={largeTablet || smallTablet ? true : false}
|
2020-12-19 13:15:34 +05:00
|
|
|
containerStyle={style}
|
|
|
|
|
gestureEnabled={gestureEnabled}
|
|
|
|
|
extraScroll={largeTablet ? 50 : 0}
|
2020-12-19 13:59:41 +05:00
|
|
|
initialOffsetFromBottom={1}
|
|
|
|
|
closeOnTouchBackdrop={closeOnTouchBackdrop}
|
2020-12-19 13:15:34 +05:00
|
|
|
indicatorColor={
|
|
|
|
|
Platform.OS === 'ios'
|
|
|
|
|
? hexToRGBA(colors.accent + '19')
|
|
|
|
|
: hexToRGBA(colors.shade)
|
|
|
|
|
}
|
|
|
|
|
onOpen={onOpen}
|
|
|
|
|
keyboardShouldPersistTaps="always"
|
|
|
|
|
premium={
|
|
|
|
|
<GetPremium
|
|
|
|
|
context="sheet"
|
2020-12-29 11:24:00 +05:00
|
|
|
close={() => fwdRef?.current?.hide()}
|
2020-12-19 13:15:34 +05:00
|
|
|
offset={50}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2021-01-09 11:14:55 +05:00
|
|
|
onClose={() => {
|
|
|
|
|
if (editing.isFocused) {
|
|
|
|
|
post('blur');
|
|
|
|
|
if (editing.focusType == "editor") {
|
|
|
|
|
post('focusEditor');
|
|
|
|
|
} else {
|
|
|
|
|
post('focusTitle');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (onClose) {
|
|
|
|
|
onClose()
|
|
|
|
|
}
|
|
|
|
|
} }>
|
2020-12-19 13:15:34 +05:00
|
|
|
{children}
|
|
|
|
|
</ActionSheet>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActionSheetWrapper;
|