@momo-kits/suggest-action 0.73.3-beta.5 → 0.74.2-react-native.1
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/SuggestActionView.tsx +124 -0
- package/index.tsx +5 -0
- package/package.json +11 -10
- package/publish.sh +1 -1
- package/styles.ts +30 -0
- package/types.ts +36 -0
- package/ExpenseI18n.js +0 -35
- package/index.js +0 -144
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
ForwardRefRenderFunction,
|
|
4
|
+
useContext,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import {Animated, Easing, TouchableOpacity} from 'react-native';
|
|
9
|
+
import {SuggestActionProps, SuggestActionRef} from './types';
|
|
10
|
+
import {
|
|
11
|
+
ApplicationContext,
|
|
12
|
+
Button,
|
|
13
|
+
Icon,
|
|
14
|
+
Image,
|
|
15
|
+
Shadow,
|
|
16
|
+
Text,
|
|
17
|
+
} from '@momo-kits/foundation';
|
|
18
|
+
import styles from './styles';
|
|
19
|
+
|
|
20
|
+
const DURATION = 200;
|
|
21
|
+
|
|
22
|
+
const SuggestAction: ForwardRefRenderFunction<
|
|
23
|
+
SuggestActionRef,
|
|
24
|
+
SuggestActionProps
|
|
25
|
+
> = (
|
|
26
|
+
{
|
|
27
|
+
image,
|
|
28
|
+
onPressButton = () => {},
|
|
29
|
+
onClose,
|
|
30
|
+
bottom = 72,
|
|
31
|
+
message = 'Message',
|
|
32
|
+
buttonTitle = 'Button',
|
|
33
|
+
boldMessage,
|
|
34
|
+
},
|
|
35
|
+
ref,
|
|
36
|
+
) => {
|
|
37
|
+
const {theme} = useContext(ApplicationContext);
|
|
38
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
39
|
+
|
|
40
|
+
useImperativeHandle(ref, () => ({show}));
|
|
41
|
+
const show = () => {
|
|
42
|
+
Animated.timing(opacity, {
|
|
43
|
+
toValue: 1,
|
|
44
|
+
duration: DURATION,
|
|
45
|
+
useNativeDriver: false,
|
|
46
|
+
easing: Easing.linear,
|
|
47
|
+
}).start();
|
|
48
|
+
};
|
|
49
|
+
const hide = () => {
|
|
50
|
+
Animated.timing(opacity, {
|
|
51
|
+
toValue: 0,
|
|
52
|
+
duration: DURATION,
|
|
53
|
+
easing: Easing.linear,
|
|
54
|
+
useNativeDriver: false,
|
|
55
|
+
}).start();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleClose = () => {
|
|
59
|
+
onClose?.();
|
|
60
|
+
hide();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleButtonPress = () => {
|
|
64
|
+
onPressButton?.();
|
|
65
|
+
hide();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const renderMessage = () => {
|
|
69
|
+
if (!!boldMessage) {
|
|
70
|
+
let splitMessage = [];
|
|
71
|
+
let index = message.toLowerCase().indexOf(boldMessage.toLowerCase());
|
|
72
|
+
if (index !== -1) {
|
|
73
|
+
splitMessage = [
|
|
74
|
+
message.substring(0, index),
|
|
75
|
+
boldMessage,
|
|
76
|
+
message.substring(index + boldMessage.length),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Text style={styles.content} typography={'body_default_regular'}>
|
|
81
|
+
{splitMessage[0]}
|
|
82
|
+
<Text typography={'action_s_bold'}>{splitMessage[1]}</Text>
|
|
83
|
+
{splitMessage[2]}
|
|
84
|
+
</Text>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Text style={styles.content} typography={'description_default_regular'}>
|
|
91
|
+
{message}
|
|
92
|
+
</Text>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Animated.View
|
|
98
|
+
style={[
|
|
99
|
+
styles.container,
|
|
100
|
+
{
|
|
101
|
+
backgroundColor: theme.colors.background.surface,
|
|
102
|
+
opacity,
|
|
103
|
+
bottom,
|
|
104
|
+
},
|
|
105
|
+
Shadow.Light,
|
|
106
|
+
]}>
|
|
107
|
+
{!!image && <Image source={{uri: image}} style={styles.image} />}
|
|
108
|
+
{renderMessage()}
|
|
109
|
+
<Button
|
|
110
|
+
type="tonal"
|
|
111
|
+
title={buttonTitle}
|
|
112
|
+
onPress={handleButtonPress}
|
|
113
|
+
size={'small'}
|
|
114
|
+
full={false}
|
|
115
|
+
/>
|
|
116
|
+
<TouchableOpacity style={styles.closeIcon} onPress={handleClose}>
|
|
117
|
+
<Icon source={'navigation_close'} />
|
|
118
|
+
</TouchableOpacity>
|
|
119
|
+
</Animated.View>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export default forwardRef(SuggestAction);
|
|
124
|
+
export type {SuggestActionRef, SuggestActionProps};
|
package/index.tsx
ADDED
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/suggest-action",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.2-react-native.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"main": "index.
|
|
6
|
-
"dependencies": {},
|
|
5
|
+
"main": "index.tsx",
|
|
7
6
|
"peerDependencies": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"react": "
|
|
11
|
-
"
|
|
12
|
-
"@momo-kits/core-v2": ">=0.0.5-beta"
|
|
7
|
+
"@momo-kits/foundation": "latest",
|
|
8
|
+
"react": "*",
|
|
9
|
+
"react-native": "*",
|
|
10
|
+
"prop-types": "15.7.2"
|
|
13
11
|
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@momo-platform/versions": "4.1.11"
|
|
14
|
+
},
|
|
15
|
+
"license": "MoMo",
|
|
16
|
+
"dependencies": {}
|
|
16
17
|
}
|
package/publish.sh
CHANGED
|
@@ -26,4 +26,4 @@ cd ..
|
|
|
26
26
|
rm -rf dist
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/suggest-action new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/suggest-action"}'
|
package/styles.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {Dimensions, StyleSheet} from 'react-native';
|
|
2
|
+
import {Radius, Spacing} from '@momo-kits/foundation';
|
|
3
|
+
|
|
4
|
+
const screenWidth = Dimensions.get('window').width;
|
|
5
|
+
|
|
6
|
+
export default StyleSheet.create({
|
|
7
|
+
image: {
|
|
8
|
+
width: 32,
|
|
9
|
+
height: 32,
|
|
10
|
+
borderRadius: Radius.XS,
|
|
11
|
+
marginRight: Spacing.S,
|
|
12
|
+
},
|
|
13
|
+
container: {
|
|
14
|
+
flexDirection: 'row',
|
|
15
|
+
width: screenWidth - Spacing.M * 2,
|
|
16
|
+
marginHorizontal: Spacing.M,
|
|
17
|
+
padding: Spacing.M,
|
|
18
|
+
borderRadius: Radius.S,
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
zIndex: 10,
|
|
22
|
+
},
|
|
23
|
+
content: {
|
|
24
|
+
flex: 1,
|
|
25
|
+
marginRight: Spacing.M,
|
|
26
|
+
},
|
|
27
|
+
closeIcon: {
|
|
28
|
+
marginLeft: Spacing.S,
|
|
29
|
+
},
|
|
30
|
+
});
|
package/types.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type SuggestActionProps = {
|
|
2
|
+
/**
|
|
3
|
+
* Optional. A callback function that is triggered when the action suggestion is closed.
|
|
4
|
+
*/
|
|
5
|
+
onClose?: () => void;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Optional. A callback function that is triggered when the action button is pressed.
|
|
9
|
+
*/
|
|
10
|
+
onPressButton?: () => void;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The image associated with the action, typically displayed as part of the suggestion.
|
|
14
|
+
*/
|
|
15
|
+
image?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional. Specifies the bottom margin for the component. Useful for positioning or spacing within a layout.
|
|
19
|
+
*/
|
|
20
|
+
bottom?: number;
|
|
21
|
+
|
|
22
|
+
message: string;
|
|
23
|
+
buttonTitle: string;
|
|
24
|
+
boldMessage?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A reference type for the SuggestAction component.
|
|
29
|
+
* Allows external control over the visibility of the SuggestAction component.
|
|
30
|
+
*/
|
|
31
|
+
export type SuggestActionRef = {
|
|
32
|
+
/**
|
|
33
|
+
* A method to show the SuggestAction component. Can be called to display the component when needed.
|
|
34
|
+
*/
|
|
35
|
+
show: () => void;
|
|
36
|
+
};
|
package/ExpenseI18n.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { LocalizedStrings } from '@momo-kits/core';
|
|
2
|
-
|
|
3
|
-
let ExpenseI18n = new LocalizedStrings({
|
|
4
|
-
vi: {
|
|
5
|
-
add: 'Thêm',
|
|
6
|
-
move: 'Đưa',
|
|
7
|
-
share: 'Chia sẻ',
|
|
8
|
-
favorite: 'vào Dịch vụ yêu thích',
|
|
9
|
-
homescreen: 'ra ngoài màn hình thiết bị',
|
|
10
|
-
friend: 'với người khác ngay',
|
|
11
|
-
},
|
|
12
|
-
en: {
|
|
13
|
-
add: 'Add',
|
|
14
|
-
move: 'Add',
|
|
15
|
-
share: 'Share',
|
|
16
|
-
favorite: 'to your Favorite Service',
|
|
17
|
-
homescreen: 'to your home screen',
|
|
18
|
-
friend: 'with your friends',
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
ExpenseI18n.get = (key, defaultValue = '') => {
|
|
23
|
-
let value;
|
|
24
|
-
value = LocalizedStrings.getLocalize(key);
|
|
25
|
-
console.log(value);
|
|
26
|
-
if (!value || value.length <= 0) {
|
|
27
|
-
value = defaultValue;
|
|
28
|
-
}
|
|
29
|
-
if (!value || typeof value !== 'string') {
|
|
30
|
-
value = '';
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default ExpenseI18n;
|
package/index.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Button,
|
|
3
|
-
Colors,
|
|
4
|
-
Icon,
|
|
5
|
-
IconSource,
|
|
6
|
-
Image,
|
|
7
|
-
ScaleSize,
|
|
8
|
-
Shadow,
|
|
9
|
-
Spacing,
|
|
10
|
-
Text,
|
|
11
|
-
TouchableOpacity,
|
|
12
|
-
} from '@momo-kits/core-v2';
|
|
13
|
-
import React, {forwardRef, useEffect, useImperativeHandle, useRef} from 'react';
|
|
14
|
-
import {Animated, StyleSheet, View} from 'react-native';
|
|
15
|
-
import ExpenseI18n from './ExpenseI18n';
|
|
16
|
-
|
|
17
|
-
export default SuggestAction = forwardRef((props, ref) => {
|
|
18
|
-
const {
|
|
19
|
-
icon,
|
|
20
|
-
name,
|
|
21
|
-
buttonTitle = 'Thêm ngay',
|
|
22
|
-
onPressButton,
|
|
23
|
-
onPressClose,
|
|
24
|
-
iconTintColor,
|
|
25
|
-
style,
|
|
26
|
-
contentType = 'add',
|
|
27
|
-
} = props;
|
|
28
|
-
|
|
29
|
-
const getContent = contentType => {
|
|
30
|
-
switch (contentType) {
|
|
31
|
-
case 'add':
|
|
32
|
-
return {
|
|
33
|
-
start: ExpenseI18n.get('add'),
|
|
34
|
-
end: ExpenseI18n.get('favorite'),
|
|
35
|
-
};
|
|
36
|
-
case 'move':
|
|
37
|
-
return {
|
|
38
|
-
start: ExpenseI18n.get('move'),
|
|
39
|
-
end: ExpenseI18n.get('homescreen'),
|
|
40
|
-
};
|
|
41
|
-
case 'share':
|
|
42
|
-
return {
|
|
43
|
-
start: ExpenseI18n.get('share'),
|
|
44
|
-
end: ExpenseI18n.get('friend'),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const fadeAnimation = useRef(new Animated.Value(0)).current;
|
|
49
|
-
|
|
50
|
-
const contentStart = getContent(contentType).start;
|
|
51
|
-
const contentEnd = getContent(contentType).end;
|
|
52
|
-
|
|
53
|
-
const show = () => {
|
|
54
|
-
Animated.timing(fadeAnimation, {
|
|
55
|
-
toValue: 1,
|
|
56
|
-
duration: 100,
|
|
57
|
-
useNativeDriver: true,
|
|
58
|
-
}).start();
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const hide = () => {
|
|
62
|
-
Animated.timing(fadeAnimation, {
|
|
63
|
-
toValue: 0,
|
|
64
|
-
useNativeDriver: true,
|
|
65
|
-
duration: 100,
|
|
66
|
-
}).start();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
useImperativeHandle(
|
|
70
|
-
ref,
|
|
71
|
-
() => ({
|
|
72
|
-
show,
|
|
73
|
-
hide,
|
|
74
|
-
}),
|
|
75
|
-
[],
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<Animated.View
|
|
80
|
-
style={[styles.container, style, Shadow.Light, {opacity: fadeAnimation}]}>
|
|
81
|
-
{icon && (
|
|
82
|
-
<Image source={icon} style={styles.icon} tintColor={iconTintColor} />
|
|
83
|
-
)}
|
|
84
|
-
<Text style={styles.description} numberOfLines={2}>
|
|
85
|
-
{contentStart}{' '}
|
|
86
|
-
<Text style={[styles.description, {fontWeight: 'bold'}]}>{name}</Text>{' '}
|
|
87
|
-
{contentEnd}
|
|
88
|
-
</Text>
|
|
89
|
-
<Button
|
|
90
|
-
title={buttonTitle}
|
|
91
|
-
type="tonal"
|
|
92
|
-
style={styles.button}
|
|
93
|
-
size="small"
|
|
94
|
-
onPress={onPressButton}
|
|
95
|
-
/>
|
|
96
|
-
<TouchableOpacity onPress={onPressClose}>
|
|
97
|
-
<Image
|
|
98
|
-
source={IconSource.ic_close_x_24}
|
|
99
|
-
tintColor={Colors.black_10}
|
|
100
|
-
style={styles.iconClose}
|
|
101
|
-
/>
|
|
102
|
-
</TouchableOpacity>
|
|
103
|
-
</Animated.View>
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const styles = StyleSheet.create({
|
|
108
|
-
container: {
|
|
109
|
-
minHeight: 60,
|
|
110
|
-
margin: Spacing.M,
|
|
111
|
-
paddingHorizontal: Spacing.M,
|
|
112
|
-
paddingVertical: ScaleSize(14),
|
|
113
|
-
borderRadius: Spacing.S,
|
|
114
|
-
backgroundColor: Colors.white,
|
|
115
|
-
|
|
116
|
-
flexDirection: 'row',
|
|
117
|
-
alignItems: 'center',
|
|
118
|
-
position: 'absolute',
|
|
119
|
-
zIndex: 99,
|
|
120
|
-
},
|
|
121
|
-
button: {
|
|
122
|
-
height: ScaleSize(28),
|
|
123
|
-
// paddingVertical: ScaleSize(6),
|
|
124
|
-
// paddingHorizontal: Spacing.S,
|
|
125
|
-
},
|
|
126
|
-
icon: {
|
|
127
|
-
width: 36,
|
|
128
|
-
height: 36,
|
|
129
|
-
marginRight: Spacing.S,
|
|
130
|
-
marginLeft: Spacing.XS,
|
|
131
|
-
},
|
|
132
|
-
iconClose: {
|
|
133
|
-
width: ScaleSize(24),
|
|
134
|
-
height: ScaleSize(24),
|
|
135
|
-
marginLeft: Spacing.S,
|
|
136
|
-
},
|
|
137
|
-
description: {
|
|
138
|
-
fontSize: 12,
|
|
139
|
-
lineHeight: 16,
|
|
140
|
-
paddingHorizontal: Spacing.S,
|
|
141
|
-
color: '#475160',
|
|
142
|
-
fontWeight: '500',
|
|
143
|
-
},
|
|
144
|
-
});
|