@momo-kits/foundation 0.75.1-beta.9 → 0.75.3-beta.0
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/Application/BottomSheet.tsx +225 -0
- package/Application/BottomTab/BottomTabBar.tsx +291 -0
- package/Application/BottomTab/index.tsx +138 -0
- package/Application/Components.tsx +555 -0
- package/Application/ModalScreen.tsx +97 -0
- package/Application/Navigation.ts +50 -0
- package/Application/NavigationContainer.tsx +121 -0
- package/Application/Navigator.ts +151 -0
- package/Application/StackScreen.tsx +148 -0
- package/Application/index.ts +37 -0
- package/{Navigation → Application}/types.ts +101 -33
- package/Application/utils.tsx +153 -0
- package/Assets/DotAnimation.json +256 -0
- package/Assets/SpinnerAnimation.json +1027 -0
- package/Assets/icon.json +89 -5
- package/Assets/icon_bank.json +506 -0
- package/Assets/language.json +202 -0
- package/Badge/Badge.tsx +56 -0
- package/Badge/BadgeDot.tsx +11 -0
- package/Badge/BadgeRibbon.tsx +125 -0
- package/Badge/Shape.tsx +29 -0
- package/Badge/index.tsx +7 -0
- package/Badge/styles.ts +58 -0
- package/Badge/types.ts +63 -0
- package/Button/index.tsx +91 -40
- package/Button/styles.ts +19 -0
- package/CheckBox/index.tsx +58 -43
- package/CheckBox/styles.ts +1 -1
- package/CheckBox/types.ts +6 -4
- package/Consts/colors+spacing+radius.ts +18 -0
- package/Consts/styles.ts +0 -26
- package/Consts/theme.ts +5 -1
- package/Divider/index.tsx +3 -1
- package/Icon/index.tsx +15 -10
- package/Icon/types.ts +4 -3
- package/IconButton/index.tsx +24 -15
- package/Image/index.tsx +63 -45
- package/Image/styles.ts +1 -9
- package/Image/types.ts +5 -1
- package/Input/Input.tsx +227 -115
- package/Input/InputDropDown.tsx +132 -0
- package/Input/InputMoney.tsx +173 -110
- package/Input/InputOTP.tsx +257 -0
- package/Input/InputSearch.tsx +160 -130
- package/Input/InputTextArea.tsx +149 -121
- package/Input/common.tsx +36 -18
- package/Input/index.tsx +212 -17
- package/Input/styles.ts +44 -7
- package/Input/utils.ts +2 -2
- package/Layout/Card.tsx +76 -37
- package/Layout/FloatingButton.tsx +168 -0
- package/Layout/GridSystem.tsx +35 -23
- package/Layout/Item.tsx +29 -33
- package/Layout/ItemList.tsx +55 -0
- package/Layout/ItemSectionList.tsx +39 -0
- package/Layout/Screen.tsx +390 -0
- package/Layout/Section.tsx +73 -35
- package/Layout/index.ts +13 -3
- package/Layout/styles.ts +101 -0
- package/Layout/types.ts +1 -37
- package/Layout/utils.ts +38 -43
- package/Loader/DotLoader.tsx +37 -0
- package/Loader/Loader.tsx +13 -0
- package/Loader/ProgressBar.tsx +44 -0
- package/Loader/Spinner.tsx +29 -0
- package/Loader/index.tsx +4 -0
- package/Loader/styles.ts +10 -0
- package/Loader/types.ts +35 -0
- package/Loader/utils.ts +25 -0
- package/Pagination/Dot.tsx +1 -1
- package/Pagination/PaginationDot.tsx +8 -3
- package/Pagination/PaginationNumber.tsx +8 -7
- package/Pagination/PaginationScroll.tsx +1 -1
- package/Pagination/PaginationWhiteDot.tsx +8 -5
- package/Pagination/styles.ts +3 -0
- package/Pagination/types.ts +2 -0
- package/Popup/PopupNotify.tsx +108 -46
- package/Popup/PopupPromotion.tsx +63 -22
- package/Popup/types.ts +15 -4
- package/Radio/index.tsx +35 -21
- package/Radio/types.ts +7 -5
- package/Skeleton/index.tsx +1 -1
- package/Skeleton/types.ts +3 -0
- package/Switch/index.tsx +35 -24
- package/Switch/types.ts +5 -3
- package/Tag/index.tsx +1 -1
- package/Text/index.tsx +32 -26
- package/Text/styles.ts +38 -0
- package/Text/types.ts +25 -13
- package/Text/utils.ts +14 -0
- package/Title/index.tsx +197 -0
- package/Title/styles.ts +79 -0
- package/Title/types.ts +20 -0
- package/code-scanner.js +143 -0
- package/index.ts +22 -2
- package/migrate_typo.js +56 -0
- package/package.json +44 -39
- package/publish.sh +2 -5
- package/tsconfig.json +24 -0
- package/verify.js +47 -0
- package/Assets/header-background.png +0 -0
- package/Layout/ScreenContainer.tsx +0 -121
- package/Navigation/BottomTab.tsx +0 -39
- package/Navigation/Components.tsx +0 -365
- package/Navigation/ModalScreen.tsx +0 -226
- package/Navigation/Navigation.ts +0 -44
- package/Navigation/NavigationButton.tsx +0 -54
- package/Navigation/NavigationContainer.tsx +0 -77
- package/Navigation/Navigator.ts +0 -82
- package/Navigation/Observer.ts +0 -79
- package/Navigation/StackScreen.tsx +0 -27
- package/Navigation/index.ts +0 -14
- package/Navigation/utils.tsx +0 -137
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import {useHeaderHeight} from '@react-navigation/stack';
|
|
2
|
+
import React, {
|
|
3
|
+
forwardRef,
|
|
4
|
+
Fragment,
|
|
5
|
+
ReactNode,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import {
|
|
11
|
+
Animated,
|
|
12
|
+
KeyboardAvoidingView,
|
|
13
|
+
NativeScrollEvent,
|
|
14
|
+
NativeSyntheticEvent,
|
|
15
|
+
Platform,
|
|
16
|
+
ScrollViewProps,
|
|
17
|
+
View,
|
|
18
|
+
ViewProps,
|
|
19
|
+
} from 'react-native';
|
|
20
|
+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
21
|
+
import {
|
|
22
|
+
ApplicationContext,
|
|
23
|
+
HeaderBackground,
|
|
24
|
+
HeaderTitle,
|
|
25
|
+
} from '../Application';
|
|
26
|
+
import Navigation from '../Application/Navigation';
|
|
27
|
+
import {AnimatedHeader, NavigationOptions} from '../Application/types';
|
|
28
|
+
import {Colors, Spacing, Styles} from '../Consts';
|
|
29
|
+
import {FloatingButton, FloatingButtonProps} from './FloatingButton';
|
|
30
|
+
import {Image} from '../Image';
|
|
31
|
+
import {Card, Section, validateChildren} from './index';
|
|
32
|
+
import styles from './styles';
|
|
33
|
+
import {HeaderType} from './types';
|
|
34
|
+
|
|
35
|
+
export interface ScreenProps extends ViewProps {
|
|
36
|
+
children: React.ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Optional. Navigation object for handling navigation actions.
|
|
39
|
+
*/
|
|
40
|
+
navigation?: Navigation;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Optional. If `true`, enable keyboard avoiding view for the screen.
|
|
44
|
+
*/
|
|
45
|
+
enableKeyboardAvoidingView?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Optional. If `true`, the screen content is scrollable.
|
|
49
|
+
*/
|
|
50
|
+
scrollable?: boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Optional. Set type of header.
|
|
54
|
+
*/
|
|
55
|
+
headerType?: HeaderType;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Optional. Props for the animated component or bool used top navigation animated.
|
|
59
|
+
*/
|
|
60
|
+
animatedHeader?: AnimatedHeader;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Optional. Props for the underlying ScrollView component when `scrollable` is `true`.
|
|
64
|
+
*/
|
|
65
|
+
scrollViewProps?: ScrollViewProps;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Optional. ReactNode representing the header component of the screen.
|
|
69
|
+
*/
|
|
70
|
+
headerComponent?: ReactNode;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Optional. ReactNode representing the footer component of the screen.
|
|
74
|
+
*/
|
|
75
|
+
footerComponent?: ReactNode;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Optional. Background color of the screen.
|
|
79
|
+
*/
|
|
80
|
+
backgroundColor?: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Optional. layout card offset overlap header banner.
|
|
84
|
+
*/
|
|
85
|
+
layoutOffset?: -8 | -24 | -56;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Optional. Props for the floating action button.
|
|
89
|
+
*/
|
|
90
|
+
floatingButtonProps?: Omit<FloatingButtonProps, 'animatedValue' | 'bottom'>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* optional animated value
|
|
94
|
+
*/
|
|
95
|
+
animatedValue?: Animated.Value;
|
|
96
|
+
/**
|
|
97
|
+
* Optional. If `true`, the screen content is using grid layout by span.
|
|
98
|
+
*/
|
|
99
|
+
useGridLayout?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const Screen = forwardRef(
|
|
103
|
+
(
|
|
104
|
+
{
|
|
105
|
+
children,
|
|
106
|
+
enableKeyboardAvoidingView = false,
|
|
107
|
+
scrollable = false,
|
|
108
|
+
navigation,
|
|
109
|
+
animatedHeader,
|
|
110
|
+
scrollViewProps,
|
|
111
|
+
headerComponent: Header,
|
|
112
|
+
footerComponent: Footer,
|
|
113
|
+
layoutOffset = -56,
|
|
114
|
+
backgroundColor,
|
|
115
|
+
headerType = 'default',
|
|
116
|
+
floatingButtonProps,
|
|
117
|
+
useGridLayout = true,
|
|
118
|
+
animatedValue: animated,
|
|
119
|
+
}: ScreenProps,
|
|
120
|
+
ref,
|
|
121
|
+
) => {
|
|
122
|
+
const animatedValue = useRef<Animated.Value>(
|
|
123
|
+
animated ?? new Animated.Value(0),
|
|
124
|
+
);
|
|
125
|
+
const {theme} = useContext(ApplicationContext);
|
|
126
|
+
const insets = useSafeAreaInsets();
|
|
127
|
+
const heightHeader = useHeaderHeight();
|
|
128
|
+
const currentTint = useRef(Colors.black_01);
|
|
129
|
+
const isTab = navigation?.instance?.getState?.()?.type == 'tab';
|
|
130
|
+
|
|
131
|
+
let styleAnimatedHeader: NavigationOptions;
|
|
132
|
+
let handleScroll;
|
|
133
|
+
let headerBackground: string | undefined = undefined;
|
|
134
|
+
let Component: any = View;
|
|
135
|
+
let keyboardVerticalOffset = heightHeader - 20;
|
|
136
|
+
|
|
137
|
+
if (headerType == 'extended' || animatedHeader) {
|
|
138
|
+
keyboardVerticalOffset = -20;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (headerType == 'extended') {
|
|
142
|
+
headerBackground = theme.assets?.headerBackground;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (animatedHeader) {
|
|
147
|
+
styleAnimatedHeader = {
|
|
148
|
+
headerTransparent: true,
|
|
149
|
+
headerBackground: (props: any) => (
|
|
150
|
+
<HeaderBackground
|
|
151
|
+
{...props}
|
|
152
|
+
animatedValue={animatedValue.current}
|
|
153
|
+
/>
|
|
154
|
+
),
|
|
155
|
+
headerTitle: (props: any) => (
|
|
156
|
+
<HeaderTitle {...props} animatedValue={animatedValue.current} />
|
|
157
|
+
),
|
|
158
|
+
};
|
|
159
|
+
if (animatedHeader.type == 'surface') {
|
|
160
|
+
styleAnimatedHeader = {
|
|
161
|
+
...styleAnimatedHeader,
|
|
162
|
+
headerBackground: (props: any) => (
|
|
163
|
+
<HeaderBackground
|
|
164
|
+
{...props}
|
|
165
|
+
image={null}
|
|
166
|
+
useSurface={true}
|
|
167
|
+
animatedValue={animatedValue.current}
|
|
168
|
+
/>
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (animatedHeader.headerTitle) {
|
|
173
|
+
styleAnimatedHeader = {
|
|
174
|
+
...styleAnimatedHeader,
|
|
175
|
+
headerTitle: (props: any) =>
|
|
176
|
+
animatedHeader.headerTitle?.({
|
|
177
|
+
...props,
|
|
178
|
+
animatedValue: animatedValue.current,
|
|
179
|
+
}),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
navigation?.setOptions(styleAnimatedHeader);
|
|
183
|
+
}
|
|
184
|
+
}, [animatedHeader]);
|
|
185
|
+
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
if (!animatedHeader) {
|
|
188
|
+
let headerOptions: NavigationOptions;
|
|
189
|
+
switch (headerType) {
|
|
190
|
+
case 'none':
|
|
191
|
+
headerOptions = {
|
|
192
|
+
headerTransparent: true,
|
|
193
|
+
headerBackground: () => null,
|
|
194
|
+
headerShown: false,
|
|
195
|
+
};
|
|
196
|
+
break;
|
|
197
|
+
|
|
198
|
+
case 'surface':
|
|
199
|
+
headerOptions = {
|
|
200
|
+
headerTransparent: false,
|
|
201
|
+
headerShown: true,
|
|
202
|
+
headerTintColor: theme.colors.text.default,
|
|
203
|
+
headerBackground: (props: any) => (
|
|
204
|
+
<HeaderBackground {...props} image={null} useSurface={true} />
|
|
205
|
+
),
|
|
206
|
+
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
207
|
+
};
|
|
208
|
+
break;
|
|
209
|
+
|
|
210
|
+
case 'extended':
|
|
211
|
+
headerOptions = {
|
|
212
|
+
headerShown: true,
|
|
213
|
+
headerTransparent: true,
|
|
214
|
+
headerTintColor: Colors.black_01,
|
|
215
|
+
headerBackground: () => null,
|
|
216
|
+
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
217
|
+
};
|
|
218
|
+
break;
|
|
219
|
+
|
|
220
|
+
default:
|
|
221
|
+
headerOptions = {
|
|
222
|
+
headerTransparent: false,
|
|
223
|
+
headerShown: true,
|
|
224
|
+
headerTintColor: Colors.black_01,
|
|
225
|
+
headerBackground: (props: any) => <HeaderBackground {...props} />,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
navigation?.setOptions(headerOptions);
|
|
229
|
+
}
|
|
230
|
+
}, [headerType]);
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* animated when use scroll && animated value
|
|
234
|
+
*/
|
|
235
|
+
if (scrollable) {
|
|
236
|
+
Component = Animated.ScrollView;
|
|
237
|
+
handleScroll = scrollViewProps?.onScroll;
|
|
238
|
+
if (animatedHeader || floatingButtonProps) {
|
|
239
|
+
handleScroll = Animated.event(
|
|
240
|
+
[
|
|
241
|
+
{
|
|
242
|
+
nativeEvent: {
|
|
243
|
+
contentOffset: {y: animatedValue.current as Animated.Value},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
{
|
|
248
|
+
useNativeDriver: true,
|
|
249
|
+
listener: (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
250
|
+
scrollViewProps?.onScroll?.(e);
|
|
251
|
+
if (animatedHeader?.type == 'surface') {
|
|
252
|
+
const offsetY = e.nativeEvent.contentOffset.y;
|
|
253
|
+
let color = Colors.black_01;
|
|
254
|
+
if (offsetY > 50) {
|
|
255
|
+
color = theme.colors.text.default;
|
|
256
|
+
}
|
|
257
|
+
if (color != currentTint.current) {
|
|
258
|
+
currentTint.current = color;
|
|
259
|
+
navigation?.setOptions({
|
|
260
|
+
headerTintColor: color,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* render top navigation banner
|
|
272
|
+
*/
|
|
273
|
+
const renderHeader = () => {
|
|
274
|
+
if (typeof animatedHeader?.component === 'function') {
|
|
275
|
+
return animatedHeader?.component({
|
|
276
|
+
animatedValue: animatedValue.current,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* build content for screen
|
|
283
|
+
*/
|
|
284
|
+
const renderContent = (children: any): any => {
|
|
285
|
+
const results = validateChildren(children, [Section, Card, undefined]);
|
|
286
|
+
if (Array.isArray(results)) {
|
|
287
|
+
return results.map((item, index) => {
|
|
288
|
+
const space = item?.props?.useMargin === false ? 0 : Spacing.M;
|
|
289
|
+
if (item?.type == Fragment) {
|
|
290
|
+
return renderContent(item?.props?.children);
|
|
291
|
+
}
|
|
292
|
+
if (item) {
|
|
293
|
+
return (
|
|
294
|
+
<View
|
|
295
|
+
key={`ScreenItem${index}`}
|
|
296
|
+
style={{
|
|
297
|
+
marginTop: space,
|
|
298
|
+
flex: item.props?.expanded ? 1 : undefined,
|
|
299
|
+
}}>
|
|
300
|
+
{item}
|
|
301
|
+
</View>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
const item: any = children;
|
|
307
|
+
const space = item?.props?.useMargin === false ? 0 : Spacing.M;
|
|
308
|
+
if (item?.type == Fragment) {
|
|
309
|
+
return renderContent(item?.props?.children);
|
|
310
|
+
}
|
|
311
|
+
return (
|
|
312
|
+
<View
|
|
313
|
+
key={`ScreenItem`}
|
|
314
|
+
style={{
|
|
315
|
+
marginTop: space,
|
|
316
|
+
flex: item?.props?.expanded ? 1 : undefined,
|
|
317
|
+
}}>
|
|
318
|
+
{children}
|
|
319
|
+
</View>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<View style={[Styles.flex, {backgroundColor}]}>
|
|
326
|
+
{!!headerBackground && (
|
|
327
|
+
<>
|
|
328
|
+
<Image
|
|
329
|
+
source={{
|
|
330
|
+
uri: headerBackground,
|
|
331
|
+
}}
|
|
332
|
+
style={styles.extendedHeader}
|
|
333
|
+
/>
|
|
334
|
+
<View style={{height: heightHeader}} />
|
|
335
|
+
</>
|
|
336
|
+
)}
|
|
337
|
+
<KeyboardAvoidingView
|
|
338
|
+
style={Styles.flex}
|
|
339
|
+
enabled={enableKeyboardAvoidingView}
|
|
340
|
+
keyboardVerticalOffset={keyboardVerticalOffset}
|
|
341
|
+
behavior={Platform.select({
|
|
342
|
+
ios: 'padding',
|
|
343
|
+
android: undefined,
|
|
344
|
+
})}>
|
|
345
|
+
{Header}
|
|
346
|
+
|
|
347
|
+
<Component
|
|
348
|
+
{...scrollViewProps}
|
|
349
|
+
ref={ref}
|
|
350
|
+
showsVerticalScrollIndicator={false}
|
|
351
|
+
onScroll={handleScroll}
|
|
352
|
+
style={Styles.flex}>
|
|
353
|
+
<View
|
|
354
|
+
style={[styles.screenBanner, {maxHeight: 210 + layoutOffset}]}>
|
|
355
|
+
{renderHeader()}
|
|
356
|
+
</View>
|
|
357
|
+
{useGridLayout ? renderContent(children) : children}
|
|
358
|
+
</Component>
|
|
359
|
+
|
|
360
|
+
{floatingButtonProps && (
|
|
361
|
+
<View>
|
|
362
|
+
<FloatingButton
|
|
363
|
+
{...floatingButtonProps}
|
|
364
|
+
animatedValue={animatedValue.current}
|
|
365
|
+
bottom={
|
|
366
|
+
Footer || isTab ? 12 : Math.min(insets.bottom, 21) + Spacing.S
|
|
367
|
+
}
|
|
368
|
+
/>
|
|
369
|
+
</View>
|
|
370
|
+
)}
|
|
371
|
+
|
|
372
|
+
{Footer && (
|
|
373
|
+
<View
|
|
374
|
+
style={[
|
|
375
|
+
styles.shadow,
|
|
376
|
+
{
|
|
377
|
+
paddingBottom: Math.min(insets.bottom, 21) + Spacing.S,
|
|
378
|
+
backgroundColor: theme.colors.background.surface,
|
|
379
|
+
},
|
|
380
|
+
]}>
|
|
381
|
+
<Section>{Footer}</Section>
|
|
382
|
+
</View>
|
|
383
|
+
)}
|
|
384
|
+
</KeyboardAvoidingView>
|
|
385
|
+
</View>
|
|
386
|
+
);
|
|
387
|
+
},
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
export default Screen;
|
package/Layout/Section.tsx
CHANGED
|
@@ -1,13 +1,43 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {Dimensions, View} from 'react-native';
|
|
3
|
-
import {validateChildren} from './utils';
|
|
4
|
-
import {GridContextProps
|
|
1
|
+
import React, {Fragment, useContext} from 'react';
|
|
2
|
+
import {Dimensions, View, ViewProps} from 'react-native';
|
|
3
|
+
import {useGridSystem, validateChildren} from './utils';
|
|
4
|
+
import {GridContextProps} from './types';
|
|
5
5
|
import {GridContext} from './index';
|
|
6
|
-
import {GRIDVIEW} from '../Consts';
|
|
7
6
|
import Item from './Item';
|
|
7
|
+
import {ApplicationContext} from '../Application';
|
|
8
|
+
import styles from './styles';
|
|
9
|
+
import {Image} from '../Image';
|
|
10
|
+
import ItemList from './ItemList';
|
|
11
|
+
|
|
12
|
+
export interface SectionProps extends ViewProps {
|
|
13
|
+
/**
|
|
14
|
+
* Optional. If `true`, the Section component will be displayed in an expanded state.
|
|
15
|
+
* Defaults to `false` if not provided.
|
|
16
|
+
*/
|
|
17
|
+
expanded?: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Optional. If `true`, margin will be applied to the Section component.
|
|
21
|
+
* Defaults to `false` if not provided.
|
|
22
|
+
*/
|
|
23
|
+
useMargin?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Optional. Background image for the Section component.
|
|
27
|
+
*/
|
|
28
|
+
backgroundImage?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const Section: React.FC<SectionProps> = ({
|
|
32
|
+
children,
|
|
33
|
+
useMargin = true,
|
|
34
|
+
backgroundImage,
|
|
35
|
+
style,
|
|
36
|
+
...props
|
|
37
|
+
}) => {
|
|
38
|
+
const {showGrid} = useContext(ApplicationContext);
|
|
39
|
+
const {numberOfColumns} = useGridSystem();
|
|
8
40
|
|
|
9
|
-
const Section: React.FC<SectionProps> = ({children, useMargin = true}) => {
|
|
10
|
-
const numberOfColumns = 12;
|
|
11
41
|
const gutterSize = 12;
|
|
12
42
|
let margin = 0;
|
|
13
43
|
if (useMargin) {
|
|
@@ -21,7 +51,6 @@ const Section: React.FC<SectionProps> = ({children, useMargin = true}) => {
|
|
|
21
51
|
const gridContext: GridContextProps = {
|
|
22
52
|
numberOfColumns,
|
|
23
53
|
gutterSize,
|
|
24
|
-
margin,
|
|
25
54
|
sizePerSpan,
|
|
26
55
|
getSizeSpan: span => {
|
|
27
56
|
return span * sizePerSpan + (span - 1) * gutterSize;
|
|
@@ -32,20 +61,7 @@ const Section: React.FC<SectionProps> = ({children, useMargin = true}) => {
|
|
|
32
61
|
* render overlay only dev mode
|
|
33
62
|
*/
|
|
34
63
|
const renderOverlay = () => {
|
|
35
|
-
return
|
|
36
|
-
<View
|
|
37
|
-
pointerEvents={'none'}
|
|
38
|
-
style={{
|
|
39
|
-
position: 'absolute',
|
|
40
|
-
top: 0,
|
|
41
|
-
bottom: 0,
|
|
42
|
-
left: 0,
|
|
43
|
-
right: 0,
|
|
44
|
-
borderColor: 'red',
|
|
45
|
-
borderWidth: 1,
|
|
46
|
-
}}
|
|
47
|
-
/>
|
|
48
|
-
);
|
|
64
|
+
return <View pointerEvents={'none'} style={styles.boxGridSection} />;
|
|
49
65
|
};
|
|
50
66
|
|
|
51
67
|
/**
|
|
@@ -91,8 +107,9 @@ const Section: React.FC<SectionProps> = ({children, useMargin = true}) => {
|
|
|
91
107
|
if (Array.isArray(children)) {
|
|
92
108
|
let cursor = 0;
|
|
93
109
|
let rows: any[] = [];
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
const arrayChild = children.filter(item => !!item);
|
|
111
|
+
for (let i = 0; i < arrayChild.length; ++i) {
|
|
112
|
+
const item = arrayChild[i];
|
|
96
113
|
const totalSpan = rows
|
|
97
114
|
.concat([item])
|
|
98
115
|
.map(i => i.props?.widthSpan)
|
|
@@ -108,29 +125,50 @@ const Section: React.FC<SectionProps> = ({children, useMargin = true}) => {
|
|
|
108
125
|
rows = [item];
|
|
109
126
|
}
|
|
110
127
|
|
|
111
|
-
if (i ==
|
|
128
|
+
if (i == arrayChild.length - 1) {
|
|
112
129
|
cursor += 1;
|
|
113
130
|
element.push(addRowView(rows, cursor, true));
|
|
114
131
|
}
|
|
115
132
|
}
|
|
116
133
|
} else {
|
|
117
134
|
element.push(children);
|
|
135
|
+
if (children?.type == Fragment) {
|
|
136
|
+
return renderView(children?.props.children);
|
|
137
|
+
}
|
|
118
138
|
}
|
|
119
139
|
return element;
|
|
120
140
|
};
|
|
121
141
|
|
|
122
142
|
return (
|
|
123
|
-
<GridContext.Provider
|
|
143
|
+
<GridContext.Provider
|
|
144
|
+
value={{
|
|
145
|
+
numberOfColumns,
|
|
146
|
+
gutterSize,
|
|
147
|
+
sizePerSpan,
|
|
148
|
+
getSizeSpan: span => {
|
|
149
|
+
return span * sizePerSpan + (span - 1) * gutterSize;
|
|
150
|
+
},
|
|
151
|
+
}}>
|
|
124
152
|
<View
|
|
125
|
-
|
|
126
|
-
style={
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
{...props}
|
|
154
|
+
style={[
|
|
155
|
+
style,
|
|
156
|
+
styles.protectedStyle,
|
|
157
|
+
{
|
|
158
|
+
width: widthSection,
|
|
159
|
+
marginHorizontal: margin,
|
|
160
|
+
flexDirection: 'row',
|
|
161
|
+
flexWrap: 'wrap',
|
|
162
|
+
},
|
|
163
|
+
]}>
|
|
164
|
+
{!!backgroundImage && (
|
|
165
|
+
<Image
|
|
166
|
+
source={{uri: backgroundImage}}
|
|
167
|
+
style={styles.imageBackground}
|
|
168
|
+
/>
|
|
169
|
+
)}
|
|
170
|
+
{renderView(validateChildren(children, [Item, ItemList]))}
|
|
171
|
+
{showGrid && renderOverlay()}
|
|
134
172
|
</View>
|
|
135
173
|
</GridContext.Provider>
|
|
136
174
|
);
|
package/Layout/index.ts
CHANGED
|
@@ -5,13 +5,23 @@ import {validateChildren} from './utils';
|
|
|
5
5
|
import {createContext} from 'react';
|
|
6
6
|
import {GridContextProps} from './types';
|
|
7
7
|
import Item from './Item';
|
|
8
|
+
import ItemList from './ItemList';
|
|
9
|
+
import ItemSectionList from './ItemSectionList';
|
|
8
10
|
|
|
9
11
|
const GridContext = createContext<GridContextProps>({
|
|
10
12
|
numberOfColumns: 12,
|
|
11
13
|
gutterSize: 12,
|
|
12
|
-
margin: 12,
|
|
13
14
|
sizePerSpan: 0,
|
|
14
|
-
getSizeSpan:
|
|
15
|
+
getSizeSpan: () => 0,
|
|
15
16
|
});
|
|
16
17
|
|
|
17
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
GridContext,
|
|
20
|
+
Card,
|
|
21
|
+
Section,
|
|
22
|
+
GridSystem,
|
|
23
|
+
validateChildren,
|
|
24
|
+
Item,
|
|
25
|
+
ItemList,
|
|
26
|
+
ItemSectionList,
|
|
27
|
+
};
|
package/Layout/styles.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {Platform, StyleSheet} from 'react-native';
|
|
2
|
+
import {Colors, Radius, Spacing} from '../Consts';
|
|
3
|
+
|
|
4
|
+
export default StyleSheet.create({
|
|
5
|
+
extendedHeader: {
|
|
6
|
+
aspectRatio: 1.75,
|
|
7
|
+
position: 'absolute',
|
|
8
|
+
width: '100%',
|
|
9
|
+
height: 210,
|
|
10
|
+
},
|
|
11
|
+
screenBanner: {
|
|
12
|
+
width: '100%',
|
|
13
|
+
},
|
|
14
|
+
boxGrid: {
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
top: 0,
|
|
17
|
+
bottom: 0,
|
|
18
|
+
left: 0,
|
|
19
|
+
right: 0,
|
|
20
|
+
borderColor: 'red',
|
|
21
|
+
borderWidth: 1,
|
|
22
|
+
zIndex: 99,
|
|
23
|
+
},
|
|
24
|
+
boxGridSection: {
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
top: 0,
|
|
27
|
+
bottom: 0,
|
|
28
|
+
left: 0,
|
|
29
|
+
right: 0,
|
|
30
|
+
borderColor: 'blue',
|
|
31
|
+
borderWidth: 2,
|
|
32
|
+
zIndex: 100,
|
|
33
|
+
},
|
|
34
|
+
boxGridCard: {
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
top: 0,
|
|
37
|
+
bottom: 0,
|
|
38
|
+
left: 0,
|
|
39
|
+
right: 0,
|
|
40
|
+
borderColor: 'green',
|
|
41
|
+
borderWidth: 2,
|
|
42
|
+
zIndex: 100,
|
|
43
|
+
},
|
|
44
|
+
card: {
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
flexWrap: 'wrap',
|
|
47
|
+
borderRadius: Radius.M,
|
|
48
|
+
padding: 12,
|
|
49
|
+
},
|
|
50
|
+
item: {
|
|
51
|
+
overflow: 'hidden',
|
|
52
|
+
margin: undefined,
|
|
53
|
+
marginTop: undefined,
|
|
54
|
+
marginBottom: undefined,
|
|
55
|
+
marginLeft: undefined,
|
|
56
|
+
marginRight: undefined,
|
|
57
|
+
marginVertical: undefined,
|
|
58
|
+
marginHorizontal: undefined,
|
|
59
|
+
},
|
|
60
|
+
imageBackground: {
|
|
61
|
+
position: 'absolute',
|
|
62
|
+
top: 0,
|
|
63
|
+
bottom: 0,
|
|
64
|
+
left: 0,
|
|
65
|
+
right: 0,
|
|
66
|
+
},
|
|
67
|
+
protectedStyle: {
|
|
68
|
+
marginTop: undefined,
|
|
69
|
+
marginBottom: undefined,
|
|
70
|
+
marginLeft: undefined,
|
|
71
|
+
marginRight: undefined,
|
|
72
|
+
paddingTop: undefined,
|
|
73
|
+
paddingBottom: undefined,
|
|
74
|
+
paddingLeft: undefined,
|
|
75
|
+
paddingRight: undefined,
|
|
76
|
+
padding: undefined,
|
|
77
|
+
margin: undefined,
|
|
78
|
+
marginHorizontal: undefined,
|
|
79
|
+
marginVertical: undefined,
|
|
80
|
+
paddingHorizontal: undefined,
|
|
81
|
+
paddingVertical: undefined,
|
|
82
|
+
},
|
|
83
|
+
shadow: {
|
|
84
|
+
paddingTop: Spacing.S,
|
|
85
|
+
...Platform.select({
|
|
86
|
+
ios: {
|
|
87
|
+
shadowColor: Colors.black_17,
|
|
88
|
+
shadowOffset: {
|
|
89
|
+
width: 2,
|
|
90
|
+
height: 2,
|
|
91
|
+
},
|
|
92
|
+
shadowOpacity: 0.25,
|
|
93
|
+
shadowRadius: 10,
|
|
94
|
+
},
|
|
95
|
+
android: {
|
|
96
|
+
shadowColor: Colors.black_20,
|
|
97
|
+
elevation: 24,
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
});
|