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

99 lines
2.8 KiB
JavaScript
Raw Normal View History

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-14 14:36:33 +05:00
import {editing} from '../../utils';
import {EditorWebView, post, textInput} from '../../views/Editor/Functions';
import {sleep} from '../../utils/TimeUtils';
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
return (
<ActionSheet
ref={fwdRef}
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-14 14:36:33 +05:00
onClose={async () => {
2021-01-10 10:59:57 +05:00
if (editing.isFocused === true) {
2021-01-14 14:36:33 +05:00
if (editing.focusType == 'editor') {
await sleep(10);
if (Platform.OS === 'android') {
textInput.current?.focus();
post('focusEditor');
EditorWebView.current?.requestFocus();
} else {
post('focusEditor');
}
} else {
2021-01-14 14:36:33 +05:00
await sleep(10);
if (Platform.OS === 'android') {
textInput.current?.focus();
post('focusTitle');
EditorWebView.current?.requestFocus();
} else {
post('focusTitle');
}
}
}
if (onClose) {
2021-01-14 14:36:33 +05:00
onClose();
}
2021-01-14 14:36:33 +05:00
}}>
2020-12-19 13:15:34 +05:00
{children}
</ActionSheet>
);
};
export default ActionSheetWrapper;