@mpxjs/webpack-plugin 2.9.69-beta.7 → 2.9.69-beta.8

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.
@@ -14,25 +14,27 @@ module.exports = function (script, {
14
14
  localPagesMap
15
15
  }, callback) {
16
16
  let scriptSrcMode = srcMode
17
+ const mode = loaderContext.getMpx().mode
17
18
  if (script) {
18
19
  scriptSrcMode = script.mode || scriptSrcMode
19
20
  } else {
20
21
  script = { tag: 'script' }
21
22
  }
22
-
23
23
  let output = '/* script */\n'
24
24
  if (ctorType === 'app') {
25
25
  output += `
26
26
  import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
27
27
  import { NavigationContainer, StackActions } from '@react-navigation/native'
28
- import { createStackNavigator } from '@react-navigation/stack'
28
+ ${mode === 'ios' ? "import { createNativeStackNavigator } from '@react-navigation/native-stack'" : "import { createStackNavigator } from '@react-navigation/stack'" }
29
+ import { useHeaderHeight } from '@react-navigation/elements';
29
30
  import Provider from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-provider'
30
31
  import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
31
32
  import { GestureHandlerRootView } from 'react-native-gesture-handler'
32
33
 
33
34
  global.__navigationHelper = {
34
35
  NavigationContainer: NavigationContainer,
35
- createStackNavigator: createStackNavigator,
36
+ createStackNavigator: ${mode === 'ios' ? 'createNativeStackNavigator' : 'createStackNavigator'},
37
+ useHeaderHeight: useHeaderHeight,
36
38
  StackActions: StackActions,
37
39
  GestureHandlerRootView: GestureHandlerRootView,
38
40
  Provider: Provider,
@@ -1,4 +1,4 @@
1
- import { AppState, View } from 'react-native';
1
+ import { View } from 'react-native';
2
2
  import { GestureDetector, Gesture } from 'react-native-gesture-handler';
3
3
  import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, useAnimatedReaction, cancelAnimation } from 'react-native-reanimated';
4
4
  import React, { forwardRef, useRef, useEffect, useMemo } from 'react';
@@ -63,7 +63,7 @@ const activeDotStyle = {
63
63
  };
64
64
  const longPressRatio = 100;
65
65
  const easeMap = {
66
- default: Easing.linear,
66
+ default: Easing.inOut(Easing.poly(3)),
67
67
  linear: Easing.linear,
68
68
  easeInCubic: Easing.in(Easing.cubic),
69
69
  easeOutCubic: Easing.out(Easing.cubic),
@@ -121,7 +121,6 @@ const SwiperWrapper = forwardRef((props, ref) => {
121
121
  const moveTime = useSharedValue(0);
122
122
  const timerId = useRef(0);
123
123
  const intervalTimer = props.interval || 500;
124
- const appState = useRef(AppState.currentState);
125
124
  const {
126
125
  // 存储layout布局信息
127
126
  layoutRef, layoutProps, layoutStyle } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef, onLayout: onWrapperLayout });
@@ -235,7 +234,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
235
234
  }
236
235
  const { loop, pauseLoop, resumeLoop } = useMemo(() => {
237
236
  function createAutoPlay() {
238
- if (!step.value || appState.current !== 'active')
237
+ if (!step.value)
239
238
  return;
240
239
  let targetOffset = 0;
241
240
  let nextIndex = currentIndex.value;
@@ -289,9 +288,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
289
288
  // loop在JS线程中调用,createAutoPlay + useEffect中
290
289
  function loop() {
291
290
  timerId.current && clearTimeout(timerId.current);
292
- if (appState.current === 'active') {
293
- timerId.current = setTimeout(createAutoPlay, intervalTimer);
294
- }
291
+ timerId.current = setTimeout(createAutoPlay, intervalTimer);
295
292
  }
296
293
  function pauseLoop() {
297
294
  timerId.current && clearTimeout(timerId.current);
@@ -359,21 +356,6 @@ const SwiperWrapper = forwardRef((props, ref) => {
359
356
  runOnJS(handleSwiperChange)(newIndex);
360
357
  }
361
358
  });
362
- // 监听切换前后台,默认切换到后台JS执行不会立即停止定时器还在
363
- useEffect(() => {
364
- const subscription = AppState.addEventListener('change', nextAppState => {
365
- appState.current = nextAppState;
366
- if (nextAppState === 'active' && autoplayShared.value && childrenLength.value > 1) {
367
- loop();
368
- }
369
- else {
370
- appState.current = nextAppState;
371
- }
372
- });
373
- return () => {
374
- subscription.remove();
375
- };
376
- }, []);
377
359
  useEffect(() => {
378
360
  let patchStep = 0;
379
361
  if (preMargin !== preMarginShared.value) {
@@ -392,18 +374,13 @@ const SwiperWrapper = forwardRef((props, ref) => {
392
374
  }, [preMargin, nextMargin]);
393
375
  useEffect(() => {
394
376
  childrenLength.value = children.length;
395
- pauseLoop();
396
377
  if (children.length - 1 < currentIndex.value) {
378
+ pauseLoop();
397
379
  currentIndex.value = 0;
398
380
  offset.value = getOffset(0, step.value);
399
- }
400
- else {
401
- // children变化-其他属性都不变化(比如从1变化到3或者从3变到1, 在circular的情况下offset是需要更新的)
402
- currentIndex.value = props.current || 0;
403
- offset.value = getOffset(props.current || 0, step.value);
404
- }
405
- if (autoplay && children.length > 1) {
406
- loop();
381
+ if (autoplay && children.length > 1) {
382
+ loop();
383
+ }
407
384
  }
408
385
  }, [children.length]);
409
386
  useEffect(() => {
@@ -54,7 +54,8 @@ const _WebView = forwardRef((props, ref) => {
54
54
  const [pageLoadErr, setPageLoadErr] = useState(false);
55
55
  const currentPage = useMemo(() => getCurrentPage(pageId), [pageId]);
56
56
  const webViewRef = useRef(null);
57
- const isLoaded = useRef(false);
57
+ const [isLoaded, setIsLoaded] = useState(true);
58
+ const fristLoaded = useRef(false);
58
59
  const defaultWebViewStyle = {
59
60
  position: 'absolute',
60
61
  left: 0,
@@ -101,6 +102,9 @@ const _WebView = forwardRef((props, ref) => {
101
102
  return null;
102
103
  }
103
104
  const _reload = function () {
105
+ if (__mpx_mode__ === 'android') {
106
+ fristLoaded.current = false; // 安卓需要重新设置
107
+ }
104
108
  setPageLoadErr(false);
105
109
  };
106
110
  const injectedJavaScript = `
@@ -131,7 +135,7 @@ const _WebView = forwardRef((props, ref) => {
131
135
  `;
132
136
  const sendMessage = function (params) {
133
137
  return `
134
- window.mpxWebviewMessageCallback(${params})
138
+ window.mpxWebviewMessageCallback && window.mpxWebviewMessageCallback(${params})
135
139
  true;
136
140
  `;
137
141
  };
@@ -232,11 +236,10 @@ const _WebView = forwardRef((props, ref) => {
232
236
  });
233
237
  };
234
238
  let isLoadError = false;
235
- let fristLoaded = false;
236
239
  let statusCode = '';
237
- const onLoadEnd = function (res) {
238
- fristLoaded = true;
239
- isLoaded.current = true;
240
+ const onLoadEndHandle = function (res) {
241
+ fristLoaded.current = true;
242
+ setIsLoaded(true);
240
243
  const src = res.nativeEvent?.url;
241
244
  if (isLoadError) {
242
245
  isLoadError = false;
@@ -262,6 +265,16 @@ const _WebView = forwardRef((props, ref) => {
262
265
  bindload?.(result);
263
266
  }
264
267
  };
268
+ const onLoadEnd = function (res) {
269
+ if (__mpx_mode__ === 'android') {
270
+ setTimeout(() => {
271
+ onLoadEndHandle(res);
272
+ }, 0);
273
+ }
274
+ else {
275
+ onLoadEndHandle(res);
276
+ }
277
+ };
265
278
  const onHttpError = function (res) {
266
279
  isLoadError = true;
267
280
  statusCode = res.nativeEvent?.statusCode;
@@ -269,12 +282,14 @@ const _WebView = forwardRef((props, ref) => {
269
282
  const onError = function () {
270
283
  statusCode = '';
271
284
  isLoadError = true;
272
- if (!fristLoaded) {
285
+ if (!fristLoaded.current) {
273
286
  setPageLoadErr(true);
274
287
  }
275
288
  };
276
289
  const onLoadStart = function () {
277
- isLoaded.current = false;
290
+ if (!fristLoaded.current) {
291
+ setIsLoaded(false);
292
+ }
278
293
  };
279
294
  return (<Portal key={pageLoadErr ? 'error' : 'webview'}>
280
295
  {pageLoadErr
@@ -4,10 +4,10 @@ import { error } from '@mpxjs/utils';
4
4
  // 微信 timingFunction 和 RN Easing 对应关系
5
5
  const EasingKey = {
6
6
  linear: Easing.linear,
7
- ease: Easing.ease,
8
- 'ease-in': Easing.in(Easing.ease),
9
- 'ease-in-out': Easing.inOut(Easing.ease),
10
- 'ease-out': Easing.out(Easing.ease)
7
+ ease: Easing.inOut(Easing.ease),
8
+ 'ease-in': Easing.in(Easing.poly(3)),
9
+ 'ease-in-out': Easing.inOut(Easing.poly(3)),
10
+ 'ease-out': Easing.out(Easing.poly(3))
11
11
  // 'step-start': '',
12
12
  // 'step-end': ''
13
13
  };
@@ -1,4 +1,4 @@
1
- import { AppState, View, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
1
+ import { View, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
2
2
  import { GestureDetector, Gesture } from 'react-native-gesture-handler'
3
3
  import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS, useAnimatedReaction, cancelAnimation } from 'react-native-reanimated'
4
4
 
@@ -117,7 +117,7 @@ const activeDotStyle = {
117
117
  const longPressRatio = 100
118
118
 
119
119
  const easeMap = {
120
- default: Easing.linear,
120
+ default: Easing.inOut(Easing.poly(3)),
121
121
  linear: Easing.linear,
122
122
  easeInCubic: Easing.in(Easing.cubic),
123
123
  easeOutCubic: Easing.out(Easing.cubic),
@@ -195,7 +195,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
195
195
  const moveTime = useSharedValue(0)
196
196
  const timerId = useRef(0 as number | ReturnType<typeof setTimeout>)
197
197
  const intervalTimer = props.interval || 500
198
- const appState = useRef(AppState.currentState)
199
198
  const {
200
199
  // 存储layout布局信息
201
200
  layoutRef,
@@ -315,7 +314,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
315
314
 
316
315
  const { loop, pauseLoop, resumeLoop } = useMemo(() => {
317
316
  function createAutoPlay () {
318
- if (!step.value || appState.current !== 'active') return
317
+ if (!step.value) return
319
318
  let targetOffset = 0
320
319
  let nextIndex = currentIndex.value
321
320
  if (!circularShared.value) {
@@ -367,9 +366,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
367
366
  // loop在JS线程中调用,createAutoPlay + useEffect中
368
367
  function loop () {
369
368
  timerId.current && clearTimeout(timerId.current)
370
- if (appState.current === 'active') {
371
- timerId.current = setTimeout(createAutoPlay, intervalTimer)
372
- }
369
+ timerId.current = setTimeout(createAutoPlay, intervalTimer)
373
370
  }
374
371
 
375
372
  function pauseLoop () {
@@ -437,20 +434,6 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
437
434
  runOnJS(handleSwiperChange)(newIndex)
438
435
  }
439
436
  })
440
- // 监听切换前后台,默认切换到后台JS执行不会立即停止定时器还在
441
- useEffect(() => {
442
- const subscription = AppState.addEventListener('change', nextAppState => {
443
- appState.current = nextAppState
444
- if (nextAppState === 'active' && autoplayShared.value && childrenLength.value > 1) {
445
- loop()
446
- } else {
447
- appState.current = nextAppState
448
- }
449
- })
450
- return () => {
451
- subscription.remove()
452
- }
453
- }, [])
454
437
 
455
438
  useEffect(() => {
456
439
  let patchStep = 0
@@ -471,17 +454,13 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
471
454
 
472
455
  useEffect(() => {
473
456
  childrenLength.value = children.length
474
- pauseLoop()
475
457
  if (children.length - 1 < currentIndex.value) {
458
+ pauseLoop()
476
459
  currentIndex.value = 0
477
460
  offset.value = getOffset(0, step.value)
478
- } else {
479
- // children变化-其他属性都不变化(比如从1变化到3或者从3变到1, 在circular的情况下offset是需要更新的)
480
- currentIndex.value = props.current || 0
481
- offset.value = getOffset(props.current || 0, step.value)
482
- }
483
- if (autoplay && children.length > 1) {
484
- loop()
461
+ if (autoplay && children.length > 1) {
462
+ loop()
463
+ }
485
464
  }
486
465
  }, [children.length])
487
466
 
@@ -99,7 +99,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
99
99
  const [pageLoadErr, setPageLoadErr] = useState<boolean>(false)
100
100
  const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
101
101
  const webViewRef = useRef<WebView>(null)
102
- const isLoaded = useRef<boolean>(false)
102
+ const [isLoaded, setIsLoaded] = useState<boolean>(true)
103
+ const fristLoaded = useRef<boolean>(false)
104
+
103
105
  const defaultWebViewStyle = {
104
106
  position: 'absolute' as 'absolute' | 'relative' | 'static',
105
107
  left: 0 as number,
@@ -153,6 +155,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
153
155
  }
154
156
 
155
157
  const _reload = function () {
158
+ if (__mpx_mode__ === 'android') {
159
+ fristLoaded.current = false // 安卓需要重新设置
160
+ }
156
161
  setPageLoadErr(false)
157
162
  }
158
163
 
@@ -186,7 +191,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
186
191
 
187
192
  const sendMessage = function (params: string) {
188
193
  return `
189
- window.mpxWebviewMessageCallback(${params})
194
+ window.mpxWebviewMessageCallback && window.mpxWebviewMessageCallback(${params})
190
195
  true;
191
196
  `
192
197
  }
@@ -288,11 +293,10 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
288
293
  }
289
294
 
290
295
  let isLoadError = false
291
- let fristLoaded = false
292
296
  let statusCode: string | number = ''
293
- const onLoadEnd = function (res: WebViewEvent) {
294
- fristLoaded = true
295
- isLoaded.current = true
297
+ const onLoadEndHandle = function (res: WebViewEvent) {
298
+ fristLoaded.current = true
299
+ setIsLoaded(true)
296
300
  const src = res.nativeEvent?.url
297
301
  if (isLoadError) {
298
302
  isLoadError = false
@@ -317,6 +321,15 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
317
321
  bindload?.(result)
318
322
  }
319
323
  }
324
+ const onLoadEnd = function (res: WebViewEvent) {
325
+ if (__mpx_mode__ === 'android') {
326
+ setTimeout(() => {
327
+ onLoadEndHandle(res)
328
+ }, 0)
329
+ } else {
330
+ onLoadEndHandle(res)
331
+ }
332
+ }
320
333
  const onHttpError = function (res: WebViewHttpErrorEvent) {
321
334
  isLoadError = true
322
335
  statusCode = res.nativeEvent?.statusCode
@@ -324,12 +337,14 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
324
337
  const onError = function () {
325
338
  statusCode = ''
326
339
  isLoadError = true
327
- if (!fristLoaded) {
340
+ if (!fristLoaded.current) {
328
341
  setPageLoadErr(true)
329
342
  }
330
343
  }
331
344
  const onLoadStart = function () {
332
- isLoaded.current = false
345
+ if (!fristLoaded.current) {
346
+ setIsLoaded(false)
347
+ }
333
348
  }
334
349
 
335
350
  return (
@@ -40,10 +40,10 @@ export type AnimationProp = {
40
40
  // 微信 timingFunction 和 RN Easing 对应关系
41
41
  const EasingKey = {
42
42
  linear: Easing.linear,
43
- ease: Easing.ease,
44
- 'ease-in': Easing.in(Easing.ease),
45
- 'ease-in-out': Easing.inOut(Easing.ease),
46
- 'ease-out': Easing.out(Easing.ease)
43
+ ease: Easing.inOut(Easing.ease),
44
+ 'ease-in': Easing.in(Easing.poly(3)),
45
+ 'ease-in-out': Easing.inOut(Easing.poly(3)),
46
+ 'ease-out': Easing.out(Easing.poly(3))
47
47
  // 'step-start': '',
48
48
  // 'step-end': ''
49
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.9.69-beta.7",
3
+ "version": "2.9.69-beta.8",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"