@onehat/ui 0.2.25 → 0.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/Components/Container/Container.js +10 -4
- package/src/Components/Container/ScreenContainer.js +81 -0
- package/src/Components/Form/Field/Date.js +1 -1
- package/src/Components/Form/Field/{CKEditor/CKEditor.js → HtmlEditor.js} +11 -10
- package/src/Components/Hoc/withInlineEditor.js +3 -3
- package/src/Components/Panel/Header.js +72 -2
- package/src/Components/Panel/Panel.js +5 -6
- package/src/Components/index.js +2 -2
- package/src/Functions/getComponentFromType.js +1 -0
- package/src/Functions/registerReactNativeComponents.js +5 -1
- package/src/Functions/registerWebComponents.js +1 -1
- package/src/PlatformImports/ReactNative/CKEditor.js +3 -0
- package/src/PlatformImports/Web/CKEditor.js +4 -0
- package/src/Components/ScreenContainer.js +0 -71
- /package/src/{Components/Form/Field/CKEditor/styles.css → PlatformImports/Web/ckeditor.css} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onehat/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.27",
|
|
4
4
|
"description": "Base UI for OneHat apps",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "UNLICENSED",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@ckeditor/ckeditor5-react": "^5.0.6",
|
|
23
22
|
"@onehat/data": "^1.13.6",
|
|
24
23
|
"@hookform/resolvers": "^2.9.11",
|
|
25
24
|
"ckeditor5-custom-build": "file:ckeditor5",
|
|
@@ -28,11 +27,13 @@
|
|
|
28
27
|
"react-hook-form": "^7.43.1"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
30
|
+
"@ckeditor/ckeditor5-react": "^5.0.6",
|
|
31
31
|
"react": "*",
|
|
32
32
|
"react-color": "^2.19.3",
|
|
33
33
|
"react-datetime": "^3.2.0",
|
|
34
34
|
"react-draggable": "^4.4.5",
|
|
35
35
|
"react-native-draggable": "^3.3.0",
|
|
36
|
+
"react-native-ckeditor5": "^1.0.9",
|
|
36
37
|
"react-dom": "*",
|
|
37
38
|
"react-native": "*"
|
|
38
39
|
},
|
|
@@ -7,6 +7,11 @@ import {
|
|
|
7
7
|
HORIZONTAL,
|
|
8
8
|
VERTICAL,
|
|
9
9
|
} from '../../Constants/Directions.js';
|
|
10
|
+
import {
|
|
11
|
+
UI_MODE_WEB,
|
|
12
|
+
UI_MODE_REACT_NATIVE,
|
|
13
|
+
CURRENT_MODE,
|
|
14
|
+
} from '../../Constants/UiModes.js';
|
|
10
15
|
import Splitter from './Splitter.js';
|
|
11
16
|
|
|
12
17
|
export default function Container(props) {
|
|
@@ -26,6 +31,7 @@ export default function Container(props) {
|
|
|
26
31
|
isWestCollapsed,
|
|
27
32
|
setIsWestCollapsed,
|
|
28
33
|
} = props,
|
|
34
|
+
canResize = CURRENT_MODE === UI_MODE_WEB,
|
|
29
35
|
[localIsNorthCollapsed, setLocalIsNorthCollapsed] = useState(north ? north.props.startsCollapsed : false),
|
|
30
36
|
[localIsSouthCollapsed, setLocalIsSouthCollapsed] = useState(south ? south.props.startsCollapsed : false),
|
|
31
37
|
[localIsEastCollapsed, setLocalIsEastCollapsed] = useState(east ? east.props.startsCollapsed : false),
|
|
@@ -68,7 +74,7 @@ export default function Container(props) {
|
|
|
68
74
|
if (!north.props.h && !north.props.flex) {
|
|
69
75
|
componentProps.flex = 50;
|
|
70
76
|
}
|
|
71
|
-
if (north.props.isResizable) {
|
|
77
|
+
if (canResize && north.props.isResizable) {
|
|
72
78
|
if (northHeight) {
|
|
73
79
|
componentProps.h = northHeight;
|
|
74
80
|
componentProps.flex = null;
|
|
@@ -92,7 +98,7 @@ export default function Container(props) {
|
|
|
92
98
|
if (!south.props.h && !south.props.flex) {
|
|
93
99
|
componentProps.flex = 50;
|
|
94
100
|
}
|
|
95
|
-
if (south.props.isResizable) {
|
|
101
|
+
if (canResize && south.props.isResizable) {
|
|
96
102
|
if (southHeight) {
|
|
97
103
|
componentProps.h = southHeight;
|
|
98
104
|
componentProps.flex = null;
|
|
@@ -116,7 +122,7 @@ export default function Container(props) {
|
|
|
116
122
|
if (!east.props.h && !east.props.flex) {
|
|
117
123
|
componentProps.flex = 50;
|
|
118
124
|
}
|
|
119
|
-
if (east.props.isResizable) {
|
|
125
|
+
if (canResize && east.props.isResizable) {
|
|
120
126
|
if (eastWidth) {
|
|
121
127
|
componentProps.w = eastWidth;
|
|
122
128
|
componentProps.flex = null;
|
|
@@ -140,7 +146,7 @@ export default function Container(props) {
|
|
|
140
146
|
if (!west.props.h && !west.props.flex) {
|
|
141
147
|
componentProps.flex = 50;
|
|
142
148
|
}
|
|
143
|
-
if (west.props.isResizable) {
|
|
149
|
+
if (canResize && west.props.isResizable) {
|
|
144
150
|
if (westWidth) {
|
|
145
151
|
componentProps.w = westWidth;
|
|
146
152
|
componentProps.flex = null;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Platform,
|
|
3
|
+
RefreshControl,
|
|
4
|
+
useWindowDimensions,
|
|
5
|
+
} from 'react-native';
|
|
6
|
+
import {
|
|
7
|
+
Column,
|
|
8
|
+
ScrollView,
|
|
9
|
+
KeyboardAvoidingView,
|
|
10
|
+
} from 'native-base';
|
|
11
|
+
import { useHeaderHeight } from '@react-navigation/elements';
|
|
12
|
+
// import testProps from '../OneHat/functions/testProps';
|
|
13
|
+
|
|
14
|
+
export default function ScreenContainer(props) {
|
|
15
|
+
const {
|
|
16
|
+
screenName = 'ScreenContainer',
|
|
17
|
+
p = 0,
|
|
18
|
+
safeArea = false,
|
|
19
|
+
bg = '#fff',
|
|
20
|
+
scrollEnabled = false,
|
|
21
|
+
keyboardAvoiding = false,
|
|
22
|
+
subtractHeaderHeight = true,
|
|
23
|
+
setScrollViewRef = () => {},
|
|
24
|
+
onLayout = () => {},
|
|
25
|
+
onRefresh = () => {},
|
|
26
|
+
isRefreshing,
|
|
27
|
+
} = props,
|
|
28
|
+
{
|
|
29
|
+
height,
|
|
30
|
+
} = useWindowDimensions(),
|
|
31
|
+
headerHeight = subtractHeaderHeight ? useHeaderHeight() : 0,
|
|
32
|
+
safeAreaProps = {};
|
|
33
|
+
if (safeArea !== false) {
|
|
34
|
+
safeAreaProps.safeArea = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const column = <Column
|
|
38
|
+
// {...testProps(screenName)}
|
|
39
|
+
alignItems="center"
|
|
40
|
+
justifyContent="flex-start"
|
|
41
|
+
flex={1}
|
|
42
|
+
w="100%"
|
|
43
|
+
p={p}
|
|
44
|
+
bg={bg}
|
|
45
|
+
overflow="visible"
|
|
46
|
+
onLayout={onLayout}
|
|
47
|
+
{...safeAreaProps}
|
|
48
|
+
>
|
|
49
|
+
{props.children}
|
|
50
|
+
</Column>;
|
|
51
|
+
|
|
52
|
+
if (scrollEnabled) {
|
|
53
|
+
const scrollViewProps = {};
|
|
54
|
+
if (onRefresh && typeof isRefreshing !== 'undefined') {
|
|
55
|
+
scrollViewProps.refreshControl = <RefreshControl refreshing={isRefreshing} onRefresh={onRefresh} />
|
|
56
|
+
}
|
|
57
|
+
const scrollView = <ScrollView
|
|
58
|
+
ref={(ref) => {
|
|
59
|
+
setScrollViewRef(ref);
|
|
60
|
+
}}
|
|
61
|
+
keyboardShouldPersistTaps="handled"
|
|
62
|
+
_contentContainerStyle={{
|
|
63
|
+
minHeight: height - headerHeight,
|
|
64
|
+
}}
|
|
65
|
+
{...scrollViewProps}
|
|
66
|
+
>{column}</ScrollView>;
|
|
67
|
+
if (keyboardAvoiding) {
|
|
68
|
+
return <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} flex={1} width="100%">
|
|
69
|
+
{scrollView}
|
|
70
|
+
</KeyboardAvoidingView>
|
|
71
|
+
} else {
|
|
72
|
+
return scrollView;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (keyboardAvoiding) {
|
|
76
|
+
return <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} flex={1} width="100%">
|
|
77
|
+
{column}
|
|
78
|
+
</KeyboardAvoidingView>;
|
|
79
|
+
}
|
|
80
|
+
return column;
|
|
81
|
+
}
|
|
@@ -38,7 +38,7 @@ export function DateElement(props) {
|
|
|
38
38
|
tooltipPlacement = 'bottom',
|
|
39
39
|
} = props,
|
|
40
40
|
styles = UiGlobals.styles,
|
|
41
|
-
Datetime = getComponentFromType('
|
|
41
|
+
Datetime = getComponentFromType('Datetime'),
|
|
42
42
|
inputRef = useRef(),
|
|
43
43
|
triggerRef = useRef(),
|
|
44
44
|
pickerRef = useRef(),
|
|
@@ -4,22 +4,23 @@ import {
|
|
|
4
4
|
} from 'native-base';
|
|
5
5
|
import {
|
|
6
6
|
AUTO_SUBMIT_DELAY,
|
|
7
|
-
} from '
|
|
7
|
+
} from '../../../Constants/Input.js';
|
|
8
8
|
import Editor from 'ckeditor5-custom-build/build/ckeditor.js'; // built using https://ckeditor.com/ckeditor-5/online-builder/
|
|
9
|
-
import
|
|
10
|
-
import withValue from '
|
|
11
|
-
import withTooltip from '
|
|
12
|
-
import '
|
|
9
|
+
import getComponentFromType from '../../../Functions/getComponentFromType.js';
|
|
10
|
+
import withValue from '../../Hoc/withValue.js';
|
|
11
|
+
import withTooltip from '../../Hoc/withTooltip.js';
|
|
12
|
+
import _ from 'lodash';
|
|
13
13
|
|
|
14
14
|
const
|
|
15
|
-
|
|
15
|
+
HtmlEditorElement = (props) => {
|
|
16
16
|
const {
|
|
17
17
|
value,
|
|
18
18
|
setValue,
|
|
19
19
|
h = 150,
|
|
20
20
|
} = props,
|
|
21
|
+
CKEditor = getComponentFromType('CKEditor'),
|
|
21
22
|
debouncedSetValueRef = useRef(),
|
|
22
|
-
[editor, setEditor] = useState(null),
|
|
23
|
+
[editor, setEditor] = useState(null), // in case you need to adjust things procedurally
|
|
23
24
|
config = {
|
|
24
25
|
};
|
|
25
26
|
|
|
@@ -51,12 +52,12 @@ const
|
|
|
51
52
|
/>
|
|
52
53
|
</Row>;
|
|
53
54
|
},
|
|
54
|
-
|
|
55
|
+
HtmlEditorField = withValue(HtmlEditorElement);
|
|
55
56
|
|
|
56
57
|
|
|
57
|
-
export default
|
|
58
|
+
export default HtmlEditorField;
|
|
58
59
|
|
|
59
60
|
// // Tooltip needs us to forwardRef
|
|
60
61
|
// export default withTooltip(React.forwardRef((props, ref) => {
|
|
61
|
-
// return <
|
|
62
|
+
// return <HtmlEditorField {...props} outerRef={ref} />;
|
|
62
63
|
// }));
|
|
@@ -18,9 +18,6 @@ import withEditor from './withEditor.js';
|
|
|
18
18
|
import _ from 'lodash';
|
|
19
19
|
|
|
20
20
|
export default function withInlineEditor(WrappedComponent) {
|
|
21
|
-
if (UiGlobals.mode === UI_MODE_REACT_NATIVE) {
|
|
22
|
-
throw new Error('Not yet implemented for RN.');
|
|
23
|
-
}
|
|
24
21
|
return withEditor((props) => {
|
|
25
22
|
const {
|
|
26
23
|
useEditor = false,
|
|
@@ -69,6 +66,9 @@ export default function withInlineEditor(WrappedComponent) {
|
|
|
69
66
|
if (isEditorShown && selection.length !== 1) {
|
|
70
67
|
throw new Error('Can only edit one at a time with inline editor!');
|
|
71
68
|
}
|
|
69
|
+
if (UiGlobals.mode === UI_MODE_REACT_NATIVE) {
|
|
70
|
+
throw new Error('Not yet implemented for RN.');
|
|
71
|
+
}
|
|
72
72
|
|
|
73
73
|
return <>
|
|
74
74
|
<WrappedComponent
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
Column,
|
|
4
4
|
Icon,
|
|
5
|
+
Pressable,
|
|
5
6
|
Row,
|
|
6
7
|
Text,
|
|
7
8
|
} from 'native-base';
|
|
@@ -106,9 +107,78 @@ export default function Header(props) {
|
|
|
106
107
|
|
|
107
108
|
} else if (CURRENT_MODE === UI_MODE_REACT_NATIVE) {
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
if (isCollapsed) {
|
|
111
|
+
if (collapseDirection === HORIZONTAL) {
|
|
112
|
+
collapseBtn = React.cloneElement(collapseBtn, { my: 2, mr: 1, });
|
|
113
|
+
return <Pressable
|
|
114
|
+
testID={testID}
|
|
115
|
+
flex={1}
|
|
116
|
+
w="100%"
|
|
117
|
+
style={{ userSelect: 'none', ...doubleClickStyle, }}
|
|
118
|
+
onPress={(e) => {
|
|
119
|
+
if (isCollapsible) {
|
|
120
|
+
onToggleCollapse(e);
|
|
121
|
+
}
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
<Column
|
|
125
|
+
alignItems="center"
|
|
126
|
+
justifyContent="flex-start"
|
|
127
|
+
h="100%"
|
|
128
|
+
w="100%"
|
|
129
|
+
bg={styles.PANEL_HEADER_BG_VERTICAL}
|
|
130
|
+
>
|
|
131
|
+
{collapseBtn}
|
|
132
|
+
<Column
|
|
133
|
+
alignItems="center"
|
|
134
|
+
justifyContent="center"
|
|
135
|
+
flex={1}
|
|
136
|
+
w="100%"
|
|
137
|
+
>
|
|
138
|
+
<Text
|
|
139
|
+
textAlign="right"
|
|
140
|
+
fontSize={styles.PANEL_HEADER_TEXT_FONTSIZE}
|
|
141
|
+
color={styles.PANEL_HEADER_TEXT_COLOR}
|
|
142
|
+
numberOfLines={1}
|
|
143
|
+
ellipsizeMode="head"
|
|
144
|
+
w={200}
|
|
145
|
+
style={{ transform: [{ rotate: '-90deg'}] }}
|
|
146
|
+
>{title}</Text>
|
|
147
|
+
</Column>
|
|
148
|
+
</Column>
|
|
149
|
+
</Pressable>;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return <Pressable
|
|
154
|
+
testID={testID}
|
|
155
|
+
w="100%"
|
|
156
|
+
style={{ userSelect: 'none', ...doubleClickStyle, }}
|
|
157
|
+
onPress={(e) => {
|
|
158
|
+
if (isCollapsible) {
|
|
159
|
+
onToggleCollapse(e);
|
|
160
|
+
}
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
<Row
|
|
164
|
+
alignItems="center"
|
|
165
|
+
justifyContent="flex-start"
|
|
166
|
+
px={styles.PANEL_HEADER_PX}
|
|
167
|
+
py={styles.PANEL_HEADER_PY}
|
|
168
|
+
bg={styles.PANEL_HEADER_BG}
|
|
169
|
+
>
|
|
170
|
+
{closeBtn}
|
|
171
|
+
<Text
|
|
172
|
+
flex={1}
|
|
173
|
+
fontSize={styles.PANEL_HEADER_TEXT_FONTSIZE}
|
|
174
|
+
color={styles.PANEL_HEADER_TEXT_COLOR}
|
|
175
|
+
numberOfLines={1}
|
|
176
|
+
ellipsizeMode="head"
|
|
177
|
+
>{title}</Text>
|
|
178
|
+
{collapseBtn}
|
|
179
|
+
</Row>
|
|
180
|
+
</Pressable>;
|
|
110
181
|
|
|
111
182
|
}
|
|
112
183
|
|
|
113
|
-
|
|
114
184
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useState, } from 'react';
|
|
2
1
|
import {
|
|
3
2
|
Column,
|
|
4
3
|
Row,
|
|
@@ -120,22 +119,22 @@ function Panel(props) {
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
if (isCollapsed) {
|
|
123
|
-
if (collapseDirection
|
|
124
|
-
return <Column overflow="hidden" {...framePropsToUse} w="33px"
|
|
122
|
+
if (collapseDirection === HORIZONTAL) {
|
|
123
|
+
return <Column overflow="hidden" {...propsToPass} {...framePropsToUse} w="33px" h="100%">
|
|
125
124
|
{isDisabled && <Mask />}
|
|
126
125
|
{headerComponent}
|
|
127
126
|
</Column>;
|
|
128
127
|
}
|
|
129
|
-
return <Column overflow="hidden" {...framePropsToUse}>
|
|
128
|
+
return <Column overflow="hidden" {...propsToPass} {...framePropsToUse} h="33px" w="100%">
|
|
130
129
|
{isDisabled && <Mask />}
|
|
131
130
|
{headerComponent}
|
|
132
131
|
</Column>;
|
|
133
132
|
}
|
|
134
|
-
return <Column overflow="hidden" onLayout={onLayout} {...framePropsToUse} {...sizeProps}>
|
|
133
|
+
return <Column overflow="hidden" {...propsToPass} onLayout={onLayout} {...framePropsToUse} {...sizeProps}>
|
|
135
134
|
{isDisabled && <Mask />}
|
|
136
135
|
{headerComponent}
|
|
137
136
|
{topToolbar}
|
|
138
|
-
<Column flex={1} w="100%" overflow="hidden"
|
|
137
|
+
<Column flex={1} w="100%" overflow="hidden">
|
|
139
138
|
{isScrollable ? <ScrollView>{children}</ScrollView> : children}
|
|
140
139
|
</Column>
|
|
141
140
|
{bottomToolbar}
|
package/src/Components/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import Blank from './Blank.js';
|
|
|
10
10
|
import BooleanCombo from './Form/Field/Combo/BooleanCombo.js';
|
|
11
11
|
// import CartButtonWithBadge from '../Components/Buttons/CartButtonWithBadge.js';
|
|
12
12
|
import CheckboxGroup from './Form/Field/CheckboxGroup/CheckboxGroup.js';
|
|
13
|
-
// import CKEditor from './Form/Field/CKEditor/CKEditor.js'; // web only
|
|
14
13
|
import Color from './Form/Field/Color.js';
|
|
15
14
|
import Combo from './Form/Field/Combo/Combo.js';
|
|
16
15
|
// import ComboEditor from '../Components/Form/Field/Combo/ComboEditor.js';
|
|
@@ -26,6 +25,7 @@ import FiltersForm from './Form/FiltersForm.js';
|
|
|
26
25
|
import Form from './Form/Form.js';
|
|
27
26
|
import Grid from './Grid/Grid.js';
|
|
28
27
|
import GridPanel from './Panel/GridPanel.js';
|
|
28
|
+
import HtmlEditor from './Form/Field/HtmlEditor.js';
|
|
29
29
|
import IconButton from './Buttons/IconButton.js';
|
|
30
30
|
import Input from './Form/Field/Input.js';
|
|
31
31
|
import IntervalsCombo from './Form/Field/Combo/IntervalsCombo.js';
|
|
@@ -56,7 +56,6 @@ const components = {
|
|
|
56
56
|
BooleanCombo,
|
|
57
57
|
// CartButtonWithBadge,
|
|
58
58
|
CheckboxGroup,
|
|
59
|
-
// CKEditor,
|
|
60
59
|
Color,
|
|
61
60
|
Column,
|
|
62
61
|
Combo,
|
|
@@ -73,6 +72,7 @@ const components = {
|
|
|
73
72
|
Form,
|
|
74
73
|
Grid,
|
|
75
74
|
GridPanel,
|
|
75
|
+
HtmlEditor,
|
|
76
76
|
IconButton,
|
|
77
77
|
Input,
|
|
78
78
|
IntervalsCombo,
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import UiGlobals from '../UiGlobals.js';
|
|
2
|
+
import CKEditor from '../PlatformImports/ReactNative/CKEditor';
|
|
2
3
|
import Datetime from '../PlatformImports/ReactNative/Datetime';
|
|
3
4
|
import Draggable from '../PlatformImports/ReactNative/Draggable';
|
|
5
|
+
import ScreenContainer from '../Components/Container/ScreenContainer';
|
|
4
6
|
import _ from 'lodash';
|
|
5
7
|
|
|
6
|
-
export function registerReactNativeComponents() {
|
|
8
|
+
export default function registerReactNativeComponents() {
|
|
7
9
|
_.merge(UiGlobals.components, {
|
|
10
|
+
CKEditor,
|
|
8
11
|
Datetime,
|
|
9
12
|
Draggable,
|
|
13
|
+
ScreenContainer,
|
|
10
14
|
});
|
|
11
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import UiGlobals from '../UiGlobals.js';
|
|
2
|
-
import CKEditor from '../
|
|
2
|
+
import CKEditor from '../PlatformImports/Web/CKEditor';
|
|
3
3
|
import Datetime from '../PlatformImports/Web/Datetime.js';
|
|
4
4
|
import Draggable from '../PlatformImports/Web/Draggable.js';
|
|
5
5
|
import File from '../Components/Form/Field/File.js';
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Keyboard,
|
|
3
|
-
Platform,
|
|
4
|
-
TouchableWithoutFeedback,
|
|
5
|
-
} from 'react-native';
|
|
6
|
-
import {
|
|
7
|
-
Column,
|
|
8
|
-
KeyboardAvoidingView,
|
|
9
|
-
ScrollView,
|
|
10
|
-
} from 'native-base';
|
|
11
|
-
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
|
|
12
|
-
import { useDimensions } from '@react-native-community/Hooks';
|
|
13
|
-
import { useHeaderHeight } from '@react-navigation/elements';
|
|
14
|
-
import testProps from '../Functions/testProps';
|
|
15
|
-
|
|
16
|
-
export default function ScreenContainer(props) {
|
|
17
|
-
const {
|
|
18
|
-
screenName = 'ScreenContainer',
|
|
19
|
-
p = 0,
|
|
20
|
-
safeArea = false,
|
|
21
|
-
bg = '#fff',
|
|
22
|
-
scrollEnabled = false,
|
|
23
|
-
keyboardAvoiding = false,
|
|
24
|
-
behavior = Platform.OS === 'ios' ? 'padding' : 'height', // for the KeyboardAvoidingView. 'height', 'position', 'padding'
|
|
25
|
-
justifyContent = 'flex-start',
|
|
26
|
-
alignItems = 'center',
|
|
27
|
-
onLayout = () => {},
|
|
28
|
-
} = props,
|
|
29
|
-
screen = useDimensions().screen,
|
|
30
|
-
headerHeight = useHeaderHeight(),
|
|
31
|
-
safeAreaProps = {};
|
|
32
|
-
if (safeArea !== false) {
|
|
33
|
-
safeAreaProps.safeAreaTop = true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let content = <Column
|
|
37
|
-
{...testProps(screenName)}
|
|
38
|
-
alignItems={alignItems}
|
|
39
|
-
justifyContent={justifyContent}
|
|
40
|
-
flex={1}
|
|
41
|
-
w="100%"
|
|
42
|
-
p={p}
|
|
43
|
-
bg={bg}
|
|
44
|
-
overflow="visible"
|
|
45
|
-
onLayout={onLayout}
|
|
46
|
-
{...safeAreaProps}
|
|
47
|
-
>
|
|
48
|
-
{props.children}
|
|
49
|
-
</Column>;
|
|
50
|
-
if (keyboardAvoiding && scrollEnabled) {
|
|
51
|
-
content = <KeyboardAwareScrollView behavior={behavior} contentContainerStyle={{ flex: 1, }}>
|
|
52
|
-
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
|
53
|
-
{content}
|
|
54
|
-
</TouchableWithoutFeedback>
|
|
55
|
-
</KeyboardAwareScrollView>;
|
|
56
|
-
} else {
|
|
57
|
-
if (keyboardAvoiding) {
|
|
58
|
-
content = <KeyboardAvoidingView behavior={behavior} flex={1}>
|
|
59
|
-
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
|
|
60
|
-
{content}
|
|
61
|
-
</TouchableWithoutFeedback>
|
|
62
|
-
</KeyboardAvoidingView>;
|
|
63
|
-
}
|
|
64
|
-
if (scrollEnabled) {
|
|
65
|
-
content = <ScrollView keyboardShouldPersistTaps="always" _contentContainerStyle={{
|
|
66
|
-
minHeight: screen.height - headerHeight,
|
|
67
|
-
}}>{content}</ScrollView>;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return content;
|
|
71
|
-
}
|
|
File without changes
|