2021-02-17 16:04:51 +05:00
|
|
|
import React from 'react';
|
2021-07-24 13:16:09 +05:00
|
|
|
import { Platform, View } from 'react-native';
|
2020-12-29 11:24:00 +05:00
|
|
|
import ActionSheet from 'react-native-actions-sheet';
|
2021-07-24 13:16:09 +05:00
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
|
|
import { useTracked } from '../../provider';
|
|
|
|
|
import { useSettingStore } from '../../provider/stores';
|
|
|
|
|
import { hexToRGBA } from '../../utils/ColorUtils';
|
2021-10-20 14:48:52 +05:00
|
|
|
import { reFocusEditor } from '../../views/Editor/tiny/toolbar/constants';
|
2021-07-24 13:16:09 +05:00
|
|
|
import { Toast } from '../Toast';
|
2021-10-20 14:48:52 +05:00
|
|
|
import { BouncingView } from './BouncingView';
|
2021-07-24 13:16:09 +05:00
|
|
|
import { GetPremium } from './GetPremium';
|
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,
|
2021-07-10 14:23:30 +05:00
|
|
|
onHasReachedTop,
|
2021-07-24 13:16:09 +05:00
|
|
|
keyboardMode
|
2020-12-19 13:15:34 +05:00
|
|
|
}) => {
|
|
|
|
|
const [state] = useTracked();
|
|
|
|
|
const {colors} = state;
|
2021-06-13 14:59:09 +05:00
|
|
|
const deviceMode = useSettingStore(state => state.deviceMode);
|
2021-07-10 14:23:30 +05:00
|
|
|
const largeTablet = deviceMode === 'tablet';
|
|
|
|
|
const smallTablet = deviceMode === 'smallTablet';
|
2021-07-24 11:02:45 +05:00
|
|
|
const dimensions = useSettingStore(state => state.dimensions);
|
2021-02-17 16:04:51 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
2021-07-24 11:02:45 +05:00
|
|
|
|
|
|
|
|
let width = dimensions.width > 600 ? 600 : 500;
|
|
|
|
|
|
2020-12-19 13:15:34 +05:00
|
|
|
const style = React.useMemo(() => {
|
|
|
|
|
return {
|
2021-07-24 11:02:45 +05:00
|
|
|
width: largeTablet || smallTablet ? width : '100%',
|
2020-12-19 13:15:34 +05:00
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
zIndex: 10,
|
2021-07-10 14:23:30 +05:00
|
|
|
paddingTop: 10,
|
|
|
|
|
paddingBottom: 0,
|
2021-06-13 14:59:09 +05:00
|
|
|
borderTopRightRadius: 10,
|
|
|
|
|
borderTopLeftRadius: 10,
|
2020-12-19 13:15:34 +05:00
|
|
|
alignSelf: 'center',
|
2021-07-25 01:13:58 +05:00
|
|
|
borderBottomRightRadius: 0,
|
|
|
|
|
borderBottomLeftRadius: 0
|
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-02-15 11:02:09 +05:00
|
|
|
const _onOpen = () => {
|
|
|
|
|
onOpen && onOpen();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const _onClose = async () => {
|
2021-10-21 13:19:34 +05:00
|
|
|
//await reFocusEditor();
|
2021-02-15 11:02:09 +05:00
|
|
|
if (onClose) {
|
|
|
|
|
onClose();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-19 13:15:34 +05:00
|
|
|
return (
|
|
|
|
|
<ActionSheet
|
|
|
|
|
ref={fwdRef}
|
2021-06-11 10:38:14 +05:00
|
|
|
drawUnderStatusBar={false}
|
2020-12-19 13:15:34 +05:00
|
|
|
containerStyle={style}
|
|
|
|
|
gestureEnabled={gestureEnabled}
|
2020-12-19 13:59:41 +05:00
|
|
|
initialOffsetFromBottom={1}
|
2021-07-07 12:54:48 +05:00
|
|
|
onPositionChanged={onHasReachedTop}
|
2020-12-19 13:59:41 +05:00
|
|
|
closeOnTouchBackdrop={closeOnTouchBackdrop}
|
2021-07-10 14:23:30 +05:00
|
|
|
keyboardMode={keyboardMode}
|
|
|
|
|
closeOnPressBack={closeOnTouchBackdrop}
|
2020-12-19 13:15:34 +05:00
|
|
|
indicatorColor={
|
|
|
|
|
Platform.OS === 'ios'
|
|
|
|
|
? hexToRGBA(colors.accent + '19')
|
|
|
|
|
: hexToRGBA(colors.shade)
|
|
|
|
|
}
|
2021-02-15 11:02:09 +05:00
|
|
|
onOpen={_onOpen}
|
2020-12-19 13:15:34 +05:00
|
|
|
keyboardShouldPersistTaps="always"
|
2021-08-03 11:17:06 +05:00
|
|
|
ExtraOverlayComponent={
|
2021-02-20 15:03:02 +05:00
|
|
|
<>
|
2021-06-11 10:38:14 +05:00
|
|
|
<Toast context="local" />
|
|
|
|
|
<GetPremium
|
|
|
|
|
context="sheet"
|
|
|
|
|
close={() => fwdRef?.current?.hide()}
|
|
|
|
|
offset={50}
|
|
|
|
|
/>
|
2021-02-20 15:03:02 +05:00
|
|
|
</>
|
2020-12-19 13:15:34 +05:00
|
|
|
}
|
2021-02-15 11:02:09 +05:00
|
|
|
onClose={_onClose}>
|
2021-10-20 14:48:52 +05:00
|
|
|
<BouncingView>
|
|
|
|
|
{children}
|
2021-10-26 12:11:05 +05:00
|
|
|
<View style={{height: Platform.OS === 'ios' ? insets.bottom / 2 : 20}} />
|
2021-10-20 14:48:52 +05:00
|
|
|
</BouncingView>
|
2020-12-19 13:15:34 +05:00
|
|
|
</ActionSheet>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActionSheetWrapper;
|