Skip to content

onLayout repeated triggered #1

@aoarashi1988

Description

@aoarashi1988

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions