React-native:FlatList基本使用

<FlatList style={{width: ScreenWidth}}
                          ListFooterComponent={
                              //在底部的view,对应有ListHeaderComponent
                              //在列表顶部和尾部需要显示额外信息时候使用
                              ()=>{
                                  return !this.state.FlatListIsLoding?
                                      <TouchableOpacity
                                          style={{backgroundColor:'white',width:ScreenWidth,height:0.1*ScreenHeight,justifyContent:'center',
                                              alignItems:'center'
                                          }}
                                          onPress={()=>{
                                              this.setState((prevState) => ({FlatListIsLoding: true}));
                                              setTimeout(()=>{
                                                  this.setState((prevState) => ({FlatListIsLoding: false}));
                                              },3000)
                                          }}
                                      >
                                          <Text>点击加载更多</Text>
                                      </TouchableOpacity>

                                      :  <ActivityIndicator style={{backgroundColor:'white',width:ScreenWidth,height:0.1*ScreenHeight}} size="large" color="#ff0000"/>;
                              }
                          }
                          ItemSeparatorComponent={
                              () => {
                                  return <View style={{backgroundColor: 'white', width: ScreenWidth, height: 8}}/>;
                              }

                          }
                          refreshing={this.state.FlatListIsRefreshing}
                          onRefresh={()=>{
                              //刷新的方法
                              this.setState((prevState) => ({FlatListIsRefreshing: true}));
                              setTimeout(()=>{
                                  this.setState((prevState) => ({FlatListIsRefreshing: false}));
                              },3000)
                          }}
                          ListEmptyComponent={
                              <View style={{
                                  justifyContent: 'center',
                                  alignItems: 'center',
                                  width: ScreenWidth,
                                  height: 0.8 * ScreenHeight
                              }}>
                                  <Text>空空如也</Text>
                              </View>}
                          data={this.props.hadAddedGoods}
                          renderItem={({item}) => (
                              <View style={{
                                  backgroundColor: item.type == 0 ? 'gray' : '#005AB5',
                                  width: ScreenWidth,
                                  height: 0.13 * ScreenHeight
                              }}>
                                  <Text
                                      style={{fontSize: 17, marginTop: 20, marginLeft: 10}}
                                  >{item.name}</Text>

                                  <TouchableOpacity style={{
                                      paddingTop: 5,
                                      paddingBottom: 5,
                                      paddingLeft: 10,
                                      paddingRight: 10,
                                      borderRadius: 5,
                                      backgroundColor: 'red',
                                      position: 'absolute',
                                      justifyContent: 'center',
                                      alignItems: 'center',
                                      bottom: 10, right: 10
                                  }} onPress={() => {
                                      Alert.alert(
                                          '警告',
                                          '确认删除吗',
                                          [
                                              {text: '取消', onPress: () => console.log('Ask me later pressed'), style: 'cancel'},
                                              {text: '确定', onPress: () => {
                                                      this.props.deleteGoods(item);
                                                  }},
                                          ],
                                          { cancelable: false }
                                      )

                                  }}>
                                      <Text style={{color: 'black'}}>点击删除</Text>
                                  </TouchableOpacity>
                              </View>

                          )}
                >
                </FlatList>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值