@momo-kits/foundation 0.75.1-beta.15 → 0.75.1-beta.17
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/Layout/Card.tsx +5 -4
- package/Layout/GridSystem.tsx +5 -3
- package/Layout/ScreenContainer.tsx +1 -1
- package/Layout/Section.tsx +5 -4
- package/Layout/utils.ts +24 -3
- package/package.json +1 -1
package/Layout/Card.tsx
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {validateChildren} from './utils';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {useGridSystem, validateChildren} from './utils';
|
|
4
4
|
import {CardProps, GridContextProps} from './types';
|
|
5
5
|
import {GridContext} from './index';
|
|
6
6
|
import {GRIDVIEW} from '../Consts';
|
|
7
7
|
import Item from './Item';
|
|
8
8
|
|
|
9
9
|
const Card: React.FC<CardProps> = ({children, style}) => {
|
|
10
|
-
const numberOfColumns =
|
|
10
|
+
const {numberOfColumns, window} = useGridSystem();
|
|
11
|
+
|
|
11
12
|
const gutterSize = 8;
|
|
12
13
|
const margin = 12;
|
|
13
14
|
|
|
14
|
-
const widthSection =
|
|
15
|
+
const widthSection = window.width - margin * 2;
|
|
15
16
|
const totalGutterSize = gutterSize * (numberOfColumns - 1);
|
|
16
17
|
const sizePerSpan = (widthSection - totalGutterSize - 24) / numberOfColumns;
|
|
17
18
|
|
package/Layout/GridSystem.tsx
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import React, {useContext} from 'react';
|
|
2
2
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
3
|
-
import {
|
|
3
|
+
import {StyleSheet, View} from 'react-native';
|
|
4
4
|
import {ApplicationContext} from '../Navigation';
|
|
5
5
|
import {Colors, Spacing} from '../Consts';
|
|
6
6
|
import {GridContextProps} from './types';
|
|
7
|
+
import {useGridSystem} from './utils';
|
|
7
8
|
|
|
8
9
|
const GridSystem: React.FC = () => {
|
|
9
10
|
const {theme} = useContext(ApplicationContext);
|
|
10
|
-
const numberOfColumns =
|
|
11
|
+
const {numberOfColumns, window} = useGridSystem();
|
|
12
|
+
|
|
11
13
|
const gutterSize = 12;
|
|
12
14
|
const margin = 12;
|
|
13
|
-
const widthSection =
|
|
15
|
+
const widthSection = window.width - margin * 2;
|
|
14
16
|
const totalGutterSize = gutterSize * (numberOfColumns - 1);
|
|
15
17
|
const sizePerSpan = (widthSection - totalGutterSize) / numberOfColumns;
|
|
16
18
|
|
|
@@ -57,7 +57,7 @@ const ScreenContainer: React.FC<ScreenContainerProps> = ({
|
|
|
57
57
|
const results = validateChildren(children, [Section, Card]);
|
|
58
58
|
if (Array.isArray(results)) {
|
|
59
59
|
return results.map((item, index) => {
|
|
60
|
-
const space = item.props
|
|
60
|
+
const space = item.props?.useMargin === false ? 0 : Spacing.M;
|
|
61
61
|
return (
|
|
62
62
|
<View
|
|
63
63
|
key={`ScreenItem${index}`}
|
package/Layout/Section.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {validateChildren} from './utils';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {useGridSystem, validateChildren} from './utils';
|
|
4
4
|
import {GridContextProps, SectionProps} from './types';
|
|
5
5
|
import {GridContext} from './index';
|
|
6
6
|
import {GRIDVIEW} from '../Consts';
|
|
@@ -11,13 +11,14 @@ const Section: React.FC<SectionProps> = ({
|
|
|
11
11
|
useMargin = true,
|
|
12
12
|
backgroundColor,
|
|
13
13
|
}) => {
|
|
14
|
-
const numberOfColumns =
|
|
14
|
+
const {numberOfColumns, window} = useGridSystem();
|
|
15
|
+
|
|
15
16
|
const gutterSize = 12;
|
|
16
17
|
let margin = 0;
|
|
17
18
|
if (useMargin) {
|
|
18
19
|
margin = 12;
|
|
19
20
|
}
|
|
20
|
-
let widthSection =
|
|
21
|
+
let widthSection = window.width;
|
|
21
22
|
if (useMargin) widthSection = widthSection - margin * 2;
|
|
22
23
|
const totalGutterSize = gutterSize * (numberOfColumns - 1);
|
|
23
24
|
const sizePerSpan = (widthSection - totalGutterSize) / numberOfColumns;
|
package/Layout/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Alert} from 'react-native';
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import {Alert, Dimensions} from 'react-native';
|
|
2
|
+
import React, {useEffect, useState} from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* validate children type
|
|
@@ -56,4 +56,25 @@ const validateChildren = (
|
|
|
56
56
|
return results;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
const useGridSystem = () => {
|
|
60
|
+
const [numberOfColumns, setNumberOfColumns] = useState(
|
|
61
|
+
Dimensions.get('window').width > 600 ? 24 : 12,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const subscription: any = Dimensions.addEventListener(
|
|
66
|
+
'change',
|
|
67
|
+
({window}: any) => {
|
|
68
|
+
const newColumns = window.width > 600 ? 24 : 12;
|
|
69
|
+
if (numberOfColumns !== newColumns) {
|
|
70
|
+
setNumberOfColumns(newColumns);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
return () => subscription?.remove();
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
return {numberOfColumns, window: Dimensions.get('window')};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export {validateChildren, useGridSystem};
|