@momo-kits/foundation 0.112.1-rn76.44 → 0.112.1-rn76.45-test1
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/BottomTab/index.tsx +2 -3
- package/Application/ModalScreen.tsx +39 -22
- package/Application/Navigation.ts +0 -3
- package/Application/NavigationContainer.tsx +0 -2
- package/Application/Navigator.ts +10 -2
- package/Application/WidgetContainer.tsx +133 -0
- package/Application/index.ts +2 -0
- package/Application/types.ts +11 -11
- package/Popup/PopupPromotion.tsx +14 -11
- package/Popup/types.ts +5 -0
- package/package.json +3 -3
|
@@ -155,7 +155,6 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
155
155
|
const activeIndex = useRef(initialIndex > 0 ? initialIndex : 0);
|
|
156
156
|
const itemWidth = dimensions.width / tabs.length;
|
|
157
157
|
|
|
158
|
-
console.log('CCC', floatingButton);
|
|
159
158
|
useLayoutEffect(() => {
|
|
160
159
|
navigation?.setOptions({
|
|
161
160
|
headerShown: false,
|
|
@@ -248,7 +247,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
248
247
|
/>
|
|
249
248
|
)}
|
|
250
249
|
initialRouteName={initialRouteName}>
|
|
251
|
-
{tabs.map(item => {
|
|
250
|
+
{tabs.map((item, index) => {
|
|
252
251
|
const isNum = !isNaN(parseInt(`${item?.badgeLabel}`, 10));
|
|
253
252
|
const isDot = typeof item?.badgeLabel === 'string' && !item?.badgeLabel;
|
|
254
253
|
return (
|
|
@@ -256,7 +255,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
256
255
|
key={`BottomTab-${item.name}`}
|
|
257
256
|
name={item.name}
|
|
258
257
|
component={TabScreen}
|
|
259
|
-
initialParams={{...item, nested}}
|
|
258
|
+
initialParams={{...item, nested, index}}
|
|
260
259
|
listeners={handler}
|
|
261
260
|
options={{
|
|
262
261
|
tabBarLabel: ({focused, color}) => {
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
Platform,
|
|
7
7
|
Pressable,
|
|
8
8
|
StyleSheet,
|
|
9
|
+
View,
|
|
10
|
+
Modal as ModalRN,
|
|
9
11
|
} from 'react-native';
|
|
10
12
|
|
|
11
13
|
import {ApplicationContext} from './index';
|
|
@@ -23,7 +25,12 @@ const ModalScreen: React.FC<any> = props => {
|
|
|
23
25
|
|
|
24
26
|
const Modal: React.FC<ModalParams> = props => {
|
|
25
27
|
const {navigator} = useContext(ApplicationContext);
|
|
26
|
-
const {
|
|
28
|
+
const {
|
|
29
|
+
screen,
|
|
30
|
+
barrierDismissible,
|
|
31
|
+
modalStyle,
|
|
32
|
+
useNativeModal = false,
|
|
33
|
+
} = props.route.params;
|
|
27
34
|
const Component = useRef(screen).current;
|
|
28
35
|
const opacity = useRef(new Animated.Value(0)).current;
|
|
29
36
|
const scale = useRef(new Animated.Value(0.8)).current;
|
|
@@ -34,6 +41,10 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
34
41
|
navigation,
|
|
35
42
|
};
|
|
36
43
|
delete params.screen;
|
|
44
|
+
let Container: any = View;
|
|
45
|
+
if (useNativeModal) {
|
|
46
|
+
Container = ModalRN;
|
|
47
|
+
}
|
|
37
48
|
|
|
38
49
|
useEffect(() => {
|
|
39
50
|
Animated.parallel([
|
|
@@ -55,8 +66,8 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
55
66
|
};
|
|
56
67
|
}, [opacity, scale]);
|
|
57
68
|
|
|
58
|
-
const onDismiss = (callback = () => {}) => {
|
|
59
|
-
if (
|
|
69
|
+
const onDismiss = (callback = () => {}, preventClose = false) => {
|
|
70
|
+
if (preventClose) {
|
|
60
71
|
return;
|
|
61
72
|
}
|
|
62
73
|
Animated.parallel([
|
|
@@ -78,25 +89,31 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
78
89
|
};
|
|
79
90
|
|
|
80
91
|
return (
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
<Container
|
|
93
|
+
transparent
|
|
94
|
+
visible={true}
|
|
95
|
+
onRequestClose={onDismiss}
|
|
96
|
+
style={StyleSheet.absoluteFillObject}>
|
|
97
|
+
<KeyboardAvoidingView
|
|
98
|
+
style={Styles.flexCenter}
|
|
99
|
+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
|
|
100
|
+
<Pressable
|
|
101
|
+
style={StyleSheet.absoluteFillObject}
|
|
102
|
+
onPress={() => onDismiss(undefined, barrierDismissible)}>
|
|
103
|
+
<Animated.View style={[styles.overlayContent, {opacity}]} />
|
|
104
|
+
</Pressable>
|
|
105
|
+
<Animated.View
|
|
106
|
+
style={[
|
|
107
|
+
{
|
|
108
|
+
opacity,
|
|
109
|
+
transform: [{scale}],
|
|
110
|
+
},
|
|
111
|
+
modalStyle,
|
|
112
|
+
]}>
|
|
113
|
+
<Component {...params} onRequestClose={onDismiss} />
|
|
114
|
+
</Animated.View>
|
|
115
|
+
</KeyboardAvoidingView>
|
|
116
|
+
</Container>
|
|
100
117
|
);
|
|
101
118
|
};
|
|
102
119
|
|
|
@@ -55,9 +55,6 @@ class Navigation {
|
|
|
55
55
|
* @param params
|
|
56
56
|
*/
|
|
57
57
|
setOptions = (params: NavigationOptions) => {
|
|
58
|
-
console.log(
|
|
59
|
-
'performance issue!!!, please change to use ref.current.setOptions()'
|
|
60
|
-
);
|
|
61
58
|
const options = getOptions(this.filterParams(params));
|
|
62
59
|
this.instance.setOptions(options as StackNavigationOptions);
|
|
63
60
|
};
|
package/Application/Navigator.ts
CHANGED
|
@@ -4,12 +4,14 @@ import {BottomSheetParams, ModalParams, ScreenParams} from './types';
|
|
|
4
4
|
class Navigator {
|
|
5
5
|
ref?: any;
|
|
6
6
|
isReady?: any;
|
|
7
|
+
isWidget?: any;
|
|
7
8
|
maxApi?: any;
|
|
8
9
|
dismissData?: any;
|
|
9
10
|
|
|
10
|
-
constructor(navigation: any, isReady: any) {
|
|
11
|
+
constructor(navigation: any, isReady: any, isWidget = false) {
|
|
11
12
|
this.ref = navigation;
|
|
12
13
|
this.isReady = isReady;
|
|
14
|
+
this.isWidget = isWidget;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -60,7 +62,12 @@ class Navigator {
|
|
|
60
62
|
showModal = (params: ModalParams, onError?: (error: string) => void) => {
|
|
61
63
|
try {
|
|
62
64
|
if (this.isReady.current) {
|
|
63
|
-
this.ref.current?.dispatch?.(
|
|
65
|
+
this.ref.current?.dispatch?.(
|
|
66
|
+
StackActions.push('Modal', {
|
|
67
|
+
...params,
|
|
68
|
+
useNativeModal: this.isWidget ? true : params?.useNativeModal,
|
|
69
|
+
})
|
|
70
|
+
);
|
|
64
71
|
} else {
|
|
65
72
|
onError?.('NavigationContainer not ready');
|
|
66
73
|
}
|
|
@@ -83,6 +90,7 @@ class Navigator {
|
|
|
83
90
|
this.ref.current?.dispatch?.(
|
|
84
91
|
StackActions.push('Modal', {
|
|
85
92
|
...params,
|
|
93
|
+
useNativeModal: this.isWidget ? true : params?.useNativeModal,
|
|
86
94
|
isBottomSheet: true,
|
|
87
95
|
})
|
|
88
96
|
);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React, {useContext, useRef, useState} from 'react';
|
|
2
|
+
import {SafeAreaProvider} from 'react-native-safe-area-context';
|
|
3
|
+
import Navigator from './Navigator';
|
|
4
|
+
import {WidgetContainerProps} from './types';
|
|
5
|
+
import {ApplicationContext, MiniAppContext} from './index';
|
|
6
|
+
import Localize from './Localize';
|
|
7
|
+
import {defaultTheme} from '../Consts';
|
|
8
|
+
import {
|
|
9
|
+
NavigationContainer as ReactNavigationContainer,
|
|
10
|
+
NavigationContainerRef,
|
|
11
|
+
} from '@react-navigation/native';
|
|
12
|
+
import {getModalOptions} from './utils';
|
|
13
|
+
import {createStackNavigator} from '@react-navigation/stack';
|
|
14
|
+
import ModalScreen from './ModalScreen';
|
|
15
|
+
import {View} from 'react-native';
|
|
16
|
+
|
|
17
|
+
const Stack = createStackNavigator();
|
|
18
|
+
|
|
19
|
+
const WidgetContent: React.FC = ({route}: any) => {
|
|
20
|
+
const Component = route?.params?.screen;
|
|
21
|
+
return (
|
|
22
|
+
<View
|
|
23
|
+
onLayout={e => {
|
|
24
|
+
route?.params?.setHeight?.(e.nativeEvent.layout.height);
|
|
25
|
+
}}>
|
|
26
|
+
<Component />
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
32
|
+
widget,
|
|
33
|
+
theme = defaultTheme,
|
|
34
|
+
maxApi,
|
|
35
|
+
localize = new Localize({vi: {}, en: {}}),
|
|
36
|
+
}) => {
|
|
37
|
+
const [height, setHeight] = useState<any>(undefined);
|
|
38
|
+
const context = useContext<any>(MiniAppContext);
|
|
39
|
+
const navigationRef = useRef<NavigationContainerRef>(null);
|
|
40
|
+
const isReady = useRef(false);
|
|
41
|
+
const navigator = useRef(new Navigator(navigationRef, isReady, true));
|
|
42
|
+
const [currentContext, setCurrentContext] = useState({});
|
|
43
|
+
|
|
44
|
+
let headerBackground = context?.designConfig?.headerBar;
|
|
45
|
+
let headerGradient = theme.colors?.gradient;
|
|
46
|
+
|
|
47
|
+
if (theme.assets?.headerBackground) {
|
|
48
|
+
headerBackground = theme.assets?.headerBackground;
|
|
49
|
+
}
|
|
50
|
+
if (context?.designConfig?.headerGradient) {
|
|
51
|
+
headerGradient = context?.designConfig?.headerGradient;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* inject data for navigator
|
|
56
|
+
*/
|
|
57
|
+
navigator.current.maxApi = maxApi;
|
|
58
|
+
|
|
59
|
+
const translate = (data?: string | {vi: string; en: string}) => {
|
|
60
|
+
if (data && typeof data !== 'string') {
|
|
61
|
+
return localize?.translateData(data);
|
|
62
|
+
}
|
|
63
|
+
return localize?.translate(data as string);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
navigator.current.setCurrentContext = setCurrentContext;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<View style={{height: height ?? '100%'}}>
|
|
70
|
+
<SafeAreaProvider>
|
|
71
|
+
<MiniAppContext.Provider
|
|
72
|
+
value={{
|
|
73
|
+
...context,
|
|
74
|
+
...currentContext,
|
|
75
|
+
}}>
|
|
76
|
+
<ApplicationContext.Provider
|
|
77
|
+
value={{
|
|
78
|
+
navigator: navigator.current,
|
|
79
|
+
theme: {
|
|
80
|
+
...theme,
|
|
81
|
+
colors: {
|
|
82
|
+
...theme.colors,
|
|
83
|
+
gradient: headerGradient,
|
|
84
|
+
},
|
|
85
|
+
assets: {
|
|
86
|
+
...theme.assets,
|
|
87
|
+
headerBackground,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
translate,
|
|
91
|
+
}}>
|
|
92
|
+
<ReactNavigationContainer
|
|
93
|
+
theme={{
|
|
94
|
+
...theme,
|
|
95
|
+
colors: {
|
|
96
|
+
...theme.colors,
|
|
97
|
+
background: theme.colors.background.default,
|
|
98
|
+
card: theme.colors.background.surface,
|
|
99
|
+
text: theme.colors.text.default,
|
|
100
|
+
border: theme.colors.border.default,
|
|
101
|
+
notification: theme.colors.error.primary,
|
|
102
|
+
},
|
|
103
|
+
}}
|
|
104
|
+
ref={navigationRef}
|
|
105
|
+
onReady={() => {
|
|
106
|
+
isReady.current = true;
|
|
107
|
+
}}
|
|
108
|
+
independent={true}>
|
|
109
|
+
<Stack.Navigator initialRouteName="Stack" headerMode="screen">
|
|
110
|
+
<Stack.Screen
|
|
111
|
+
name="Stack"
|
|
112
|
+
component={WidgetContent}
|
|
113
|
+
initialParams={{screen: widget, setHeight}}
|
|
114
|
+
options={{
|
|
115
|
+
headerShown: false,
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
<Stack.Screen
|
|
119
|
+
name="Modal"
|
|
120
|
+
component={ModalScreen}
|
|
121
|
+
options={getModalOptions()}
|
|
122
|
+
initialParams={{screen: widget}}
|
|
123
|
+
/>
|
|
124
|
+
</Stack.Navigator>
|
|
125
|
+
</ReactNavigationContainer>
|
|
126
|
+
</ApplicationContext.Provider>
|
|
127
|
+
</MiniAppContext.Provider>
|
|
128
|
+
</SafeAreaProvider>
|
|
129
|
+
</View>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export {WidgetContainer};
|
package/Application/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {Platform} from 'react-native';
|
|
2
2
|
import {createContext} from 'react';
|
|
3
3
|
import {NavigationContainer} from './NavigationContainer';
|
|
4
|
+
import {WidgetContainer} from './WidgetContainer';
|
|
4
5
|
import Localize from './Localize';
|
|
5
6
|
import Screen from '../Layout/Screen';
|
|
6
7
|
import BottomTab from './BottomTab';
|
|
@@ -28,6 +29,7 @@ export {
|
|
|
28
29
|
ComponentContext,
|
|
29
30
|
SkeletonContext,
|
|
30
31
|
NavigationContainer,
|
|
32
|
+
WidgetContainer,
|
|
31
33
|
Localize,
|
|
32
34
|
HeaderTitle,
|
|
33
35
|
HeaderBackground,
|
package/Application/types.ts
CHANGED
|
@@ -13,8 +13,6 @@ import Navigation from './Navigation';
|
|
|
13
13
|
import Navigator from './Navigator';
|
|
14
14
|
import {InputRef, InputSearchProps} from '../Input';
|
|
15
15
|
|
|
16
|
-
type Screen = React.ComponentType<NavigationScreenProps>;
|
|
17
|
-
|
|
18
16
|
export type Theme = {
|
|
19
17
|
dark: boolean;
|
|
20
18
|
colors: {
|
|
@@ -103,7 +101,7 @@ export type Tool = {
|
|
|
103
101
|
};
|
|
104
102
|
|
|
105
103
|
export type NavigationContainerProps = {
|
|
106
|
-
screen:
|
|
104
|
+
screen: React.ComponentType<NavigationScreenProps>;
|
|
107
105
|
options?: NavigationOptions;
|
|
108
106
|
theme?: Theme;
|
|
109
107
|
maxApi: any;
|
|
@@ -111,6 +109,13 @@ export type NavigationContainerProps = {
|
|
|
111
109
|
localize: Localize;
|
|
112
110
|
};
|
|
113
111
|
|
|
112
|
+
export type WidgetContainerProps = {
|
|
113
|
+
widget: React.ComponentType<any>;
|
|
114
|
+
theme?: Theme;
|
|
115
|
+
maxApi: any;
|
|
116
|
+
localize: Localize;
|
|
117
|
+
};
|
|
118
|
+
|
|
114
119
|
export type NavigationScreenProps = {
|
|
115
120
|
[key: string]: any;
|
|
116
121
|
options?: NavigationOptions;
|
|
@@ -119,7 +124,7 @@ export type NavigationScreenProps = {
|
|
|
119
124
|
|
|
120
125
|
export type ScreenParams = {
|
|
121
126
|
[key: string]: any;
|
|
122
|
-
screen:
|
|
127
|
+
screen: React.ComponentType<NavigationScreenProps>;
|
|
123
128
|
options?: NavigationOptions;
|
|
124
129
|
};
|
|
125
130
|
|
|
@@ -134,6 +139,7 @@ export type ModalParams = {
|
|
|
134
139
|
onDismiss?: () => void;
|
|
135
140
|
barrierDismissible?: boolean;
|
|
136
141
|
modalStyle?: ViewStyle;
|
|
142
|
+
useNativeModal?: boolean;
|
|
137
143
|
};
|
|
138
144
|
|
|
139
145
|
export type BottomSheetParams = {
|
|
@@ -233,12 +239,6 @@ export type TitleJourneyProps = {
|
|
|
233
239
|
isLoading?: boolean;
|
|
234
240
|
};
|
|
235
241
|
|
|
236
|
-
export type HeaderToolkitProps = {
|
|
237
|
-
[key: string]: any;
|
|
238
|
-
appCode: string;
|
|
239
|
-
configs: any[];
|
|
240
|
-
};
|
|
241
|
-
|
|
242
242
|
export interface HeaderAnimatedProps extends ViewProps {
|
|
243
243
|
animatedValue: Animated.Value;
|
|
244
244
|
image: string;
|
|
@@ -251,7 +251,7 @@ export type BottomTabItemProps = {
|
|
|
251
251
|
icon: string;
|
|
252
252
|
showDot?: boolean;
|
|
253
253
|
badgeLabel?: string | number;
|
|
254
|
-
screen:
|
|
254
|
+
screen: React.ComponentType<NavigationScreenProps>;
|
|
255
255
|
options: NavigationOptions;
|
|
256
256
|
initialParams?: any;
|
|
257
257
|
};
|
package/Popup/PopupPromotion.tsx
CHANGED
|
@@ -11,6 +11,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
|
|
|
11
11
|
image,
|
|
12
12
|
onIconClose,
|
|
13
13
|
onRequestClose,
|
|
14
|
+
onActionClick,
|
|
14
15
|
}) => {
|
|
15
16
|
const context = useContext<any>(MiniAppContext);
|
|
16
17
|
const {theme, navigator} = useContext(ApplicationContext);
|
|
@@ -93,17 +94,19 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
|
|
|
93
94
|
|
|
94
95
|
return (
|
|
95
96
|
<View accessibilityLabel={'popup_promotion'}>
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
<TouchableOpacity onPress={() => onAction(onActionClick)}>
|
|
98
|
+
<Image
|
|
99
|
+
source={{
|
|
100
|
+
uri: image,
|
|
101
|
+
}}
|
|
102
|
+
style={[
|
|
103
|
+
styles.container,
|
|
104
|
+
{
|
|
105
|
+
width: widthDevice - Spacing.XL * 2,
|
|
106
|
+
},
|
|
107
|
+
]}
|
|
108
|
+
/>
|
|
109
|
+
</TouchableOpacity>
|
|
107
110
|
{buildCloseIcon()}
|
|
108
111
|
</View>
|
|
109
112
|
);
|
package/Popup/types.ts
CHANGED
|
@@ -70,6 +70,11 @@ export type PopupPromotionProps = {
|
|
|
70
70
|
*/
|
|
71
71
|
onIconClose?: () => void;
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* `onActionClick`: Optional. A callback function that is called when the PopupPromotion component is closed.
|
|
75
|
+
*/
|
|
76
|
+
onActionClick?: () => void;
|
|
77
|
+
|
|
73
78
|
/**
|
|
74
79
|
* onRequestClose on request close for modal
|
|
75
80
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/foundation",
|
|
3
|
-
"version": "0.112.1-rn76.
|
|
3
|
+
"version": "0.112.1-rn76.45-test1",
|
|
4
4
|
"description": "React Native Component Kits",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {},
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@momo-kits/foundation"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@momo-kits/fast-image": "0.112.1-rn76.
|
|
11
|
+
"@momo-kits/fast-image": "0.112.1-rn76.45",
|
|
12
12
|
"react-native-linear-gradient": "2.8.3",
|
|
13
13
|
"react-native-gesture-handler": "2.23.1",
|
|
14
14
|
"react-native-safe-area-context": "5.2.0",
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org/"
|
|
32
32
|
},
|
|
33
33
|
"license": "MoMo"
|
|
34
|
-
}
|
|
34
|
+
}
|