-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I see the the code below in your index.js
onLayout = (event: LayoutChangeEvent) => {
const { loop } = this.props
const {
index,
total,
dir,
width,
height,
} = this.state
const { width: layoutWidth, height: layoutHeight } = event.nativeEvent.layout // <== here
// const layoutWidth = Math.round(event.nativeEvent.layout.width)
// const layoutHeight = Math.round(event.nativeEvent.layout.height)
let offsetWouldBeSet: Partial<Offset> = this.realtimeOffset = {}
const stateWouldBeSet: any = { width: layoutWidth, height: layoutHeight }
if (total > 1) {
let actualIndex = index
loop && actualIndex++
offsetWouldBeSet = getOffset(dir, actualIndex, layoutWidth, layoutHeight)
}
// only update the offset in state if needed, updating offset while swiping
// causes some bad jumping / stuttering
if (layoutWidth !== width || layoutHeight !== height) {
stateWouldBeSet.offset = offsetWouldBeSet
}
this.setState(stateWouldBeSet)
}
then I found that onLayout method triggered every few milliseconds , and it lead to a huge lag .
if I enable the 2 row below
// const layoutWidth = Math.round(event.nativeEvent.layout.width)
// const layoutHeight = Math.round(event.nativeEvent.layout.height)
this problem will be resolved .
Metadata
Metadata
Assignees
Labels
No labels