Skip to content

Commit

Permalink
fix: codereivew修改
Browse files Browse the repository at this point in the history
  • Loading branch information
human committed Jan 17, 2025
1 parent 8ab4e76 commit ec0878f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, isObject, isString, noop } from '@mpxjs/utils'
import { isArray, isObject, isString, noop, warn } from '@mpxjs/utils'
import throttle from 'lodash/throttle'
import { Dimensions } from 'react-native'
import { getFocusedNavigation } from '../../../common/js'
Expand All @@ -11,25 +11,27 @@ class RNIntersectionObserver {
constructor (component, options, intersectionCtx) {
this.id = idCount++
this.component = component
this.mpxFileResource = component.__mpxProxy?.options?.mpxFileResource || ''
this.options = Object.assign({
thresholds: [0],
initialRatio: 0,
observeAll: false
observeAll: false,
throttleTime: 100
}, options || {})
this.thresholds = this.options.thresholds.sort((a, b) => a - b) || [0]
this.initialRatio = this.options.initialRatio
this.observeAll = this.options.observeAll

// 组件上挂载对应的observers,用于在组件销毁的时候进行批量disconnect
this.component._intersectionObservers = this.component.__intersectionObservers || []
this.component._intersectionObservers = this.component.__intersectionObservers
this.component._intersectionObservers.push(this)

this.observerRefs = null
this.relativeRef = null
this.margins = DefaultMargin
this.callback = noop

this.throttleMeasure = this.getThrottleMeasure(this.options.throttleTime || 100)
this.throttleMeasure = this.getThrottleMeasure(this.options.throttleTime)

// 记录上一次相交的比例
this.previousIntersectionRatio = []
Expand All @@ -55,7 +57,7 @@ class RNIntersectionObserver {
this.relativeRef = relativeRef
this.margins = Object.assign({}, DefaultMargin, margins)
} else {
console.warn(`node ${selector}is not found. The relative node for intersection observer will be ignored`)
warn(`node ${selector}is not found. The relative node for intersection observer will be ignored`, this.mpxFileResource)
}
return this
}
Expand All @@ -68,7 +70,7 @@ class RNIntersectionObserver {

observe (selector, callback) {
if (this.observerRefs) {
console.warn('"observe" call can be only called once in IntersectionObserver')
warn('"observe" call can be only called once in IntersectionObserver', this.mpxFileResource)
return
}
let targetRef = null
Expand All @@ -78,7 +80,7 @@ class RNIntersectionObserver {
targetRef = this.component.__selectRef(selector, 'node')
}
if (!targetRef || targetRef.length === 0) {
console.warn('intersection observer target not found')
warn('intersection observer target not found', this.mpxFileResource)
return
}
this.observerRefs = isArray(targetRef) ? targetRef : [targetRef]
Expand Down Expand Up @@ -230,7 +232,7 @@ class RNIntersectionObserver {
}
})
}).catch((e) => {
console.log('_measureTarget fail', e)
warn('_measureTarget fail', this.mpxFileResource, e)
})
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,15 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {

useLayoutEffect(() => {
const isCustom = pageConfig.navigationStyle === 'custom'
navigation.setOptions({
navigation.setOptions(Object.assign({
headerShown: !isCustom,
title: pageConfig.navigationBarTitleText || '',
headerStyle: {
backgroundColor: pageConfig.navigationBarBackgroundColor || '#000000'
},
headerTintColor: pageConfig.navigationBarTextStyle || 'white',
statusBarTranslucent: true
})
}, __mpx_mode__ === 'android' ? { statusBarStyle: pageConfig.statusBarStyle || 'light' } : {}))
}, [])

const rootRef = useRef(null)
Expand Down

0 comments on commit ec0878f

Please sign in to comment.