@momo-kits/foundation 0.75.1-beta.16 → 0.75.1-beta.18

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 CHANGED
@@ -1,17 +1,18 @@
1
1
  import React from 'react';
2
- import {Dimensions, View} from 'react-native';
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 = Dimensions.get('window').width > 600 ? 24 : 12;
10
+ const {numberOfColumns, window} = useGridSystem();
11
+
11
12
  const gutterSize = 8;
12
13
  const margin = 12;
13
14
 
14
- const widthSection = Dimensions.get('window').width - margin * 2;
15
+ const widthSection = window.width - margin * 2;
15
16
  const totalGutterSize = gutterSize * (numberOfColumns - 1);
16
17
  const sizePerSpan = (widthSection - totalGutterSize - 24) / numberOfColumns;
17
18
 
@@ -1,16 +1,18 @@
1
1
  import React, {useContext} from 'react';
2
2
  import {useSafeAreaInsets} from 'react-native-safe-area-context';
3
- import {Dimensions, StyleSheet, View} from 'react-native';
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 = Dimensions.get('window').width > 600 ? 24 : 12;
11
+ const {numberOfColumns, window} = useGridSystem();
12
+
11
13
  const gutterSize = 12;
12
14
  const margin = 12;
13
- const widthSection = Dimensions.get('window').width - margin * 2;
15
+ const widthSection = window.width - margin * 2;
14
16
  const totalGutterSize = gutterSize * (numberOfColumns - 1);
15
17
  const sizePerSpan = (widthSection - totalGutterSize) / numberOfColumns;
16
18
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import {Dimensions, View} from 'react-native';
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 = Dimensions.get('window').width > 600 ? 24 : 12;
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 = Dimensions.get('window').width;
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,26 @@ const validateChildren = (
56
56
  return results;
57
57
  };
58
58
 
59
- export {validateChildren};
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
+ alert(`change ${newColumns}`);
71
+ setNumberOfColumns(newColumns);
72
+ }
73
+ },
74
+ );
75
+ return () => subscription?.remove();
76
+ }, []);
77
+
78
+ return {numberOfColumns, window: Dimensions.get('window')};
79
+ };
80
+
81
+ export {validateChildren, useGridSystem};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.75.1-beta.16",
3
+ "version": "0.75.1-beta.18",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {