鍍金池/ 問答/HTML5  HTML/ react-native 在 SectionList 的 ref 中 setNa

react-native 在 SectionList 的 ref 中 setNativeProps 無效

先看代碼

  render() {
    const { children, listRef } = this.props
    const { animatedValue, _panResponder } = this.state
    // console.log(listRef)
    listRef.setNativeProps({
      onScroll: () => {
        console.log('開始滾動')
      }
    })

    return (
      <Animated.View
        {..._panResponder.panHandlers}
        style={{
          transform: animatedValue.getTranslateTransform(),
        }}
      >
        {children}
      </Animated.View>
    )
  }

問題:第6行的onScroll沒有如期觸發(fā)

  • 可以確定 listRef 是一個正確的實例
  • SectionList 的 jsx 中傳入的 onScroll 是可以生效的
  • listRef.setNativeProps({ scrollEnabled: true })是可以生效的

有沒有道友知道是哪里出了問題?

回答
編輯回答
忠妾

好吧,我在 官方github 找到了答案

事實上這個問題并沒有被解決,因為當前版本的 RN (5.2) 的 SectionList 似乎不支持 setNativeProps 的完整功能

2017年4月16日 07:34