-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathStepScreenDragAndDropWrapper.tsx
66 lines (54 loc) · 2.58 KB
/
StepScreenDragAndDropWrapper.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type {ReactNode} from 'react';
import React, {useState} from 'react';
import {View} from 'react-native';
import DragAndDropProvider from '@components/DragAndDrop/Provider';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useThemeStyles from '@hooks/useThemeStyles';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import callOrReturn from '@src/types/utils/callOrReturn';
type StepScreenDragAndDropWrapperProps = {
/** The title to show in the header (should be translated already) */
headerTitle: string;
/** A function triggered when the back button is pressed */
onBackButtonPress: () => void;
/** A function triggered when the entry transition is ended. Useful for auto-focusing elements. */
onEntryTransitionEnd?: () => void;
/** Whether or not the wrapper should be shown (sometimes screens can be embedded inside another screen that already is using a wrapper) */
shouldShowWrapper: boolean;
/** An ID used for unit testing */
testID: string;
/** The children to render */
children: ((isDraggingOver: boolean) => ReactNode) | ReactNode;
};
function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, onEntryTransitionEnd, children, shouldShowWrapper}: StepScreenDragAndDropWrapperProps) {
const styles = useThemeStyles();
const [isDraggingOver, setIsDraggingOver] = useState(false);
if (!shouldShowWrapper) {
return callOrReturn(children, false);
}
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableKeyboardAvoidingView={false}
onEntryTransitionEnd={onEntryTransitionEnd}
testID={testID}
shouldEnableMaxHeight={DeviceCapabilities.canUseTouchScreen()}
headerGapStyles={isDraggingOver ? [styles.isDraggingOver] : []}
>
{({safeAreaPaddingBottomStyle}) => (
<DragAndDropProvider setIsDraggingOver={setIsDraggingOver}>
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton
title={headerTitle}
onBackButtonPress={onBackButtonPress}
/>
{callOrReturn(children, isDraggingOver)}
</View>
</DragAndDropProvider>
)}
</ScreenWrapper>
);
}
StepScreenDragAndDropWrapper.displayName = 'StepScreenDragAndDropWrapper';
export default StepScreenDragAndDropWrapper;