@mpxjs/webpack-plugin 2.9.69-beta.2 → 2.9.69-beta.4
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/react/processScript.js +1 -1
- package/lib/runtime/components/react/context.ts +17 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +2 -2
- package/lib/runtime/components/react/dist/locale-provider.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +9 -37
- package/lib/runtime/components/react/dist/mpx-image.jsx +13 -9
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +12 -13
- package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +23 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +124 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +40 -0
- package/lib/runtime/components/react/dist/mpx-portal.jsx +12 -0
- package/lib/runtime/components/react/dist/mpx-provider.jsx +31 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +10 -16
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +10 -5
- package/lib/runtime/components/react/dist/mpx-view.jsx +15 -21
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +78 -20
- package/lib/runtime/components/react/dist/pickerFaces.js +1 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +14 -2
- package/lib/runtime/components/react/getInnerListeners.ts +2 -2
- package/lib/runtime/components/react/locale-provider.tsx +83 -0
- package/lib/runtime/components/react/mpx-button.tsx +13 -49
- package/lib/runtime/components/react/mpx-image.tsx +41 -25
- package/lib/runtime/components/react/mpx-picker/time.tsx +2 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +12 -13
- package/lib/runtime/components/react/mpx-portal/portal-consumer.tsx +32 -0
- package/lib/runtime/components/react/mpx-portal/portal-host.tsx +158 -0
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +64 -0
- package/lib/runtime/components/react/mpx-portal.tsx +29 -0
- package/lib/runtime/components/react/mpx-provider.tsx +51 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +9 -15
- package/lib/runtime/components/react/mpx-swiper.tsx +11 -5
- package/lib/runtime/components/react/mpx-view.tsx +17 -23
- package/lib/runtime/components/react/mpx-web-view.tsx +110 -21
- package/lib/runtime/components/react/pickerFaces.ts +1 -1
- package/lib/runtime/components/react/types/global.d.ts +3 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +19 -3
- package/package.json +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { forwardRef,
|
|
1
|
+
import { forwardRef, useRef, useContext, useMemo, useState, createElement, useCallback, useEffect } from 'react'
|
|
2
2
|
import { warn, getFocusedNavigation, isFunction } from '@mpxjs/utils'
|
|
3
|
-
import
|
|
3
|
+
import Portal from './mpx-portal'
|
|
4
4
|
import { getCustomEvent } from './getInnerListeners'
|
|
5
5
|
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
6
6
|
import { WebView } from 'react-native-webview'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
8
|
import { getCurrentPage, extendObject } from './utils'
|
|
9
|
-
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation, WebViewProgressEvent } from 'react-native-webview/lib/WebViewTypes'
|
|
9
|
+
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation, WebViewProgressEvent, WebViewSource } from 'react-native-webview/lib/WebViewTypes'
|
|
10
10
|
import { RouteContext } from './context'
|
|
11
|
-
import { BackHandler } from 'react-native'
|
|
11
|
+
import { BackHandler, StyleSheet, View, Text, Platform } from 'react-native'
|
|
12
12
|
|
|
13
13
|
type OnMessageCallbackEvent = {
|
|
14
14
|
detail: {
|
|
@@ -41,13 +41,60 @@ type MessageData = {
|
|
|
41
41
|
callbackId?: number
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
type LanguageCode = 'zh-CN' | 'en-US'; // 支持的语言代码
|
|
45
|
+
|
|
46
|
+
interface ErrorText {
|
|
47
|
+
text: string;
|
|
48
|
+
button: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ErrorTextMap = Record<LanguageCode, ErrorText>
|
|
52
|
+
|
|
53
|
+
const styles = StyleSheet.create({
|
|
54
|
+
loadErrorContext: {
|
|
55
|
+
display: 'flex',
|
|
56
|
+
alignItems: 'center'
|
|
57
|
+
},
|
|
58
|
+
loadErrorText: {
|
|
59
|
+
fontSize: 12,
|
|
60
|
+
color: '#666666',
|
|
61
|
+
paddingTop: '40%',
|
|
62
|
+
paddingBottom: 20,
|
|
63
|
+
paddingLeft: '10%',
|
|
64
|
+
paddingRight: '10%',
|
|
65
|
+
textAlign: 'center'
|
|
66
|
+
},
|
|
67
|
+
loadErrorButton: {
|
|
68
|
+
color: '#666666',
|
|
69
|
+
textAlign: 'center',
|
|
70
|
+
padding: 10,
|
|
71
|
+
borderColor: '#666666',
|
|
72
|
+
borderStyle: 'solid',
|
|
73
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
74
|
+
borderRadius: 10
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
44
78
|
const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element | null => {
|
|
45
79
|
const { src, bindmessage, bindload, binderror } = props
|
|
46
80
|
const mpx = global.__mpx
|
|
81
|
+
const errorText: ErrorTextMap = {
|
|
82
|
+
'zh-CN': {
|
|
83
|
+
text: '网络不可用,请检查网络设置',
|
|
84
|
+
button: '重新加载'
|
|
85
|
+
},
|
|
86
|
+
'en-US': {
|
|
87
|
+
text: 'The network is not available. Please check the network settings',
|
|
88
|
+
button: 'Reload'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const currentErrorText = errorText[(mpx.i18n.locale as LanguageCode) || 'zh-CN']
|
|
92
|
+
|
|
47
93
|
if (props.style) {
|
|
48
94
|
warn('The web-view component does not support the style prop.')
|
|
49
95
|
}
|
|
50
96
|
const pageId = useContext(RouteContext)
|
|
97
|
+
const [pageLoadErr, setPageLoadErr] = useState<boolean>(false)
|
|
51
98
|
const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
|
|
52
99
|
const webViewRef = useRef<WebView>(null)
|
|
53
100
|
const defaultWebViewStyle = {
|
|
@@ -76,6 +123,28 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
76
123
|
|
|
77
124
|
const navigation = getFocusedNavigation()
|
|
78
125
|
|
|
126
|
+
// ios 16以下版本 的hash会被转义,因此对于iOS环境下在页面load之后再注入hash部分的逻辑
|
|
127
|
+
let [baseUrl, hashParams = ''] = src.split('#')
|
|
128
|
+
if (hashParams) hashParams = '#' + hashParams
|
|
129
|
+
const source = useMemo<WebViewSource>(() => {
|
|
130
|
+
if (Platform.OS === 'ios') {
|
|
131
|
+
return { uri: baseUrl };
|
|
132
|
+
}
|
|
133
|
+
return { uri: baseUrl + hashParams };
|
|
134
|
+
}, [baseUrl, hashParams])
|
|
135
|
+
|
|
136
|
+
const hashInjectedJavascript = useMemo(() => {
|
|
137
|
+
if (Platform.OS === 'ios' && hashParams) {
|
|
138
|
+
return `(function() {
|
|
139
|
+
try {
|
|
140
|
+
location.hash = '${hashParams}';
|
|
141
|
+
} catch(e) {
|
|
142
|
+
}
|
|
143
|
+
})()`;
|
|
144
|
+
}
|
|
145
|
+
return '';
|
|
146
|
+
}, [hashParams]);
|
|
147
|
+
|
|
79
148
|
navigation?.addListener('beforeRemove', beforeRemoveHandle)
|
|
80
149
|
|
|
81
150
|
useEffect(() => {
|
|
@@ -83,6 +152,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
83
152
|
BackHandler.addEventListener('hardwareBackPress', onAndroidBackPress)
|
|
84
153
|
return () => {
|
|
85
154
|
BackHandler.removeEventListener('hardwareBackPress', onAndroidBackPress)
|
|
155
|
+
navigation?.removeListener('beforeRemove', beforeRemoveHandle)
|
|
86
156
|
}
|
|
87
157
|
}
|
|
88
158
|
}, [])
|
|
@@ -106,6 +176,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
106
176
|
bindload?.(result)
|
|
107
177
|
}
|
|
108
178
|
const _error = function (res: WebViewErrorEvent) {
|
|
179
|
+
setPageLoadErr(true)
|
|
109
180
|
const result = {
|
|
110
181
|
type: 'error',
|
|
111
182
|
timeStamp: res.timeStamp,
|
|
@@ -113,8 +184,14 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
113
184
|
src: ''
|
|
114
185
|
}
|
|
115
186
|
}
|
|
116
|
-
binderror
|
|
187
|
+
binderror && binderror(result)
|
|
117
188
|
}
|
|
189
|
+
|
|
190
|
+
const _reload = function () {
|
|
191
|
+
setPageLoadErr(false)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
118
195
|
const injectedJavaScript = `
|
|
119
196
|
if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
|
|
120
197
|
var _documentTitle = document.title;
|
|
@@ -138,6 +215,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
138
215
|
return _documentTitle
|
|
139
216
|
}
|
|
140
217
|
});
|
|
218
|
+
${hashInjectedJavascript}
|
|
141
219
|
}
|
|
142
220
|
true;
|
|
143
221
|
`
|
|
@@ -249,23 +327,34 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
249
327
|
onLoad: _load
|
|
250
328
|
})
|
|
251
329
|
}
|
|
252
|
-
if (binderror) {
|
|
253
|
-
extendObject(events, {
|
|
254
|
-
onError: _error
|
|
255
|
-
})
|
|
256
|
-
}
|
|
257
330
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
331
|
+
extendObject(events, {
|
|
332
|
+
onError: _error
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<Portal key={pageLoadErr ? 'error' : 'webview'}>
|
|
337
|
+
{pageLoadErr
|
|
338
|
+
? (
|
|
339
|
+
<View style={[styles.loadErrorContext, defaultWebViewStyle]}>
|
|
340
|
+
<View style={styles.loadErrorText}><Text style={{ fontSize: 14, color: '#999999' }}>{currentErrorText.text}</Text></View>
|
|
341
|
+
<View style={styles.loadErrorButton} onTouchEnd={_reload}><Text style={{ fontSize: 12, color: '#666666' }}>{currentErrorText.button}</Text></View>
|
|
342
|
+
</View>
|
|
343
|
+
)
|
|
344
|
+
: (<WebView
|
|
345
|
+
style={defaultWebViewStyle}
|
|
346
|
+
source={source}
|
|
347
|
+
ref={webViewRef}
|
|
348
|
+
javaScriptEnabled={true}
|
|
349
|
+
onNavigationStateChange={_changeUrl}
|
|
350
|
+
onMessage={_message}
|
|
351
|
+
injectedJavaScript={injectedJavaScript}
|
|
352
|
+
onLoadProgress={_onLoadProgress}
|
|
353
|
+
allowsBackForwardNavigationGestures={true}
|
|
354
|
+
{...events}
|
|
355
|
+
></WebView>)}
|
|
356
|
+
</Portal>
|
|
357
|
+
)
|
|
269
358
|
})
|
|
270
359
|
|
|
271
360
|
_WebView.displayName = 'MpxWebview'
|
|
@@ -23,6 +23,9 @@ declare module '@mpxjs/utils' {
|
|
|
23
23
|
},
|
|
24
24
|
setOptions: (params: Record<string, any>) => void,
|
|
25
25
|
addListener: (eventName: string, callback: (e: Event) => void) => void
|
|
26
|
+
removeListener: (eventName: string, callback: (e: Event) => void) => void
|
|
27
|
+
dispatch: (eventName: string) => void
|
|
28
|
+
pageId: number
|
|
26
29
|
} | undefined
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
WithTimingConfig,
|
|
14
14
|
AnimationCallback
|
|
15
15
|
} from 'react-native-reanimated'
|
|
16
|
+
import { error } from '@mpxjs/utils'
|
|
16
17
|
import { ExtendedViewStyle } from './types/common'
|
|
17
18
|
import type { _ViewProps } from './mpx-view'
|
|
18
19
|
|
|
@@ -166,8 +167,17 @@ const formatStyle = (style: ExtendedViewStyle): ExtendedViewStyle => {
|
|
|
166
167
|
})
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
170
|
-
const { style = {}, animation } = props
|
|
170
|
+
export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean }) {
|
|
171
|
+
const { style = {}, animation, enableAnimation } = props
|
|
172
|
+
|
|
173
|
+
const enableStyleAnimation = enableAnimation || !!animation
|
|
174
|
+
const enableAnimationRef = useRef(enableStyleAnimation)
|
|
175
|
+
if (enableAnimationRef.current !== enableStyleAnimation) {
|
|
176
|
+
error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!enableStyleAnimation) return { enableStyleAnimation }
|
|
180
|
+
|
|
171
181
|
const originalStyle = formatStyle(style)
|
|
172
182
|
// id 标识
|
|
173
183
|
const id = animation?.id || -1
|
|
@@ -336,7 +346,8 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
|
336
346
|
}, {} as { [propName: string]: string | number })
|
|
337
347
|
}
|
|
338
348
|
// ** 生成动画样式
|
|
339
|
-
|
|
349
|
+
|
|
350
|
+
const animationStyle = useAnimatedStyle(() => {
|
|
340
351
|
// console.info(`useAnimatedStyle styles=`, originalStyle)
|
|
341
352
|
return animatedStyleKeys.value.reduce((styles, key) => {
|
|
342
353
|
// console.info('getAnimationStyles', key, shareValMap[key].value)
|
|
@@ -354,4 +365,9 @@ export default function useAnimationHooks<T, P> (props: _ViewProps) {
|
|
|
354
365
|
return styles
|
|
355
366
|
}, {} as ExtendedViewStyle)
|
|
356
367
|
})
|
|
368
|
+
|
|
369
|
+
return {
|
|
370
|
+
enableStyleAnimation,
|
|
371
|
+
animationStyle
|
|
372
|
+
}
|
|
357
373
|
}
|