Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

路由切换使用native-stack&相交api部分问题修复 #1815

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { isArray, isObject, isString, noop } from '@mpxjs/utils'
import throttle from 'lodash/throttle'
import { Dimensions } from 'react-native'
import { getFocusedNavigation } from '../../../common/js'

const WindowRefStr = 'window'
const IgnoreTarget = 'ignore'
const DefaultMargin = { top: 0, bottom: 0, left: 0, right: 0 }
Expand All @@ -12,10 +11,14 @@ class RNIntersectionObserver {
constructor (component, options, intersectionCtx) {
this.id = idCount++
this.component = component
this.options = options
this.thresholds = options.thresholds.sort((a, b) => a - b) || [0]
this.initialRatio = options.initialRatio || 0
this.observeAll = options.observeAll || false
this.options = Object.assign({
thresholds: [0],
initialRatio: 0,
observeAll: false
}, options || {})
this.thresholds = this.options.thresholds.sort((a, b) => a - b) || [0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| [0]不需要了

this.initialRatio = this.options.initialRatio
this.observeAll = this.options.observeAll

// 组件上挂载对应的observers,用于在组件销毁的时候进行批量disconnect
this.component._intersectionObservers = this.component.__intersectionObservers || []
Expand All @@ -26,7 +29,7 @@ class RNIntersectionObserver {
this.margins = DefaultMargin
this.callback = noop

this.throttleMeasure = this.getThrottleMeasure(options.throttleTime || 100)
this.throttleMeasure = this.getThrottleMeasure(this.options.throttleTime || 100)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认值直接写在上面呗


// 记录上一次相交的比例
this.previousIntersectionRatio = []
Expand Down Expand Up @@ -65,7 +68,7 @@ class RNIntersectionObserver {

observe (selector, callback) {
if (this.observerRefs) {
console.error('"observe" call can be only called once in IntersectionObserver')
console.warn('"observe" call can be only called once in IntersectionObserver')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

走utils中的logger

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把component传进去,可以有更多定位信息

return
}
let targetRef = null
Expand All @@ -75,7 +78,7 @@ class RNIntersectionObserver {
targetRef = this.component.__selectRef(selector, 'node')
}
if (!targetRef || targetRef.length === 0) {
console.error('intersection observer target not found')
console.warn('intersection observer target not found')
return
}
this.observerRefs = isArray(targetRef) ? targetRef : [targetRef]
Expand All @@ -95,10 +98,10 @@ class RNIntersectionObserver {
}

const windowRect = {
top: navigationLayout.y + this.margins.top,
left: this.margins.left,
right: navigationLayout.width - this.margins.right,
bottom: navigationLayout.y + navigationLayout.height - this.margins.bottom
top: navigationLayout.y - this.margins.top,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥是这么改

left: 0 - this.margins.left,
right: navigationLayout.width + this.margins.right,
bottom: navigationLayout.y + navigationLayout.height + this.margins.bottom
}

this.windowRect = windowRect
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import Mpx from '../index'
import { createElement, memo, useRef, useEffect } from 'react'
import * as ReactNative from 'react-native'
import { Image } from 'react-native'

const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)

Expand Down Expand Up @@ -180,18 +179,18 @@ export default function createApp (options) {
}, [])

const { initialRouteName, initialParams } = initialRouteRef.current
const headerBackImageProps = Mpx.config.rnConfig.headerBackImageProps || null
const headerBackImageSource = Mpx.config.rnConfig.headerBackImageSource || null
const navScreenOpts = {
// 7.x替换headerBackTitleVisible
// headerBackButtonDisplayMode: 'minimal',
headerBackTitleVisible: false,
// 安卓上会出现初始化时闪现导航条的问题
headerShown: false
headerShown: false,
// 隐藏导航下的那条线
headerShadowVisible: false
}
if (headerBackImageProps) {
navScreenOpts.headerBackImage = () => {
return createElement(Image, headerBackImageProps)
}
if (headerBackImageSource) {
navScreenOpts.headerBackImageSource = headerBackImageSource
}
return createElement(SafeAreaProvider,
null,
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,9 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
headerStyle: {
backgroundColor: pageConfig.navigationBarBackgroundColor || '#000000'
},
headerTintColor: pageConfig.navigationBarTextStyle || 'white'
headerTintColor: pageConfig.navigationBarTextStyle || 'white',
statusBarTranslucent: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

安卓statusbar那堆东西确定不要了?

})
if (__mpx_mode__ === 'android') {
ReactNative.StatusBar.setBarStyle(pageConfig.barStyle || 'dark-content')
ReactNative.StatusBar.setTranslucent(isCustom) // 控制statusbar是否占位
const color = isCustom ? 'transparent' : pageConfig.statusBarColor
color && ReactNative.StatusBar.setBackgroundColor(color)
}
}, [])

const rootRef = useRef(null)
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/lib/react/processScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ module.exports = function (script, {
output += `
import { getComponent } from ${stringifyRequest(loaderContext, optionProcessorPath)}
import { NavigationContainer, StackActions } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import { createNativeStackNavigator } from '@react-navigation/native-stack'
import { Provider } from '@ant-design/react-native'
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
import { GestureHandlerRootView } from 'react-native-gesture-handler'

global.__navigationHelper = {
NavigationContainer: NavigationContainer,
createStackNavigator: createStackNavigator,
createStackNavigator: createNativeStackNavigator,
StackActions: StackActions,
GestureHandlerRootView: GestureHandlerRootView,
Provider: Provider,
Expand Down
Loading