@mpxjs/webpack-plugin 2.9.55 → 2.9.57
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/lib/index.js +2 -0
- package/lib/json-compiler/index.js +2 -1
- package/lib/platform/json/wx/index.js +0 -1
- package/lib/runtime/base.styl +27 -0
- package/lib/runtime/components/react/dist/event.config.js +27 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +230 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +270 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +229 -0
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +6 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +203 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +294 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +353 -0
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +57 -0
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +25 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +67 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +27 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +307 -0
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +25 -0
- package/lib/runtime/components/react/dist/utils.js +80 -0
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-button.tsx +1 -2
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -1
- package/lib/runtime/components/react/{getInnerListeners.type.ts → types/getInnerListeners.ts} +2 -2
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/optionProcessor.js +27 -1
- package/lib/template-compiler/compiler.js +72 -25
- package/lib/template-compiler/index.js +2 -1
- package/lib/web/processTemplate.js +1 -1
- package/package.json +7 -4
package/lib/index.js
CHANGED
|
@@ -897,6 +897,8 @@ class MpxWebpackPlugin {
|
|
|
897
897
|
runtimeInfo: {},
|
|
898
898
|
// 记录运行时组件依赖的运行时组件当中使用的基础组件 slot,最终依据依赖关系注入到运行时组件的 json 配置当中
|
|
899
899
|
dynamicSlotDependencies: {},
|
|
900
|
+
// 模板引擎参数,用来检测模板引擎支持渲染的模板
|
|
901
|
+
dynamicTemplateRuleRunner: this.options.dynamicTemplateRuleRunner,
|
|
900
902
|
// 依据 package 注入到 mpx-custom-element-*.json 里面的组件路径
|
|
901
903
|
getPackageInjectedComponentsMap: (packageName = 'main') => {
|
|
902
904
|
const res = {}
|
|
@@ -706,7 +706,8 @@ module.exports = function (content) {
|
|
|
706
706
|
for (const root in subPackagesCfg) {
|
|
707
707
|
const subPackageCfg = subPackagesCfg[root]
|
|
708
708
|
// 分包不存在 pages,输出 subPackages 字段会报错
|
|
709
|
-
|
|
709
|
+
// tt模式下分包异步允许一个分包不存在 pages
|
|
710
|
+
if (subPackageCfg.pages.length || mode === 'tt') {
|
|
710
711
|
if (!json.subPackages) {
|
|
711
712
|
json.subPackages = []
|
|
712
713
|
}
|
package/lib/runtime/base.styl
CHANGED
|
@@ -128,3 +128,30 @@ page {
|
|
|
128
128
|
font-family "weui"
|
|
129
129
|
src url('data:application/octet-stream;base64,AAEAAAALAIAAAwAwR1NVQrD+s+0AAAE4AAAAQk9TLzJAKEx+AAABfAAAAFZjbWFw65cFHQAAAhwAAAJQZ2x5ZvCRR/EAAASUAAAKtGhlYWQLKIN9AAAA4AAAADZoaGVhCCwD+gAAALwAAAAkaG10eEJo//8AAAHUAAAASGxvY2EYqhW6AAAEbAAAACZtYXhwASEAVQAAARgAAAAgbmFtZeNcHtgAAA9IAAAB5nBvc3T6bLhLAAARMAAAAOYAAQAAA+gAAABaA+j/////A+kAAQAAAAAAAAAAAAAAAAAAABIAAQAAAAEAACkCj3dfDzz1AAsD6AAAAADUER9XAAAAANQRH1f//wAAA+kD6gAAAAgAAgAAAAAAAAABAA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AbgAgADEALgAwAHcAZQB1AGkARwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABzAHYAZwAyAHQAdABmACAAZgByAG8AbQAgAEYAbwBuAHQAZQBsAGwAbwAgAHAAcgBvAGoAZQBjAHQALgBoAHQAdABwADoALwAvAGYAbwBuAHQAZQBsAGwAbwAuAGMAbwBtAAAAAgAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAENAQ4BDwEQAREBEgETAAZjaXJjbGUIZG93bmxvYWQEaW5mbwxzYWZlX3N1Y2Nlc3MJc2FmZV93YXJuB3N1Y2Nlc3MOc3VjY2Vzcy1jaXJjbGURc3VjY2Vzcy1uby1jaXJjbGUHd2FpdGluZw53YWl0aW5nLWNpcmNsZQR3YXJuC2luZm8tY2lyY2xlBmNhbmNlbAZzZWFyY2gFY2xlYXIEYmFjawZkZWxldGUAAAAA') format('truetype')
|
|
130
130
|
}
|
|
131
|
+
|
|
132
|
+
.mpx-slide-left-enter {
|
|
133
|
+
transform: translateX(100%)
|
|
134
|
+
}
|
|
135
|
+
.mpx-slide-left-enter-active {
|
|
136
|
+
transition: transform 0.3s;
|
|
137
|
+
position: absolute;
|
|
138
|
+
top: 0;
|
|
139
|
+
right: 0;
|
|
140
|
+
left: 0;
|
|
141
|
+
bottom: 0;
|
|
142
|
+
z-index: 100;
|
|
143
|
+
}
|
|
144
|
+
.mpx-slide-left-leave-active {
|
|
145
|
+
transition: transform 0.2s
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.mpx-slide-right-leave-active {
|
|
149
|
+
position: absolute;
|
|
150
|
+
z-index: 100;
|
|
151
|
+
top: 0;
|
|
152
|
+
right: 0;
|
|
153
|
+
left: 0;
|
|
154
|
+
bottom: 0;
|
|
155
|
+
transform: translateX(100%);
|
|
156
|
+
transition: transform 0.3s
|
|
157
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const eventConfigMap = {
|
|
2
|
+
bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
3
|
+
bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
4
|
+
bindtouchstart: ['onTouchStart'],
|
|
5
|
+
bindtouchmove: ['onTouchMove'],
|
|
6
|
+
bindtouchend: ['onTouchEnd'],
|
|
7
|
+
bindtouchcancel: ['onTouchCancel'],
|
|
8
|
+
catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
9
|
+
catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
10
|
+
catchtouchstart: ['onTouchStart'],
|
|
11
|
+
catchtouchmove: ['onTouchMove'],
|
|
12
|
+
catchtouchend: ['onTouchEnd'],
|
|
13
|
+
catchtouchcancel: ['onTouchCancel'],
|
|
14
|
+
'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
15
|
+
'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
16
|
+
'capture-bindtouchstart': ['onTouchStartCapture'],
|
|
17
|
+
'capture-bindtouchmove': ['onTouchMoveCapture'],
|
|
18
|
+
'capture-bindtouchend': ['onTouchEndCapture'],
|
|
19
|
+
'capture-bindtouchcancel': ['onTouchCancelCapture'],
|
|
20
|
+
'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
21
|
+
'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
22
|
+
'capture-catchtouchstart': ['onTouchStartCapture'],
|
|
23
|
+
'capture-catchtouchmove': ['onTouchMoveCapture'],
|
|
24
|
+
'capture-catchtouchend': ['onTouchEndCapture'],
|
|
25
|
+
'capture-catchtouchcancel': ['onTouchCancelCapture']
|
|
26
|
+
};
|
|
27
|
+
export default eventConfigMap;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { omit } from './utils';
|
|
3
|
+
import eventConfigMap from './event.config';
|
|
4
|
+
const getTouchEvent = (type, event, props, config) => {
|
|
5
|
+
const nativeEvent = event.nativeEvent;
|
|
6
|
+
const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent;
|
|
7
|
+
const { id } = props;
|
|
8
|
+
const { layoutRef } = config;
|
|
9
|
+
return {
|
|
10
|
+
...event,
|
|
11
|
+
type,
|
|
12
|
+
timeStamp: timestamp,
|
|
13
|
+
target: {
|
|
14
|
+
...(event.target || {}),
|
|
15
|
+
id: id || '',
|
|
16
|
+
dataset: getDataSet(props),
|
|
17
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
18
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
19
|
+
},
|
|
20
|
+
detail: {
|
|
21
|
+
x: pageX,
|
|
22
|
+
y: pageY
|
|
23
|
+
},
|
|
24
|
+
touches: touches.map(item => {
|
|
25
|
+
return {
|
|
26
|
+
identifier: item.identifier,
|
|
27
|
+
pageX: item.pageX,
|
|
28
|
+
pageY: item.pageY,
|
|
29
|
+
clientX: item.locationX,
|
|
30
|
+
clientY: item.locationY
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
changedTouches: changedTouches.map(item => {
|
|
34
|
+
return {
|
|
35
|
+
identifier: item.identifier,
|
|
36
|
+
pageX: item.pageX,
|
|
37
|
+
pageY: item.pageY,
|
|
38
|
+
clientX: item.locationX,
|
|
39
|
+
clientY: item.locationY
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
persist: event.persist,
|
|
43
|
+
stopPropagation: event.stopPropagation,
|
|
44
|
+
preventDefault: event.preventDefault
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export const getDataSet = (props) => {
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const key in props) {
|
|
50
|
+
if (key.indexOf('data-') === 0) {
|
|
51
|
+
const newKey = key.substr(5);
|
|
52
|
+
result[newKey] = props[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, props = {}) => {
|
|
58
|
+
return {
|
|
59
|
+
...oe,
|
|
60
|
+
type,
|
|
61
|
+
detail,
|
|
62
|
+
target: {
|
|
63
|
+
...(oe.target || {}),
|
|
64
|
+
id: props.id || '',
|
|
65
|
+
dataset: getDataSet(props),
|
|
66
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
67
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const useInnerProps = (props = {}, additionalProps = {}, removeProps = [], rawConfig) => {
|
|
72
|
+
const ref = useRef({
|
|
73
|
+
startTimer: {
|
|
74
|
+
bubble: null,
|
|
75
|
+
capture: null
|
|
76
|
+
},
|
|
77
|
+
needPress: {
|
|
78
|
+
bubble: false,
|
|
79
|
+
capture: false
|
|
80
|
+
},
|
|
81
|
+
mpxPressInfo: {
|
|
82
|
+
detail: {
|
|
83
|
+
x: 0,
|
|
84
|
+
y: 0
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const propsRef = useRef({});
|
|
89
|
+
const eventConfig = {};
|
|
90
|
+
const config = rawConfig || {};
|
|
91
|
+
propsRef.current = { ...props, ...additionalProps };
|
|
92
|
+
for (const key in eventConfigMap) {
|
|
93
|
+
if (propsRef.current[key]) {
|
|
94
|
+
eventConfig[key] = eventConfigMap[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!(Object.keys(eventConfig).length) || config.disableTouch) {
|
|
98
|
+
return omit(propsRef.current, removeProps);
|
|
99
|
+
}
|
|
100
|
+
function handleEmitEvent(events, type, oe) {
|
|
101
|
+
events.forEach(event => {
|
|
102
|
+
if (propsRef.current[event]) {
|
|
103
|
+
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
|
|
104
|
+
if (match) {
|
|
105
|
+
oe.stopPropagation();
|
|
106
|
+
}
|
|
107
|
+
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function handleTouchstart(e, type) {
|
|
112
|
+
e.persist();
|
|
113
|
+
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart'];
|
|
114
|
+
const bubblePressEvent = ['catchlongpress', 'bindlongpress'];
|
|
115
|
+
const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart'];
|
|
116
|
+
const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress'];
|
|
117
|
+
ref.current.startTimer[type] = null;
|
|
118
|
+
ref.current.needPress[type] = true;
|
|
119
|
+
const nativeEvent = e.nativeEvent;
|
|
120
|
+
ref.current.mpxPressInfo.detail = {
|
|
121
|
+
x: nativeEvent.changedTouches[0].pageX,
|
|
122
|
+
y: nativeEvent.changedTouches[0].pageY
|
|
123
|
+
};
|
|
124
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
125
|
+
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
126
|
+
handleEmitEvent(currentTouchEvent, 'touchstart', e);
|
|
127
|
+
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current;
|
|
128
|
+
if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
|
|
129
|
+
ref.current.startTimer[type] = setTimeout(() => {
|
|
130
|
+
ref.current.needPress[type] = false;
|
|
131
|
+
handleEmitEvent(currentPressEvent, 'longpress', e);
|
|
132
|
+
}, 350);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function handleTouchmove(e, type) {
|
|
136
|
+
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove'];
|
|
137
|
+
const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove'];
|
|
138
|
+
const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 };
|
|
139
|
+
const nativeEvent = e.nativeEvent;
|
|
140
|
+
const currentPageX = nativeEvent.changedTouches[0].pageX;
|
|
141
|
+
const currentPageY = nativeEvent.changedTouches[0].pageY;
|
|
142
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
143
|
+
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
144
|
+
ref.current.needPress[type] = false;
|
|
145
|
+
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
146
|
+
ref.current.startTimer[type] = null;
|
|
147
|
+
}
|
|
148
|
+
handleEmitEvent(currentTouchEvent, 'touchmove', e);
|
|
149
|
+
}
|
|
150
|
+
function handleTouchend(e, type) {
|
|
151
|
+
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'];
|
|
152
|
+
const bubbleTapEvent = ['catchtap', 'bindtap'];
|
|
153
|
+
const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend'];
|
|
154
|
+
const captureTapEvent = ['capture-catchtap', 'capture-bindtap'];
|
|
155
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
156
|
+
const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent;
|
|
157
|
+
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
158
|
+
ref.current.startTimer[type] = null;
|
|
159
|
+
handleEmitEvent(currentTouchEvent, 'touchend', e);
|
|
160
|
+
if (ref.current.needPress[type]) {
|
|
161
|
+
handleEmitEvent(currentTapEvent, 'tap', e);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function handleTouchcancel(e, type) {
|
|
165
|
+
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel'];
|
|
166
|
+
const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel'];
|
|
167
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
168
|
+
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
169
|
+
ref.current.startTimer[type] = null;
|
|
170
|
+
handleEmitEvent(currentTouchEvent, 'touchcancel', e);
|
|
171
|
+
}
|
|
172
|
+
const touchEventList = [{
|
|
173
|
+
eventName: 'onTouchStart',
|
|
174
|
+
handler: (e) => {
|
|
175
|
+
handleTouchstart(e, 'bubble');
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
eventName: 'onTouchMove',
|
|
179
|
+
handler: (e) => {
|
|
180
|
+
handleTouchmove(e, 'bubble');
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
eventName: 'onTouchEnd',
|
|
184
|
+
handler: (e) => {
|
|
185
|
+
handleTouchend(e, 'bubble');
|
|
186
|
+
}
|
|
187
|
+
}, {
|
|
188
|
+
eventName: 'onTouchCancel',
|
|
189
|
+
handler: (e) => {
|
|
190
|
+
handleTouchcancel(e, 'bubble');
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
eventName: 'onTouchStartCapture',
|
|
194
|
+
handler: (e) => {
|
|
195
|
+
handleTouchstart(e, 'capture');
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
eventName: 'onTouchMoveCapture',
|
|
199
|
+
handler: (e) => {
|
|
200
|
+
handleTouchmove(e, 'capture');
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
eventName: 'onTouchEndCapture',
|
|
204
|
+
handler: (e) => {
|
|
205
|
+
handleTouchend(e, 'capture');
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
eventName: 'onTouchCancelCapture',
|
|
209
|
+
handler: (e) => {
|
|
210
|
+
handleTouchcancel(e, 'capture');
|
|
211
|
+
}
|
|
212
|
+
}];
|
|
213
|
+
const events = {};
|
|
214
|
+
const transformedEventKeys = [];
|
|
215
|
+
for (const key in eventConfig) {
|
|
216
|
+
transformedEventKeys.push(...eventConfig[key]);
|
|
217
|
+
}
|
|
218
|
+
const finalEventKeys = [...new Set(transformedEventKeys)];
|
|
219
|
+
touchEventList.forEach(item => {
|
|
220
|
+
if (finalEventKeys.includes(item.eventName)) {
|
|
221
|
+
events[item.eventName] = item.handler;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const rawEventKeys = Object.keys(eventConfig);
|
|
225
|
+
return {
|
|
226
|
+
...events,
|
|
227
|
+
...omit(propsRef.current, [...rawEventKeys, ...removeProps])
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
export default useInnerProps;
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ size
|
|
3
|
+
* ✔ type
|
|
4
|
+
* ✔ plain
|
|
5
|
+
* ✔ disabled
|
|
6
|
+
* ✔ loading
|
|
7
|
+
* ✘ form-type
|
|
8
|
+
* - open-type: Partially. Only support `share`、`getUserInfo`
|
|
9
|
+
* ✔ hover-class: Convert hoverClass to hoverStyle.
|
|
10
|
+
* ✔ hover-style
|
|
11
|
+
* ✘ hover-stop-propagation
|
|
12
|
+
* ✔ hover-start-time
|
|
13
|
+
* ✔ hover-stay-time
|
|
14
|
+
* ✘ lang
|
|
15
|
+
* ✘ session-from
|
|
16
|
+
* ✘ send-message-title
|
|
17
|
+
* ✘ send-message-path
|
|
18
|
+
* ✘ send-message-img
|
|
19
|
+
* ✘ app-parameter
|
|
20
|
+
* ✘ show-message-card
|
|
21
|
+
* ✘ phone-number-no-quota-toast
|
|
22
|
+
* ✘ bindgetuserinfo
|
|
23
|
+
* ✘ bindcontact
|
|
24
|
+
* ✘ createliveactivity
|
|
25
|
+
* ✘ bindgetphonenumber
|
|
26
|
+
* ✘ bindgetphonenumber
|
|
27
|
+
* ✘ bindgetrealtimephonenumber
|
|
28
|
+
* ✘ binderror
|
|
29
|
+
* ✘ bindopensetting
|
|
30
|
+
* ✘ bindlaunchapp
|
|
31
|
+
* ✘ bindlaunchapp
|
|
32
|
+
* ✘ bindchooseavatar
|
|
33
|
+
* ✘ bindchooseavatar
|
|
34
|
+
* ✘ bindagreeprivacyauthorization
|
|
35
|
+
* ✔ bindtap
|
|
36
|
+
*/
|
|
37
|
+
import React, { useEffect, useRef, useState, forwardRef, } from 'react';
|
|
38
|
+
import { View, Text, StyleSheet, Animated, Easing, } from 'react-native';
|
|
39
|
+
import { extractTextStyle, isText, every } from './utils';
|
|
40
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
41
|
+
import useNodesRef from './useNodesRef';
|
|
42
|
+
const LOADING_IMAGE_URI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAB8hJREFUeJztnVtsFFUch6ltUYrEAi0Qo40xChGM+oAGI0EEKl4QfDVI9AkqqQZ4IVA1RSIvJlwUWwqJUokGKMVYwHJTq4mGuA+SxpJYggJSSgMpVFOtvbh+J84mk+3smXN2znZm2fNLvoQH5uQ/v4+Z2Z3dHUaNsrGxsbGxsbGxsbGxsbGxsTGSrq6uUqiHqw7iz6Vhz5WzofwYxJP4Mey5cjIUX+4hI0F52PPlXCi9WiKkOuz5ci5WiMFcvHhxOXRCHPpgLdyis4ZJITtqagtgPfRBHH6HV3XWyNpQ/DxHRDJbddYxLKTGEZHMLK2dy8ZQ/O4UQgQzVdcxJYTSZ6aQIfggrZ3MplD6CYmQmOo6BoXEJEK+TGsnsymUXicRIlimso4JIRS+TCJDsD3QzmZDKHwqDEmEdECR3zpBhVB2EVyWyBiC+4zsdNRD4Vt8jpJ3/dYwIGSTz9Gx2cjOZkMofBx0S4SIl8JlsjWCCKHsMuiXyOiGcUZ3Ouqh8BU+R0mj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2NjY1+/gNWA2LIOT/TRAAAAABJRU5ErkJggg==';
|
|
43
|
+
const TypeColorMap = {
|
|
44
|
+
default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
|
|
45
|
+
primary: ['#1AAD19', '#179B16', '26,173,25', '#9ED99D'],
|
|
46
|
+
warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89'],
|
|
47
|
+
};
|
|
48
|
+
const OpenTypeEventsMap = new Map([
|
|
49
|
+
['share', 'onShareAppMessage'],
|
|
50
|
+
['getUserInfo', 'onUserInfo'],
|
|
51
|
+
]);
|
|
52
|
+
const styles = StyleSheet.create({
|
|
53
|
+
button: {
|
|
54
|
+
width: '100%',
|
|
55
|
+
flexDirection: 'row',
|
|
56
|
+
justifyContent: 'center',
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
height: 46,
|
|
59
|
+
borderRadius: 5,
|
|
60
|
+
backgroundColor: '#F8F8F8',
|
|
61
|
+
marginHorizontal: 'auto' // 按钮默认居中
|
|
62
|
+
},
|
|
63
|
+
buttonMini: {
|
|
64
|
+
height: 30,
|
|
65
|
+
},
|
|
66
|
+
text: {
|
|
67
|
+
fontSize: 18,
|
|
68
|
+
color: '#000000',
|
|
69
|
+
},
|
|
70
|
+
textMini: {
|
|
71
|
+
fontSize: 13,
|
|
72
|
+
},
|
|
73
|
+
loading: {
|
|
74
|
+
width: 20,
|
|
75
|
+
height: 20,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
const getOpenTypeEvent = (openType) => {
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
if (!global?.__mpx?.config?.rnConfig) {
|
|
81
|
+
console.warn('Environment not supported');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const eventName = OpenTypeEventsMap.get(openType);
|
|
85
|
+
if (!eventName) {
|
|
86
|
+
console.warn(`open-type not support ${openType}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
const event = global.__mpx.config.rnConfig?.openTypeHandler?.[eventName];
|
|
91
|
+
if (!event) {
|
|
92
|
+
console.warn(`Unregistered ${eventName} event`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
return event;
|
|
96
|
+
};
|
|
97
|
+
const Loading = ({ alone = false }) => {
|
|
98
|
+
const image = useRef(new Animated.Value(0)).current;
|
|
99
|
+
const rotate = image.interpolate({
|
|
100
|
+
inputRange: [0, 1],
|
|
101
|
+
outputRange: ['0deg', '360deg'],
|
|
102
|
+
});
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const animation = Animated.loop(Animated.timing(image, {
|
|
105
|
+
toValue: 1,
|
|
106
|
+
duration: 1000,
|
|
107
|
+
easing: Easing.linear,
|
|
108
|
+
useNativeDriver: true,
|
|
109
|
+
isInteraction: false,
|
|
110
|
+
}));
|
|
111
|
+
animation.start();
|
|
112
|
+
return () => {
|
|
113
|
+
animation.stop();
|
|
114
|
+
};
|
|
115
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
|
+
}, []);
|
|
117
|
+
const loadingStyle = {
|
|
118
|
+
...styles.loading,
|
|
119
|
+
transform: [{ rotate }],
|
|
120
|
+
marginRight: alone ? 0 : 5,
|
|
121
|
+
};
|
|
122
|
+
return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }}/>;
|
|
123
|
+
};
|
|
124
|
+
const Button = forwardRef((props, ref) => {
|
|
125
|
+
const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = [], 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'enable-offset': enableOffset, style = [], children, bindgetuserinfo, bindtap, catchtap, bindtouchstart, bindtouchend, } = props;
|
|
126
|
+
const refs = useRef({
|
|
127
|
+
hoverStartTimer: undefined,
|
|
128
|
+
hoverStayTimer: undefined,
|
|
129
|
+
});
|
|
130
|
+
const layoutRef = useRef({});
|
|
131
|
+
const [isHover, setIsHover] = useState(false);
|
|
132
|
+
const isMiniSize = size === 'mini';
|
|
133
|
+
const applyHoverEffect = isHover && hoverClass !== 'none';
|
|
134
|
+
const inheritTextStyle = extractTextStyle(style);
|
|
135
|
+
const textHoverStyle = extractTextStyle(hoverStyle);
|
|
136
|
+
const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type];
|
|
137
|
+
const normalBackgroundColor = disabled ? disabledColor : applyHoverEffect || loading ? hoverColor : color;
|
|
138
|
+
const plainBorderColor = disabled
|
|
139
|
+
? 'rgba(0, 0, 0, .2)'
|
|
140
|
+
: applyHoverEffect
|
|
141
|
+
? `rgba(${plainColor},.6)`
|
|
142
|
+
: `rgb(${plainColor})`;
|
|
143
|
+
const normalBorderColor = type === 'default' ? 'rgba(0, 0, 0, .2)' : normalBackgroundColor;
|
|
144
|
+
const plainTextColor = disabled
|
|
145
|
+
? 'rgba(0, 0, 0, .2)'
|
|
146
|
+
: applyHoverEffect
|
|
147
|
+
? `rgba(${plainColor}, .6)`
|
|
148
|
+
: `rgb(${plainColor})`;
|
|
149
|
+
const normalTextColor = type === 'default'
|
|
150
|
+
? `rgba(0, 0, 0, ${disabled ? 0.3 : applyHoverEffect || loading ? 0.6 : 1})`
|
|
151
|
+
: `rgba(255 ,255 ,255 , ${disabled || applyHoverEffect || loading ? 0.6 : 1})`;
|
|
152
|
+
const viewStyle = {
|
|
153
|
+
borderWidth: 1,
|
|
154
|
+
borderStyle: 'solid',
|
|
155
|
+
borderColor: plain ? plainBorderColor : normalBorderColor,
|
|
156
|
+
backgroundColor: plain ? 'transparent' : normalBackgroundColor,
|
|
157
|
+
};
|
|
158
|
+
const textStyle = {
|
|
159
|
+
color: plain ? plainTextColor : normalTextColor,
|
|
160
|
+
...inheritTextStyle
|
|
161
|
+
};
|
|
162
|
+
const defaultViewStyle = [
|
|
163
|
+
styles.button,
|
|
164
|
+
isMiniSize && styles.buttonMini || {},
|
|
165
|
+
viewStyle,
|
|
166
|
+
];
|
|
167
|
+
const defaultTextStyle = [
|
|
168
|
+
styles.text, isMiniSize && styles.textMini, textStyle
|
|
169
|
+
];
|
|
170
|
+
const handleOpenTypeEvent = (evt) => {
|
|
171
|
+
if (!openType)
|
|
172
|
+
return;
|
|
173
|
+
const handleEvent = getOpenTypeEvent(openType);
|
|
174
|
+
if (openType === 'share') {
|
|
175
|
+
handleEvent && handleEvent({
|
|
176
|
+
from: 'button',
|
|
177
|
+
target: getCustomEvent('tap', evt, { layoutRef }, props).target,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (openType === 'getUserInfo') {
|
|
181
|
+
const userInfo = handleEvent && handleEvent();
|
|
182
|
+
if (typeof userInfo === 'object') {
|
|
183
|
+
bindgetuserinfo && bindgetuserinfo(userInfo);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const setStayTimer = () => {
|
|
188
|
+
clearTimeout(refs.current.hoverStayTimer);
|
|
189
|
+
refs.current.hoverStayTimer = setTimeout(() => {
|
|
190
|
+
setIsHover(false);
|
|
191
|
+
clearTimeout(refs.current.hoverStayTimer);
|
|
192
|
+
}, hoverStayTime);
|
|
193
|
+
};
|
|
194
|
+
const setStartTimer = () => {
|
|
195
|
+
clearTimeout(refs.current.hoverStartTimer);
|
|
196
|
+
refs.current.hoverStartTimer = setTimeout(() => {
|
|
197
|
+
setIsHover(true);
|
|
198
|
+
clearTimeout(refs.current.hoverStartTimer);
|
|
199
|
+
}, hoverStartTime);
|
|
200
|
+
};
|
|
201
|
+
const onTouchStart = (evt) => {
|
|
202
|
+
bindtouchstart && bindtouchstart(evt);
|
|
203
|
+
if (disabled)
|
|
204
|
+
return;
|
|
205
|
+
setStartTimer();
|
|
206
|
+
};
|
|
207
|
+
const onTouchEnd = (evt) => {
|
|
208
|
+
bindtouchend && bindtouchend(evt);
|
|
209
|
+
if (disabled)
|
|
210
|
+
return;
|
|
211
|
+
setStayTimer();
|
|
212
|
+
};
|
|
213
|
+
const onTap = (evt) => {
|
|
214
|
+
if (disabled)
|
|
215
|
+
return;
|
|
216
|
+
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
217
|
+
handleOpenTypeEvent(evt);
|
|
218
|
+
};
|
|
219
|
+
const catchTap = (evt) => {
|
|
220
|
+
if (disabled)
|
|
221
|
+
return;
|
|
222
|
+
catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
|
|
223
|
+
};
|
|
224
|
+
function wrapChildren(children, textStyle) {
|
|
225
|
+
if (every(children, (child) => isText(child))) {
|
|
226
|
+
children = [<Text key='buttonTextWrap' style={textStyle}>{children}</Text>];
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if (textStyle)
|
|
230
|
+
console.warn('Text style will be ignored unless every child of the Button is Text node!');
|
|
231
|
+
}
|
|
232
|
+
return children;
|
|
233
|
+
}
|
|
234
|
+
const { nodeRef } = useNodesRef(props, ref, {
|
|
235
|
+
defaultStyle: StyleSheet.flatten([
|
|
236
|
+
...defaultViewStyle,
|
|
237
|
+
...defaultTextStyle,
|
|
238
|
+
])
|
|
239
|
+
});
|
|
240
|
+
const onLayout = () => {
|
|
241
|
+
nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
|
|
242
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
const innerProps = useInnerProps(props, {
|
|
246
|
+
ref: nodeRef,
|
|
247
|
+
bindtouchstart: onTouchStart,
|
|
248
|
+
bindtouchend: onTouchEnd,
|
|
249
|
+
bindtap: onTap,
|
|
250
|
+
catchtap: catchTap,
|
|
251
|
+
...(enableOffset ? { onLayout } : {}),
|
|
252
|
+
}, [
|
|
253
|
+
'enable-offset'
|
|
254
|
+
], {
|
|
255
|
+
layoutRef
|
|
256
|
+
});
|
|
257
|
+
return (<View {...innerProps} style={[
|
|
258
|
+
...defaultViewStyle,
|
|
259
|
+
style,
|
|
260
|
+
applyHoverEffect && hoverStyle,
|
|
261
|
+
]}>
|
|
262
|
+
{loading && <Loading alone={!children}/>}
|
|
263
|
+
{wrapChildren(children, [
|
|
264
|
+
...defaultTextStyle,
|
|
265
|
+
applyHoverEffect && textHoverStyle,
|
|
266
|
+
])}
|
|
267
|
+
</View>);
|
|
268
|
+
});
|
|
269
|
+
Button.displayName = 'mpx-button';
|
|
270
|
+
export default Button;
|