代码之家  ›  专栏  ›  技术社区  ›  stevenpcurtis

React Native Refresh Flatlist不在Android上工作

  •  1
  • stevenpcurtis  · 技术社区  · 7 年前

    当用户按下由gpsdatasource填充的扁平列表时

    this.state = {
      gpsDataSource: [
        { selected: false, title: I18n.t('Settings_precise_11f271'), code: 'precise' },
        { selected: false, title: I18n.t('Settings_approximate_b23bbf'), code: 'approximate' },
        { selected: true, title: I18n.t('Settings_off_810357'), code: 'off' },
      ],
    };
    

    通过填充

            <FlatList
              data={this.state.gpsDataSource}
              extraData={this.state.refresh}
              renderItem={({ item, index }) =>
              <View>
                  {(Platform.OS === 'android') ? 
                  <TouchableNativeFeedback onPress={() => this._onGPSPress(item)}  background={TouchableNativeFeedback.SelectableBackground()} >
                      <View>
                        <MenuItem
                          item={item}
                          navigation={this.props.navigation}
                        />
                      </View>
                      </TouchableNativeFeedback>
                      :
                      <TouchableHighlight
                          onPress={() => this._onGPSPress(item)} 
                          underlayColor='gray'>
                          <MenuItem
                              item={item}
                              onPress={() => this._onGPSPress(item)} 
                              navigation={this.props.navigation}
    
                              />
    
                      </TouchableHighlight>
                  }
              </View>
          }
    
              keyExtractor={(item, index) => index.toString()}
            />
    

    用户选择一个项目

     _onGPSPress(_click) {
        this.state.gpsDataSource.map(element => {
          if (element.code == _click.code) 
          {console.log("match");  element.selected = true; return element }
          else { console.log("no match");element.selected = false ; return element }
        });
    this.setState({
      refresh: !this.state.refresh
    })
    
    //Todo: appropriate server calls
      }
    

    flatlist在iOS上刷新,而不是Android(顺便说一下,menuitem对于两个平台是相同的。

    如何让平板列表(菜单项中有一个选定的蓝色点)刷新Android?

    0 回复  |  直到 7 年前
    推荐文章