@mpxjs/core 2.10.18-beta.14 → 2.10.18-beta.16

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.10.18-beta.14",
3
+ "version": "2.10.18-beta.16",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -535,6 +535,28 @@ function getLayoutData (headerHeight) {
535
535
  }
536
536
  }
537
537
 
538
+ let hasResolvedSafeAreaTop = false
539
+
540
+ function getSafeAreaInsetsWithInitialTop (safeAreaInsets) {
541
+ if (ReactNative.Platform.OS !== 'android' || hasResolvedSafeAreaTop) {
542
+ return safeAreaInsets
543
+ }
544
+ const initialTop = initialWindowMetrics?.insets?.top || 0
545
+ if (safeAreaInsets?.top === 0 && initialTop) {
546
+ // Android 初始化时 top 可能连续为 0(如红米 10 的 bottom 已更新但 top 仍为 0),此时持续兜底并保留其他 insets 的最新值。
547
+ // 返回新对象,避免修改 useSafeAreaInsets/context 返回的引用。
548
+ return {
549
+ ...safeAreaInsets,
550
+ top: initialTop
551
+ }
552
+ }
553
+ if (safeAreaInsets?.top > 0 || !initialTop) {
554
+ // 拿到真实 top 或没有可用初始值后,后续完全使用 useSafeAreaInsets 的更新。
555
+ hasResolvedSafeAreaTop = true
556
+ }
557
+ return safeAreaInsets
558
+ }
559
+
538
560
  export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
539
561
  return function PageWrapperCom ({ navigation, route, ...props }) {
540
562
  const keyboardAvoidRef = useRef(null)
@@ -583,8 +605,8 @@ export function PageWrapperHOC (WrappedComponent, pageConfig = {}) {
583
605
  )
584
606
  )
585
607
  }
586
- // android存在第一次打开insets都返回为0情况,后续会触发第二次渲染后正确
587
- navigation.insets = useSafeAreaInsets()
608
+ // Android 初始化期间持续兜底 safe area top,直到 useSafeAreaInsets 返回真实值。
609
+ navigation.insets = getSafeAreaInsetsWithInitialTop(useSafeAreaInsets())
588
610
  return withKeyboardAvoidingView(
589
611
  createElement(ReactNative.View,
590
612
  {