react-native ScrollView下使用 RefreshControl 的 loading指示图标模拟下拉刷新页面场景

本文深入探讨了在React Native中使用RefreshControl组件实现下拉刷新功能的方法。通过代码示例展示了如何设置refreshing状态,调整indicator的大小、颜色,并通过setTimeout模拟数据加载过程。此外,还介绍了如何将该组件应用到ScrollView中,以实现更佳的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图:

 

 

代码如下:

_onRefresh = () => {
    this.setState({ refreshing: true });
    // setTimeout模拟请求获取数据回调
    setTimeout(() => {
      this.setState({ refreshing: false });
    }, 3000);
};
 <ScrollView
          style={{ flex: 1 }}
          refreshControl={
            <RefreshControl
              // size={RefreshControl.SIZE.LARGE} // size属性改变Android上的indicator的大小,值默认为DEFAULT,可以改成 LARGE.
              enabled={true}
              colors={[OAColor.headBg, "white"]} // colors属性改变Android上的indicator的颜色,值为数组,可以只设置一个颜色,
              tintColor={OAColor.headBg} // tintColor属性改变iOS上的indicator的颜色,只能指定一个值。
              refreshing={refreshing}
              onRefresh={this._onRefresh}
            />
          }
        >
          {this.renderSwiper()}

          <View style={{ flex: 1 }}>
            <Text
              style={{
                zIndex: 2,
                position: "absolute",
                top: -62,
                width: "70%",
                color: OAColor.white,
                paddingLeft: OAVariables.h_spacing_lg
              }}
              numberOfLines={1}
            >
              轮播图新闻标题...
            </Text>
            <View
              style={{
                position: "absolute",
                top: -70,
                width: "100%",
                height: 30,
                paddingVertical: OASize(8),
                opacity: 0.5,
                backgroundColor: OAColor.black
              }}
            />
          </View>

          {this.renderMainNav()}
          {this.renderNotice()}
          <WhiteSpace height={10} />
          {this.renderNews()}
</ScrollView>
      

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hzxOnlineOk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值