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

88 lines
2.2 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';
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
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}
/>
}
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;