@momo-kits/foundation 0.81.43-api.1 → 0.81.43-beta.10

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,45 +3,29 @@ import {Platform} from 'react-native';
3
3
  import {BottomTabProps, NavigationScreenProps} from './types';
4
4
  import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
5
5
  import {createStackNavigator} from '@react-navigation/stack';
6
- import {useSafeAreaInsets} from 'react-native-safe-area-context';
7
- import {NavigationContainer} from '@react-navigation/native';
8
6
  import {Icon} from '../Icon';
9
7
  import {Text} from '../Text';
10
8
  import {ApplicationContext} from './index';
11
9
  import {getStackOptions} from './utils';
12
10
  import StackScreen from './StackScreen';
11
+ import {useSafeAreaInsets} from 'react-native-safe-area-context';
13
12
 
14
13
  const Tab = createBottomTabNavigator();
15
14
  const Stack = createStackNavigator();
16
15
 
17
16
  const TabScreen: React.FC<NavigationScreenProps> = ({route}) => {
18
- if (route.params?.nested) {
19
- return (
20
- <Stack.Navigator>
21
- <Stack.Screen
22
- name="Stack"
23
- component={StackScreen}
24
- initialParams={{screen: route.params?.screen}}
25
- options={{...getStackOptions(), ...route.params?.options}}
26
- />
27
- </Stack.Navigator>
28
- );
29
- }
30
17
  return (
31
- <NavigationContainer independent={true}>
32
- <Stack.Navigator>
33
- <Stack.Screen
34
- name="Stack"
35
- component={StackScreen}
36
- initialParams={{screen: route.params?.screen}}
37
- options={{...getStackOptions(), ...route.params?.options}}
38
- />
39
- </Stack.Navigator>
40
- </NavigationContainer>
18
+ <Stack.Navigator>
19
+ <Stack.Screen
20
+ name="Stack"
21
+ component={StackScreen}
22
+ initialParams={{screen: route.params?.screen}}
23
+ options={{...getStackOptions(), ...route.params?.options}}
24
+ />
25
+ </Stack.Navigator>
41
26
  );
42
27
  };
43
28
  const BottomTab: React.FC<BottomTabProps> = ({
44
- nested,
45
29
  tabs,
46
30
  listeners,
47
31
  navigation,
@@ -77,7 +61,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
77
61
  key={item.name}
78
62
  name={item.name}
79
63
  component={TabScreen}
80
- initialParams={{...item, nested}}
64
+ initialParams={item}
81
65
  listeners={listeners}
82
66
  options={{
83
67
  tabBarLabel: ({color, focused}) => {
@@ -95,7 +95,7 @@ const styles = StyleSheet.create({
95
95
  badge: {
96
96
  position: 'absolute',
97
97
  top: -8,
98
- right: -8,
98
+ right: -6,
99
99
  },
100
100
  });
101
101
 
@@ -347,10 +347,14 @@ const HeaderRightAction: React.FC<any> = ({children, ...restProps}) => {
347
347
  return <View style={styles.headerRightButton}>{renderAction()}</View>;
348
348
  };
349
349
 
350
- const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
350
+ const HeaderToolkitAction: React.FC<any> = ({
351
+ tintColor,
352
+ pinnedTool = {key: '', badgeValue: undefined, badgeTye: undefined},
353
+ preventBack,
354
+ }) => {
351
355
  const {theme, navigator} = useContext(ApplicationContext);
352
- const [toolConfig, setToolConfig] = useState<HeaderToolkitProps>();
353
- const {appCode, hidden, type, onAction} = toolConfig ?? {};
356
+ const [toolConfig, setToolConfig] = useState<any>();
357
+ const {appCode, onAction} = toolConfig ?? {};
354
358
 
355
359
  let backgroundColor;
356
360
  if (tintColor != Colors.black_01) {
@@ -361,20 +365,21 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
361
365
  if (navigator?.toolkitConfig) {
362
366
  setToolConfig(navigator?.toolkitConfig);
363
367
  } else {
364
- navigator?.requestApi('getToolkit', [undefined], (result: boolean) => {
365
- if (result) {
366
- navigator?.requestApi(
367
- 'getToolkitConfig',
368
- [undefined],
369
- (config: any) => {
370
- navigator.toolkitConfig = {
371
- ...config?.utilityToolConfig,
372
- appCode: config?.appCode,
373
- };
374
- setToolConfig(navigator?.toolkitConfig);
375
- },
376
- );
377
- }
368
+ navigator?.requestApi('getToolkitConfig', [undefined], (config: any) => {
369
+ navigator.toolkitConfig = {
370
+ configs: [
371
+ ...config?.miniappTools?.customTools,
372
+ ...config?.defaultTools,
373
+ ],
374
+ appCode: config?.appCode,
375
+ };
376
+ setToolConfig({
377
+ configs: [
378
+ ...config?.miniappTools?.customTools,
379
+ ...config?.defaultTools,
380
+ ],
381
+ appCode: config?.appCode,
382
+ });
378
383
  });
379
384
  }
380
385
  }, []);
@@ -417,39 +422,66 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
417
422
  };
418
423
  }, [appCode]);
419
424
 
420
- const onUtilityTool = () => {
421
- onAction?.('onUtilityTool');
422
- navigator?.requestApi(type, undefined, undefined);
423
- };
424
-
425
425
  const onMore = () => {
426
426
  onAction?.('onMore');
427
- navigator?.requestApi('showToolkit', [toolConfig], undefined);
427
+ navigator?.requestApi(
428
+ 'showTools',
429
+ [toolConfig],
430
+ (res: {item: {action?: string; key: string}}) => {
431
+ const {item} = res;
432
+ navigator?.toolkitCallback?.(item);
433
+ },
434
+ );
428
435
  };
429
436
 
430
437
  const onClose = () => {
431
- onAction?.('onClose');
432
- navigator?.requestApi('dismiss', undefined, undefined);
438
+ if (preventBack) {
439
+ navigator?.showModal({
440
+ screen: () => (
441
+ <PopupNotify
442
+ {...preventBack}
443
+ primary={{
444
+ title: preventBack.primary.title,
445
+ onPress: () => {
446
+ preventBack?.primary.onPress();
447
+ navigator?.requestApi('dismiss', undefined, undefined);
448
+ },
449
+ }}
450
+ />
451
+ ),
452
+ });
453
+ } else {
454
+ navigator?.requestApi('dismiss', undefined, undefined);
455
+ }
433
456
  };
434
457
 
435
- const renderUtilityTool = () => {
436
- if (hidden === false) {
458
+ const renderPinnedTool = () => {
459
+ const pinTool = toolConfig?.configs?.find(
460
+ (i: any) => i.key === pinnedTool.key,
461
+ );
462
+
463
+ const {badgeValue, badgeType} = pinnedTool;
464
+ const {icon} = pinTool || '';
465
+
466
+ if (pinTool && pinnedTool)
437
467
  return (
438
468
  <NavigationButton
439
469
  accessibilityLabel={'UtilityTool'}
440
- icon={type as string}
470
+ icon={icon as string}
441
471
  tintColor={tintColor}
442
- onPress={onUtilityTool}
472
+ badgeValue={badgeValue}
473
+ badgeType={badgeType}
474
+ onPress={() => {
475
+ navigator?.toolkitCallback?.(pinnedTool.key);
476
+ }}
443
477
  />
444
478
  );
445
- }
446
- return null;
447
479
  };
448
480
 
449
481
  if (toolConfig) {
450
482
  return (
451
483
  <View style={styles.headerRightButton}>
452
- {renderUtilityTool()}
484
+ {renderPinnedTool()}
453
485
  <View
454
486
  style={[
455
487
  styles.toolkitContainer,
@@ -13,6 +13,7 @@ class Navigator {
13
13
  maxApi?: any;
14
14
  trackingInfo?: TrackingInfo;
15
15
  dismissData?: any;
16
+ toolkitCallback?: (item: any) => void;
16
17
 
17
18
  constructor(navigation: any) {
18
19
  this.ref = navigation;
@@ -121,6 +122,12 @@ class Navigator {
121
122
  this.maxApi[func]?.(...args, callback);
122
123
  }
123
124
  };
125
+
126
+ setToolkitCallback = (
127
+ callback: (item: {key: string; action: string}) => void,
128
+ ) => {
129
+ this.toolkitCallback = callback;
130
+ };
124
131
  }
125
132
 
126
133
  export default Navigator;
@@ -128,8 +128,14 @@ export type NavigationButtonProps = {
128
128
  useBorder?: boolean;
129
129
  onPress: () => void;
130
130
  accessibilityLabel?: string;
131
- badgeType?: 'dot' | 'number' | 'string';
132
- badgeValue?: number | string;
131
+ badgeType?: 'dot' | 'number';
132
+ badgeValue?: number;
133
+ };
134
+
135
+ export type PinnedToolType = {
136
+ key: string;
137
+ badgeValue?: number;
138
+ badgeType?: 'number' | 'dot';
133
139
  };
134
140
 
135
141
  export interface NavigationOptions extends StackNavigationOptions {
@@ -138,6 +144,7 @@ export interface NavigationOptions extends StackNavigationOptions {
138
144
  surface?: boolean;
139
145
  hiddenBack?: boolean;
140
146
  customTitle?: TitleCustomProps;
147
+ pinnedTool?: PinnedToolType;
141
148
  }
142
149
 
143
150
  export interface HeaderBackProps extends NavigationButtonProps {
@@ -166,9 +173,7 @@ export type TitleCustomProps = {
166
173
  export type HeaderToolkitProps = {
167
174
  [key: string]: any;
168
175
  appCode: string;
169
- hidden: boolean;
170
- type: string;
171
- onAction?: (action: string) => void;
176
+ configs: any[];
172
177
  };
173
178
 
174
179
  export type HeaderAnimatedProps = {
@@ -188,7 +193,6 @@ export type BottomTabItemProps = {
188
193
  };
189
194
 
190
195
  export type BottomTabProps = {
191
- nested?: boolean;
192
196
  tabs: BottomTabItemProps[];
193
197
  initialRouteName?: string;
194
198
  navigation: Navigation;
@@ -126,6 +126,21 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
126
126
  };
127
127
  }
128
128
 
129
+ if (params.pinnedTool) {
130
+ options = {
131
+ ...options,
132
+ headerRight: (props: any) => {
133
+ return (
134
+ <HeaderToolkitAction
135
+ preventBack={params.preventBack}
136
+ pinnedTool={params.pinnedTool}
137
+ {...props}
138
+ />
139
+ );
140
+ },
141
+ };
142
+ }
143
+
129
144
  return {
130
145
  ...params,
131
146
  ...options,
package/Badge/styles.ts CHANGED
@@ -4,13 +4,16 @@ import {scaleSize} from '../Text';
4
4
 
5
5
  export default StyleSheet.create({
6
6
  badge: {
7
+ paddingHorizontal: Spacing.XS,
7
8
  borderRadius: Radius.M,
8
9
  justifyContent: 'center',
10
+ alignItems: 'center',
9
11
  height: scaleSize(16),
12
+ minWidth: scaleSize(16),
10
13
  flexDirection: 'row',
14
+ borderWidth: 1,
11
15
  borderColor: Colors.black_01,
12
- paddingHorizontal: Spacing.XS,
13
- alignItems: 'center',
16
+ alignSelf: 'baseline',
14
17
  },
15
18
  dot: {
16
19
  width: 16,
package/Layout/Card.tsx CHANGED
@@ -29,7 +29,7 @@ const Card: React.FC<CardProps> = ({
29
29
  useShadow = false,
30
30
  ...props
31
31
  }) => {
32
- const {showGrid, theme} = useContext(ApplicationContext);
32
+ const {showGrid} = useContext(ApplicationContext);
33
33
  const {numberOfColumns} = useGridSystem();
34
34
 
35
35
  const gutterSize = 8;
@@ -47,7 +47,6 @@ const Card: React.FC<CardProps> = ({
47
47
  return span * sizePerSpan + (span - 1) * gutterSize;
48
48
  },
49
49
  };
50
-
51
50
  /**
52
51
  * render overlay only dev mode
53
52
  */
@@ -108,9 +107,8 @@ const Card: React.FC<CardProps> = ({
108
107
  if (Array.isArray(children)) {
109
108
  let cursor = 0;
110
109
  let rows: any[] = [];
111
- const arrayChild = children.filter(item => !!item);
112
- for (let i = 0; i < arrayChild.length; ++i) {
113
- const item = arrayChild[i];
110
+ for (let i = 0; i < children.length; ++i) {
111
+ const item = children[i];
114
112
  const totalSpan = rows
115
113
  .concat([item])
116
114
  .map(i => i.props?.widthSpan)
@@ -126,7 +124,7 @@ const Card: React.FC<CardProps> = ({
126
124
  rows = [item];
127
125
  }
128
126
 
129
- if (i == arrayChild.length - 1) {
127
+ if (i == children.length - 1) {
130
128
  cursor += 1;
131
129
  element.push(addRowView(rows, cursor, true));
132
130
  }
@@ -140,21 +138,23 @@ const Card: React.FC<CardProps> = ({
140
138
  return element;
141
139
  };
142
140
 
141
+ const {theme} = useContext(ApplicationContext);
143
142
  return (
144
143
  <GridContext.Provider value={gridContext}>
145
144
  <View
146
145
  {...props}
147
146
  accessibilityLabel={`Card`}
148
147
  style={[
149
- {backgroundColor: theme.colors.background.surface},
150
148
  style,
151
149
  styles.protectedStyle,
152
150
  styles.card,
153
151
  {
154
152
  width: widthSection,
155
153
  marginHorizontal: margin,
154
+ backgroundColor: backgroundImage
155
+ ? undefined
156
+ : theme.colors.background.surface,
156
157
  },
157
- !!backgroundImage && {backgroundColor: undefined},
158
158
  useShadow && Shadow.Light,
159
159
  ]}>
160
160
  {!!backgroundImage && (
@@ -1,4 +1,4 @@
1
- import React, {forwardRef, useContext} from 'react';
1
+ import React, {FC, useContext} from 'react';
2
2
  import {FlatList, FlatListProps, View} from 'react-native';
3
3
  import Item, {SpanNumber} from './Item';
4
4
  import {GridContext} from './index';
@@ -11,45 +11,39 @@ export interface ItemListProps extends FlatListProps<any> {
11
11
  widthSpan?: SpanNumber;
12
12
  }
13
13
 
14
- const ItemList = forwardRef(
15
- (
16
- {
17
- renderItem,
18
- widthSpan,
19
- style,
20
- contentContainerStyle,
21
- ...props
22
- }: ItemListProps,
23
- ref,
24
- ) => {
25
- const {gutterSize, numberOfColumns} = useContext(GridContext);
26
- const widthItem = (widthSpan ?? numberOfColumns) as SpanNumber;
27
- const numColumns = Math.floor(numberOfColumns / widthItem);
28
- const indexBegin = props?.data?.map((_i, index) => index * numColumns);
29
- const _renderItem = (item: any) => {
30
- if (indexBegin?.includes(item?.index)) {
31
- return <Item widthSpan={widthItem}>{renderItem?.(item)}</Item>;
32
- }
33
- return (
34
- <View style={{paddingLeft: gutterSize}}>
35
- <Item widthSpan={widthItem}>{renderItem?.(item)}</Item>
36
- </View>
37
- );
38
- };
39
-
14
+ const ItemList: FC<ItemListProps> = ({
15
+ renderItem,
16
+ widthSpan,
17
+ style,
18
+ contentContainerStyle,
19
+ ...props
20
+ }) => {
21
+ const {gutterSize, numberOfColumns} = useContext(GridContext);
22
+ const widthItem = (widthSpan ?? numberOfColumns) as SpanNumber;
23
+ const numColumns = Math.floor(numberOfColumns / widthItem);
24
+ const indexBegin = props?.data?.map((_i, index) => index * numColumns);
25
+ const _renderItem = (item: any) => {
26
+ if (indexBegin?.includes(item?.index)) {
27
+ return <Item widthSpan={widthItem}>{renderItem?.(item)}</Item>;
28
+ }
40
29
  return (
41
- <FlatList
42
- ref={ref as React.RefObject<FlatList>}
43
- {...props}
44
- numColumns={numColumns}
45
- renderItem={_renderItem}
46
- horizontal={false}
47
- ItemSeparatorComponent={() => <View style={{height: gutterSize}} />}
48
- style={[style, styles.protectedStyle]}
49
- contentContainerStyle={[contentContainerStyle, styles.protectedStyle]}
50
- />
30
+ <View style={{paddingLeft: gutterSize}}>
31
+ <Item widthSpan={widthItem}>{renderItem?.(item)}</Item>
32
+ </View>
51
33
  );
52
- },
53
- );
34
+ };
35
+
36
+ return (
37
+ <FlatList
38
+ {...props}
39
+ numColumns={numColumns}
40
+ renderItem={_renderItem}
41
+ horizontal={false}
42
+ ItemSeparatorComponent={() => <View style={{height: gutterSize}} />}
43
+ style={[style, styles.protectedStyle]}
44
+ contentContainerStyle={[contentContainerStyle, styles.protectedStyle]}
45
+ />
46
+ );
47
+ };
54
48
 
55
49
  export default ItemList;
@@ -107,9 +107,8 @@ const Section: React.FC<SectionProps> = ({
107
107
  if (Array.isArray(children)) {
108
108
  let cursor = 0;
109
109
  let rows: any[] = [];
110
- const arrayChild = children.filter(item => !!item);
111
- for (let i = 0; i < arrayChild.length; ++i) {
112
- const item = arrayChild[i];
110
+ for (let i = 0; i < children.length; ++i) {
111
+ const item = children[i];
113
112
  const totalSpan = rows
114
113
  .concat([item])
115
114
  .map(i => i.props?.widthSpan)
@@ -125,7 +124,7 @@ const Section: React.FC<SectionProps> = ({
125
124
  rows = [item];
126
125
  }
127
126
 
128
- if (i == arrayChild.length - 1) {
127
+ if (i == children.length - 1) {
129
128
  cursor += 1;
130
129
  element.push(addRowView(rows, cursor, true));
131
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.81.43-api.1",
3
+ "version": "0.81.43-beta.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/verify.js CHANGED
@@ -27,9 +27,8 @@ try {
27
27
  }
28
28
 
29
29
  if (
30
- miniInfo?.dependencies?.['@momo-platform/momo-core'] &&
31
- miniInfo?.dependencies?.['@momo-platform/momo-core'] !==
32
- packageInfo?.version
30
+ miniInfo?.name !== '@momo-platform/momo-core' &&
31
+ miniInfo?.resolutions?.['@momo-platform/momo-core'] !== packageInfo?.version
33
32
  ) {
34
33
  console.error(
35
34
  `Package ${packageInfo.name} version: ${packageInfo.version} require install resolutions @momo-platform/momo-core ${packageInfo.version}`,