Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

react native - FlatList inside ScrollView not scrolling

I have a requirement where profile data will be on the top and the feed will come after that. While scrolling the feed, the profile part also should scroll. Means the whole page needs to scroll.

So I have implemented FlatList inside ScrollView.

<ScrollView
        contentContainerStyle={{ flex: 1 }}>
        <FlatList
          showsVerticalScrollIndicator={false}
          showsHorizontalScrollIndicator={false}
          data={this.state.feed}
          keyExtractor={(item, index) => item.id}
          refreshControl={this.refreshControl()}
          renderItem={({ item, index }) => this.renderItem(item, index)}
          numColumns={2}
          ListFooterComponent={this.renderFooter.bind(this)}
          onEndReachedThreshold={0.4}
          onEndReached={this.handleLoadMore.bind(this)} />
</ScrollView> 

But I'm not able to scroll the page.

If I remove the contentContainerStyle={{ flex: 1 }}, then handleLoadMore function calling itself continuously.

Thanks for any suggestions!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this

  <ScrollView
    contentContainerStyle={{flexGrow:1}}
        scrollEventThrottle={200}
        directionalLockEnabled={true}
    >
 <FlatList
          showsVerticalScrollIndicator={false}
          showsHorizontalScrollIndicator={false}
          data={this.state.feed}
          keyExtractor={(item, index) => item.id}
          refreshControl={()=>this.refreshControl()}
          renderItem={({ item, index }) => this.renderItem(item, index)}
          numColumns={2}
          ListFooterComponent={(e)=>this.renderFooter.bind(e)}
          onEndReachedThreshold={0.4}
          onEndReached={(e)=>this.handleLoadMore.bind(e)} />



use Callback like this. //

()=>this.yourFUNC()

or

this.yourFUNC()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...