【问题标题】:Hide FlatList Footer隐藏平面列表页脚
【发布时间】:2020-06-25 10:14:15
【问题描述】:

我正在使用平面列表来显示我的购物车中的项目。 当购物车为空时,我正在使用 ListEmptyComponent 显示空购物车消息。当我的 FlatList 为空时,如何隐藏我的 ListFooterComponent?

  return (
    <View style={styles.mainscreen}>
      <View style={styles.cartScreen}>
        <FlatList
          data={cartItems}
          keyExtractor={(item) => item.productId}
          renderItem={(itemData) => (
            <CartItem
              quantity={itemData.item.quantity}
              title={itemData.item.productTitle}
              amount={itemData.item.sum}
              onRemove={() => {
                dispatch(cartActions.removeFromCart(itemData.item.productId));
              }}
            />
          )}
          ListEmptyComponent={() => (
            <Animatable.View
              style={styles.emptyCart}
              animation="bounceIn"
              easing="ease-in">
              <Image
                style={styles.emptyCartImg}
                source={{
                  uri: 'https://i.imgur.com/kgKJc5q.png',
                }}
              />
              <Text style={styles.emptyCartHeader}>Your Cart is Empty!</Text>
              <Text style={styles.emptyCartTxt}>
                Looks like you haven't added anything yet.
              </Text>
            </Animatable.View>
          )}
          ListFooterComponent={() => (
            <View style={styles.footerCart}>
              <Text style={styles.summaryText}>Taxes : </Text>
              <Text style={styles.summaryText}>Delivery Charges :</Text>
            </View>
          )}
        />

【问题讨论】:

    标签: react-native react-native-flatlist


    【解决方案1】:

    如果数组有如下数据,你可以在列表空组件中放置一个条件来渲染

          ListFooterComponent={() =>
            cartItems.length > 0 && (
              <View style={styles.footerCart}>
                <Text style={styles.summaryText}>Taxes : </Text>
                <Text style={styles.summaryText}>Delivery Charges :</Text>
              </View>
            )
          }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 2014-04-08
      • 1970-01-01
      • 2015-03-18
      相关资源
      最近更新 更多