-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathStepScreenWrapper.js
75 lines (63 loc) · 2.76 KB
/
StepScreenWrapper.js
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
67
68
69
70
71
72
73
74
75
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import useThemeStyles from '@styles/useThemeStyles';
const propTypes = {
/** The things to display inside the screenwrapper */
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
/** The title to show in the header (should be translated already) */
headerTitle: PropTypes.string.isRequired,
/** A function triggered when the back button is pressed */
onBackButtonPress: PropTypes.func.isRequired,
/** A function triggered when the entry transition is ended. Useful for auto-focusing elements. */
onEntryTransitionEnd: PropTypes.func,
/** Whether or not the wrapper should be shown (sometimes screens can be embedded inside another screen that already is using a wrapper) */
shouldShowWrapper: PropTypes.bool.isRequired,
/** An ID used for unit testing */
testID: PropTypes.string.isRequired,
};
const defaultProps = {
onEntryTransitionEnd: () => {},
};
function StepScreenWrapper({testID, headerTitle, onBackButtonPress, onEntryTransitionEnd, children, shouldShowWrapper}) {
const styles = useThemeStyles();
if (!shouldShowWrapper) {
return children;
}
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableKeyboardAvoidingView={false}
onEntryTransitionEnd={onEntryTransitionEnd}
testID={testID}
shouldEnableMaxHeight={DeviceCapabilities.canUseTouchScreen()}
>
{({insets, safeAreaPaddingBottomStyle, didScreenTransitionEnd}) => (
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton
title={headerTitle}
onBackButtonPress={onBackButtonPress}
/>
{
// If props.children is a function, call it to provide the insets to the children.
_.isFunction(children)
? children({
insets,
safeAreaPaddingBottomStyle,
didScreenTransitionEnd,
})
: children
}
</View>
)}
</ScreenWrapper>
);
}
StepScreenWrapper.displayName = 'StepScreenWrapper';
StepScreenWrapper.propTypes = propTypes;
StepScreenWrapper.defaultProps = defaultProps;
export default StepScreenWrapper;