How to customize look/feel of React Native ListView's RefreshControl

后端 未结 2 768
忘了有多久
忘了有多久 2020-12-14 18:00

React Native\'s ListView has a built-in pull-to-refresh control called RefreshControl. It\'s super easy to use.

I\'d like to customize the look and feel of the cont

相关标签:
2条回答
  • 2020-12-14 18:44

    You can outsmart it by doing:

    • setting transparent properties to ListView
    • Adding component with absolute position

    Example:

    <View style={{height:Dimensions.get('window').height}}>
      {/* custom refresh control */}
      <View
        style={{position:'absolute',
          width:Dimensions.get('window').width, height:60,
          alignItems:'center', justifyContent:'center'}}>
        <Progress.CircleSnail
          color={['red', 'green', 'blue']}
          duration={700} />
      </View>
      {/* list view*/}
      <ListView
        dataSource={this.state.dataSource}
        refreshControl={
          <RefreshControl
            onLayout={e => console.log(e.nativeEvent)}
            // all properties must be transparent
            tintColor="transparent"
            colors={['transparent']}
            style={{backgroundColor: 'transparent'}}
            refreshing={this.state.refreshing}
            onRefresh={() => {
              this.setState({refreshing:true});
              setTimeout(() => {
                this._addRows()
              }, 2000);
            }}
            />
        }
        renderRow={(rowData) => <Text>{rowData}</Text>} />
    </View>
    

    This is the result:

    0 讨论(0)
  • 2020-12-14 18:59

    You can totally do this. It requires some work though. You can start by writing something like this.

    <View style={styles.scrollview}>
      <View style={styles.topBar}><Text style={styles.navText}>PTR Animation</Text></View>
      <View style={styles.fillParent}>
        <Text>Customer indicator goes here...</Text>
      </View>
      <View style={styles.fillParent}>
        <ListView
          style={{flex: 1}}
          dataSource={this.state.dataSource}
          renderRow={(rowData) => <View style={styles.row}><Text style={styles.text}>{rowData}</Text></View>}
          ref='PTRListView'
        />
      </View>
    </View>
    

    When you'll pull to refresh, you should see the text "Custom indicator goes here..."

    Following this pattern, you can place your component instead of just a view and a text.

    For the credits, thanks to this article for the idea.

    0 讨论(0)
提交回复
热议问题