@momo-kits/foundation 0.79.6-beta.14 → 0.79.6-beta.16

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.
@@ -3,11 +3,13 @@ import {
3
3
  Alert,
4
4
  Animated,
5
5
  DeviceEventEmitter,
6
+ Platform,
6
7
  StatusBar,
7
8
  StyleSheet,
8
- TouchableOpacity,
9
9
  View,
10
+ TouchableOpacity as TouchableRN,
10
11
  } from 'react-native';
12
+ import {TouchableOpacity as TouchableGesture} from 'react-native-gesture-handler';
11
13
  import {ApplicationContext} from './index';
12
14
  import {Colors, Radius, Spacing, Styles} from '../Consts';
13
15
  import {Image} from '../Image';
@@ -22,6 +24,8 @@ import {scaleSize, Text} from '../Text';
22
24
  import {Icon} from '../Icon';
23
25
  import {PopupNotify} from '../Popup';
24
26
 
27
+ const Touchable = Platform.OS === 'android' ? TouchableGesture : TouchableRN;
28
+
25
29
  const styles = StyleSheet.create({
26
30
  navigationButton: {
27
31
  height: 28,
@@ -101,7 +105,7 @@ const NavigationButton: React.FC<NavigationButtonProps> = ({
101
105
  }
102
106
 
103
107
  return (
104
- <TouchableOpacity
108
+ <Touchable
105
109
  accessibilityLabel={`NavigationButton/${accessibilityLabel}`}
106
110
  style={[
107
111
  styles.navigationButton,
@@ -116,7 +120,7 @@ const NavigationButton: React.FC<NavigationButtonProps> = ({
116
120
  color={tintColor ?? theme.colors.text.default}
117
121
  size={20}
118
122
  />
119
- </TouchableOpacity>
123
+ </Touchable>
120
124
  );
121
125
  };
122
126
 
@@ -392,21 +396,17 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
392
396
  borderWidth: backgroundColor ? 0.5 : 0,
393
397
  },
394
398
  ]}>
395
- <TouchableOpacity
396
- accessibilityLabel={'Toolkit/More'}
397
- onPress={onMore}>
399
+ <Touchable accessibilityLabel={'Toolkit/More'} onPress={onMore}>
398
400
  <Icon color={tintColor} source="navigation_more_horiz" size={20} />
399
- </TouchableOpacity>
401
+ </Touchable>
400
402
  <View style={[styles.divider, {backgroundColor: tintColor}]} />
401
- <TouchableOpacity
402
- accessibilityLabel={`Toolkit/Close`}
403
- onPress={onClose}>
403
+ <Touchable accessibilityLabel={`Toolkit/Close`} onPress={onClose}>
404
404
  <Icon
405
405
  color={tintColor}
406
406
  source="16_navigation_close_circle"
407
407
  size={20}
408
408
  />
409
- </TouchableOpacity>
409
+ </Touchable>
410
410
  </View>
411
411
  </View>
412
412
  );
@@ -42,6 +42,9 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
42
42
  }, []);
43
43
 
44
44
  useEffect(() => {
45
+ maxApi?.getLanguage?.((lang: 'vi' | 'en') => {
46
+ setLanguage(lang);
47
+ });
45
48
  const listener = maxApi?.observer?.('language', (lang: 'vi' | 'en') => {
46
49
  setLanguage(lang);
47
50
  });
@@ -1,4 +1,4 @@
1
- import React, {useContext, useEffect} from 'react';
1
+ import React, {useContext, useLayoutEffect} from 'react';
2
2
  import {ScreenParams} from './types';
3
3
  import Navigation from './Navigation';
4
4
  import {ApplicationContext} from './index';
@@ -16,7 +16,7 @@ const StackScreen: React.FC<ScreenParams> = props => {
16
16
 
17
17
  delete params.screen;
18
18
 
19
- useEffect(() => {
19
+ useLayoutEffect(() => {
20
20
  if (options) {
21
21
  navigation.setOptions(options);
22
22
  }
package/Layout/Screen.tsx CHANGED
@@ -107,12 +107,10 @@ const Screen: React.FC<ScreenProps> = ({
107
107
  if (useExtendedHeader) {
108
108
  title = {headerTitle: HeaderTitle};
109
109
  }
110
- setImmediate(() => {
111
- navigation?.setOptions({
112
- animatedValue: animatedValue.current,
113
- headerTransparent: headerTransparent,
114
- ...title,
115
- });
110
+ navigation?.setOptions({
111
+ animatedValue: animatedValue.current,
112
+ headerTransparent: headerTransparent,
113
+ ...title,
116
114
  });
117
115
  }
118
116
  }, [useExtendedHeader, useAnimatedHeader]);
@@ -1,4 +1,4 @@
1
- import React, {useContext} from 'react';
1
+ import React, {Fragment, useContext} from 'react';
2
2
  import {Dimensions, View, ViewProps} from 'react-native';
3
3
  import {useGridSystem, validateChildren} from './utils';
4
4
  import {GridContextProps} from './types';
@@ -135,6 +135,9 @@ const Section: React.FC<SectionProps> = ({
135
135
  }
136
136
  } else {
137
137
  element.push(children);
138
+ if (children?.type == Fragment) {
139
+ return renderView(children?.props.children);
140
+ }
138
141
  }
139
142
  return element;
140
143
  };
package/Layout/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {Alert, Dimensions} from 'react-native';
2
- import React, {useEffect, useState} from 'react';
2
+ import React, {Fragment, ReactElement, useEffect, useState} from 'react';
3
3
 
4
4
  /**
5
5
  * validate children type
@@ -7,53 +7,36 @@ import React, {useEffect, useState} from 'react';
7
7
  * @param childrenTypes
8
8
  */
9
9
  const validateChildren = (
10
- children:
11
- | React.ReactElement<any, string | React.JSXElementConstructor<any>>
12
- | string
13
- | number
14
- | {}
15
- | Iterable<React.ReactNode>
16
- | React.ReactPortal
17
- | null
18
- | undefined
19
- | boolean,
20
- childrenTypes: Array<React.FC<any>>,
10
+ children: React.ReactNode | React.ReactNode[],
11
+ childrenTypes: Array<React.FC>,
21
12
  ) => {
22
13
  if (!__DEV__) return children;
23
14
 
24
- let results: React.ReactElement[] = [];
25
15
  const validateType = (child: React.ReactElement) => {
26
- return childrenTypes.some(childrenType => child?.type === childrenType);
27
- };
28
-
29
- const alertWrongType = () => {
30
- Alert.alert(
31
- 'Component Kits',
32
- `Wrong children type for this component, expected are ${childrenTypes
33
- .map(type => type.displayName)
34
- .join(', ')}.`,
16
+ const valid = childrenTypes.some(
17
+ childrenType => child?.type === childrenType || child?.type == Fragment,
35
18
  );
19
+ if (!valid) {
20
+ Alert.alert(
21
+ 'Component Kits',
22
+ `Wrong children type for this component, expected are ${childrenTypes
23
+ .map(type => type.displayName)
24
+ .join(', ')}.`,
25
+ );
26
+ }
27
+ return valid;
36
28
  };
37
29
 
38
30
  if (Array.isArray(children)) {
39
31
  const flattenChildren: React.ReactElement[] = children.flat();
40
- results = flattenChildren.filter((child: React.ReactElement) => {
41
- if (validateType(child)) {
42
- return child;
43
- } else {
44
- alertWrongType();
45
- }
46
- });
47
- } else {
48
- const singleChild: any = children;
49
- if (validateType(singleChild)) {
50
- results = [singleChild];
51
- } else {
52
- alertWrongType();
32
+ for (const child of flattenChildren) {
33
+ validateType(child);
53
34
  }
35
+ return flattenChildren;
36
+ } else {
37
+ validateType(children as ReactElement);
38
+ return children;
54
39
  }
55
-
56
- return results;
57
40
  };
58
41
 
59
42
  const useGridSystem = () => {
package/Switch/index.tsx CHANGED
@@ -1,10 +1,9 @@
1
1
  import React, {FC} from 'react';
2
- import {NativeModules, TouchableOpacity, View} from 'react-native';
2
+ import {TouchableOpacity, View} from 'react-native';
3
3
  import {SwitchProps} from './types';
4
4
  import styles from './styles';
5
5
  import {Colors} from '../Consts';
6
6
 
7
- const {HapticModule} = NativeModules;
8
7
  const Switch: FC<SwitchProps> = props => {
9
8
  const {value, onChange, disabled, style} = props;
10
9
  const circleBackgroundColor = value ? Colors.black_01 : Colors.black_03;
@@ -15,16 +14,11 @@ const Switch: FC<SwitchProps> = props => {
15
14
  backgroundColor = value ? Colors.green_09 : Colors.black_05;
16
15
  }
17
16
 
18
- const onChangeValue = () => {
19
- HapticModule?.triggerHaptic?.('medium');
20
- onChange?.(!value);
21
- };
22
-
23
17
  return (
24
18
  <TouchableOpacity
25
19
  accessibilityLabel={'Switch'}
26
20
  disabled={disabled}
27
- onPress={onChangeValue}
21
+ onPress={() => onChange?.(!value)}
28
22
  style={[
29
23
  style,
30
24
  styles.container,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.79.6-beta.14",
3
+ "version": "0.79.6-beta.16",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {