Files
notesnook/apps/mobile/src/components/ActionSheetComponent/ActionSheetWrapper.js

98 lines
2.7 KiB
JavaScript
Raw Normal View History

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 { editing } from '../../utils';
import { hexToRGBA } from '../../utils/ColorUtils';
import { sleep } from '../../utils/TimeUtils';
import { EditorWebView, textInput } from '../../views/Editor/Functions';
import tiny from '../../views/Editor/tiny/tiny';
2021-08-03 10:26:27 +05:00
import { focusEditor, reFocusEditor } from '../../views/Editor/tiny/toolbar/constants';
2021-07-24 13:16:09 +05:00
import { Toast } from '../Toast';
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';
const dimensions = useSettingStore(state => state.dimensions);
2021-02-17 16:04:51 +05:00
const insets = useSafeAreaInsets();
let width = dimensions.width > 600 ? 600 : 500;
2020-12-19 13:15:34 +05:00
const style = React.useMemo(() => {
return {
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-08-03 10:26:27 +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"
premium={
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}>
2020-12-19 13:15:34 +05:00
{children}
2021-07-10 14:23:30 +05:00
<View style={{height: Platform.OS === 'ios' ? insets.bottom / 2 : 0}} />
2020-12-19 13:15:34 +05:00
</ActionSheet>
);
};
export default ActionSheetWrapper;