简体   繁体   English

FlatList onRefresh不适用于SafeAreaView

[英]FlatList onRefresh doesn't work with SafeAreaView

Pull to refresh causes endless spinner and don't calling onRefresh when app tested on iPhone. 拉动刷新导致无尽的微调器,并且在iPhone上测试应用程序时不要调用onRefresh。 On Android and iOS devices with home button everything works as expected. 在带有主页按钮的Android和iOS设备上,一切都按预期工作。

ReactNative version: 0.58.3 ReactNative版本:0.58.3

When flex:1 removed from container style, everything works fine but it ruins a markdown of screen. 当flex:1从容器样式中删除时,一切正常,但它破坏了屏幕的降价。 Using ScrollView causes same problem. 使用ScrollView会导致同样的问题。

render() {
  return (
  <View style={styles.container}>
    <SafeAreaView style={styles.safeAreaView}>
      <Toolbar
        leftElement="menu"
        centerElement="sometext"
        style={{ container: { backgroundColor: '#ffa500' } }}
        searchable={{
          autoFocus: true,
          placeholder: 'Search',
          onChangeText: text => this.searchFilterFunction(text),
          onSearchCloseRequested: () => this.resetSearchFilter()
        }}
        onLeftElementPress={() => this.props.navigation.openDrawer()}
      />
    </SafeAreaView>

      <FlatList 
          data={this.state.data}
          keyExtractor={this.keyExtractor}
          ItemSeparatorComponent={this.renderSeparator}
          contentContainerStyle={{paddingLeft: '3%', paddingBottom: '4%'}}
          refreshing={this.state.refreshing}
          onRefresh={this.getData}
          renderItem={({item}) => 
            <PartnerCardComponent 
              partnerName={item.name} 
              discount={item.discount}
              url={item.url}
              image={item.image}
              phone={item.telephones}
              address={item.locations}
              description={item.description}
              navigation={this.props.navigation}
            />
          }
      />
      <SafeAreaView style={styles.bottomArea}/>
    </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white'
  },
  safeAreaView: {
    backgroundColor: '#ffa500',
    shadowColor: 'gray',
    shadowOffset: {height: 1, width: 0},
    shadowOpacity: 0.5,
  },
  bottomArea: {
    backgroundColor: 'white',
    shadowColor: 'white',
    shadowOffset: {height: -5, width: 0},
    shadowOpacity: 5,
  }
});

Expected: updating FlatList data 预期:更新FlatList数据

Receiving: endless spinner rotation, onRefresh doesn't calling. 接收:无尽的微调旋转,onRefresh不调用。

I had a similar situation (though my FlatList was inside a SafeAreaView, not surrounded by them). 我有类似的情况(虽然我的FlatList SafeAreaView内,没有被它们包围)。 What worked for me was using a, in my opinion, vaguely described RefreshControl component rather than setting the onRefresh and refreshing props directly. 对我来说有用的是在我看来,模糊地描述了RefreshControl组件,而不是直接设置onRefresh和刷新道具。 Without seeing the rest of your code (and importing RefreshControl from react-native) I've just dropped it in: 没有看到你的其余代码(并从react-native导入RefreshControl)我刚刚把它放入:

...
<FlatList
  data={this.state.data}
  keyExtractor={this.keyExtractor}
  ItemSeparatorComponent={this.renderSeparator}
  contentContainerStyle={{paddingLeft: '3%', paddingBottom: '4%'}}

      refreshControl={<RefreshControl
        refreshing={this.state.refreshing}
        onRefresh={this.getData}
      />}

  renderItem={({item}) =>
    <PartnerCardComponent 
      partnerName={item.name} 
      discount={item.discount}
      url={item.url}
      image={item.image}
      phone={item.telephones}
      address={item.locations}
      description={item.description}
      navigation={this.props.navigation}
    />
  }
/>
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM