@mpxjs/core 2.9.69-beta.1 → 2.9.69-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.9.69-beta.1",
3
+ "version": "2.9.69-beta.3",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "main": "src/index.js",
21
21
  "dependencies": {
22
- "@mpxjs/utils": "^2.9.69-beta.0",
22
+ "@mpxjs/utils": "^2.9.69-beta.1",
23
23
  "lodash": "^4.1.1",
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
@@ -1,6 +1,6 @@
1
1
  import transferOptions from '../core/transferOptions'
2
2
  import builtInKeysMap from './patch/builtInKeysMap'
3
- import { makeMap, spreadProp, parseUrlQuery, getFocusedNavigation, hasOwn, extend } from '@mpxjs/utils'
3
+ import { makeMap, spreadProp, getFocusedNavigation, hasOwn, extend } from '@mpxjs/utils'
4
4
  import { mergeLifecycle } from '../convertor/mergeLifecycle'
5
5
  import { LIFECYCLE } from '../platform/patch/lifecycle/index'
6
6
  import Mpx from '../index'
@@ -96,14 +96,10 @@ export default function createApp (option, config = {}) {
96
96
  })
97
97
 
98
98
  if (!global.__mpxAppLaunched) {
99
- const parsed = Mpx.config.rnConfig.parseAppProps?.(props) || {}
100
- if (parsed.url) {
101
- const { path, queryObj } = parseUrlQuery(parsed.url)
102
- Object.assign(initialRouteRef.current, {
103
- initialRouteName: path.startsWith('/') ? path.slice(1) : path,
104
- initialParams: queryObj
105
- })
106
- }
99
+ const { initialRouteName, initialParams } = Mpx.config.rnConfig.parseAppProps?.(props) || {}
100
+ initialRouteRef.current.initialRouteName = initialRouteName || initialRouteRef.current.initialRouteName
101
+ initialRouteRef.current.initialParams = initialParams || initialRouteRef.current.initialParams
102
+
107
103
  global.__mpxAppOnLaunch = (navigation) => {
108
104
  global.__mpxAppLaunched = true
109
105
  const state = navigation.getState()
@@ -151,7 +147,7 @@ export default function createApp (option, config = {}) {
151
147
  }
152
148
  }
153
149
  global.__mpxAppCbs.show.forEach((cb) => {
154
- cb(options)
150
+ cb(options || {})
155
151
  })
156
152
  if (navigation && hasOwn(global.__mpxPageStatusMap, navigation.pageId)) {
157
153
  global.__mpxPageStatusMap[navigation.pageId] = 'show'
@@ -187,7 +183,6 @@ export default function createApp (option, config = {}) {
187
183
  const { initialRouteName, initialParams } = initialRouteRef.current
188
184
  const headerBackImageProps = Mpx.config.rnConfig.headerBackImageProps || null
189
185
  const navScreenOpts = {
190
- gestureEnabled: true,
191
186
  // 7.x替换headerBackTitleVisible
192
187
  // headerBackButtonDisplayMode: 'minimal',
193
188
  headerBackTitleVisible: false,
@@ -367,6 +367,12 @@ function usePageStatus (navigation, pageId) {
367
367
  const blurSubscription = navigation.addListener('blur', () => {
368
368
  pageStatusMap[pageId] = 'hide'
369
369
  })
370
+ const transitionEndSubscription = navigation.addListener('transitionEnd', () => {
371
+ if (global.__navigationHelper.transitionEndCallback) {
372
+ global.__navigationHelper.transitionEndCallback()
373
+ global.__navigationHelper.transitionEndCallback = null
374
+ }
375
+ })
370
376
  const unWatchAppFocusedState = watch(global.__mpxAppFocusedState, (value) => {
371
377
  pageStatusMap[pageId] = value
372
378
  })
@@ -375,11 +381,13 @@ function usePageStatus (navigation, pageId) {
375
381
  focusSubscription()
376
382
  blurSubscription()
377
383
  unWatchAppFocusedState()
384
+ transitionEndSubscription()
378
385
  del(pageStatusMap, pageId)
379
386
  }
380
387
  }, [navigation])
381
388
  }
382
389
 
390
+ const pageConfigStack = []
383
391
  export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
384
392
  rawOptions = mergeOptions(rawOptions, type, false)
385
393
  const components = Object.assign({}, rawOptions.components, currentInject.getComponents())
@@ -490,7 +498,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
490
498
  const { Provider, useSafeAreaInsets, GestureHandlerRootView } = global.__navigationHelper
491
499
  const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
492
500
  const Page = ({ navigation, route }) => {
493
- const [enabled, setEnabled] = useState(true)
501
+ const [enabled, setEnabled] = useState(false)
494
502
  const currentPageId = useMemo(() => ++pageId, [])
495
503
  const intersectionObservers = useRef({})
496
504
  usePageStatus(navigation, currentPageId)
@@ -505,20 +513,38 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
505
513
  },
506
514
  headerTintColor: pageConfig.navigationBarTextStyle || 'white'
507
515
  })
508
- if (__mpx_mode__ === 'android') {
509
- ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')
516
+
517
+ const setStatusBar = (config) => {
518
+ ReactNative.StatusBar.setBarStyle(config.barStyle || 'dark-content')
510
519
  ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位
511
- const color = isCustom ? 'transparent' : pageConfig.statusBarColor
520
+ const color = isCustom ? 'transparent' : config.statusBarColor
512
521
  color && ReactNative.StatusBar.setBackgroundColor(color)
513
522
  }
523
+ if (__mpx_mode__ === 'android') {
524
+ pageConfigStack.push(pageConfig)
525
+ setStatusBar(pageConfig)
526
+ }
527
+ return () => {
528
+ if (__mpx_mode__ === 'android') {
529
+ pageConfigStack.pop()
530
+ const config = pageConfigStack[pageConfigStack.length - 1] || {}
531
+ setStatusBar(config)
532
+ }
533
+ };
514
534
  }, [])
515
535
 
516
536
  const rootRef = useRef(null)
517
- const onLayout = useCallback(() => {
518
- rootRef.current?.measureInWindow((x, y, width, height) => {
519
- navigation.layout = { x, y, width, height }
520
- })
521
- }, [])
537
+
538
+ useEffect(() => {
539
+ const unsubscribe = navigation.addListener('transitionEnd', (e) => {
540
+ setTimeout(() => {
541
+ rootRef.current?.measureInWindow((x, y, width, height) => {
542
+ navigation.layout = { x, y, width, height }
543
+ })
544
+ }, 200)
545
+ });
546
+ return unsubscribe;
547
+ }, [navigation]);
522
548
 
523
549
  const withKeyboardAvoidingView = (element) => {
524
550
  if (__mpx_mode__ === 'ios') {
@@ -546,6 +572,14 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
546
572
 
547
573
  navigation.insets = useSafeAreaInsets()
548
574
 
575
+ const [, setState] = useState(1)
576
+
577
+ const setStateRef = useRef(setState)
578
+
579
+ if (setStateRef.current !== setState) {
580
+ setStateRef.current = setState
581
+ }
582
+
549
583
  return createElement(GestureHandlerRootView,
550
584
  {
551
585
  style: {
@@ -559,8 +593,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
559
593
  flex: 1,
560
594
  backgroundColor: pageConfig.backgroundColor || '#ffffff'
561
595
  },
562
- ref: rootRef,
563
- onLayout
596
+ ref: rootRef
564
597
  },
565
598
  createElement(RouteContext.Provider,
566
599
  {
@@ -23,11 +23,13 @@ function transformProperties (properties) {
23
23
  } else {
24
24
  newFiled = Object.assign({}, rawFiled)
25
25
  }
26
+ const rawObserver = rawFiled?.observer
26
27
  newFiled.observer = function (value, oldValue) {
27
28
  if (this.__mpxProxy) {
28
29
  this[key] = value
29
30
  this.__mpxProxy.propsUpdated()
30
31
  }
32
+ rawObserver && rawObserver.call(this, value, oldValue)
31
33
  }
32
34
  newProps[key] = newFiled
33
35
  })