2021-02-17 16:04:51 +05:00
|
|
|
import React from 'react';
|
|
|
|
|
import { View } from 'react-native';
|
|
|
|
|
import { Platform } from 'react-native';
|
2020-12-29 11:24:00 +05:00
|
|
|
import ActionSheet from 'react-native-actions-sheet';
|
2021-02-17 16:04:51 +05:00
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
|
|
import { useTracked } from '../../provider';
|
|
|
|
|
import { DDS } from '../../services/DeviceDetection';
|
|
|
|
|
import { editing } from '../../utils';
|
|
|
|
|
import { hexToRGBA } from '../../utils/ColorUtils';
|
|
|
|
|
import { sleep } from '../../utils/TimeUtils';
|
2021-02-04 14:35:32 +05:00
|
|
|
import {
|
|
|
|
|
EditorWebView,
|
2021-02-17 16:04:51 +05:00
|
|
|
|
|
|
|
|
textInput
|
2021-02-04 14:35:32 +05:00
|
|
|
} from '../../views/Editor/Functions';
|
|
|
|
|
import tiny from '../../views/Editor/tiny/tiny';
|
2021-02-17 16:04:51 +05:00
|
|
|
import { focusEditor } from '../../views/Editor/tiny/toolbar/constants';
|
2021-02-20 15:03:02 +05:00
|
|
|
import { Toast } from '../Toast';
|
2021-02-17 16:04:51 +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,
|
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;
|
2021-02-17 16:04:51 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
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%',
|
2020-12-19 13:15:34 +05:00
|
|
|
borderTopRightRadius: 10,
|
|
|
|
|
borderTopLeftRadius: 10,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
padding: largeTablet ? 8 : 0,
|
|
|
|
|
zIndex: 10,
|
2021-04-22 12:30:21 +05:00
|
|
|
paddingVertical: 10,
|
2020-12-19 13:15:34 +05:00
|
|
|
borderBottomRightRadius: largeTablet ? 10 : 1,
|
|
|
|
|
borderBottomLeftRadius: largeTablet ? 10 : 1,
|
|
|
|
|
marginBottom: largeTablet ? 50 : 0,
|
|
|
|
|
alignSelf: 'center',
|
2021-06-02 17:34:39 +05:00
|
|
|
paddingTop: gestureEnabled ? 10 : 10,
|
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 () => {
|
|
|
|
|
if (editing.isFocused === true) {
|
|
|
|
|
textInput.current?.focus();
|
|
|
|
|
await sleep(10);
|
|
|
|
|
if (editing.focusType == 'editor') {
|
|
|
|
|
focusEditor();
|
|
|
|
|
} else {
|
|
|
|
|
Platform.OS === 'android' && EditorWebView.current.requestFocus();
|
|
|
|
|
tiny.call(EditorWebView, tiny.focusTitle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (onClose) {
|
|
|
|
|
onClose();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-19 13:15:34 +05:00
|
|
|
return (
|
|
|
|
|
<ActionSheet
|
|
|
|
|
ref={fwdRef}
|
2021-02-26 14:29:29 +05:00
|
|
|
hideUnderlay={true}
|
2021-06-07 08:24:38 +05:00
|
|
|
|
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)
|
|
|
|
|
}
|
2021-02-15 11:02:09 +05:00
|
|
|
onOpen={_onOpen}
|
2020-12-19 13:15:34 +05:00
|
|
|
keyboardShouldPersistTaps="always"
|
|
|
|
|
premium={
|
2021-02-20 15:03:02 +05:00
|
|
|
<>
|
|
|
|
|
<Toast context="local" />
|
2020-12-19 13:15:34 +05:00
|
|
|
<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-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}>
|
2020-12-19 13:15:34 +05:00
|
|
|
{children}
|
2021-06-07 09:51:11 +05:00
|
|
|
<View style={{height:Platform.OS === "ios" ? insets.bottom/2 : 20}}/>
|
2020-12-19 13:15:34 +05:00
|
|
|
</ActionSheet>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActionSheetWrapper;
|