Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在setState上反应本机ScrollView丢失位置_Ios_React Native_Scrollview_React Native Ios_Setstate - Fatal编程技术网

Ios 在setState上反应本机ScrollView丢失位置

Ios 在setState上反应本机ScrollView丢失位置,ios,react-native,scrollview,react-native-ios,setstate,Ios,React Native,Scrollview,React Native Ios,Setstate,我需要在ScrollView中更改行的状态(在ListView中相同),但使用组件的setState会使scroll将其位置重置为顶部 <ScrollView {...this.panResponder.panHandlers} bounces={false} onScroll={() => { this.scrollIsScrolling = true; }} o

我需要在ScrollView中更改行的状态(在ListView中相同),但使用组件的setState会使scroll将其位置重置为顶部

          <ScrollView
        {...this.panResponder.panHandlers}
        bounces={false}
        onScroll={() => {
          this.scrollIsScrolling = true;
        }}
        onTouchEnd={() => {
          this.scrollIsScrolling = false;
        }}
        onMomentumScrollEnd={() => {
          this.scrollIsScrolling = false;
        }}
        scrollEnabled={this.state.scrollEnabled}
        removeClippedSubviews={false}
        enableEmptySections
        style={styles.listView}
      >
        {this.props.settings.map((setting, i) => {
          return (
            <IntegrationSlideupCell
              key={i}
              title={setting.title}
              selected={this.state.selectedSetting === i}
              selectedGradient={this.props.integration.selectedGradient}
              onPress={() => {
                this.setState({ selectedSetting: i });
              }}
            />
          );
        })}
      </ScrollView>
{
this.scrolliscrolling=true;
}}
onTouchEnd={()=>{
this.scrolliscrolling=false;
}}
onMomentumScrollEnd={()=>{
this.scrolliscrolling=false;
}}
scrollEnabled={this.state.scrollEnabled}
removeClippedSubviews={false}
使能排空
style={styles.listView}
>
{this.props.settings.map((设置,i)=>{
返回(
{
this.setState({selectedSetting:i});
}}
/>
);
})}

UPD:移除定制的Panhandler、onScroll、onTouchEnd、OnMoneTumScrollEnd处理程序和其他道具没有什么区别。唯一导致它设置状态的因素。

使用偏移方法,如果“IntegrationSlideupCell”给定了一个固定的高度,则可以偏移该宽度并将偏移存储到状态

this.state = {
    contentOffset: {y: 0},
}

function handlePress() {
   offset = HEIGHT_OF_CONTAINER;
   newOffset = this.state.contentOffset.y + offset;    
   this.setState({contentOffset: {y: newOffset}, selectedSetting: i });
} 

          <ScrollView
    {...this.panResponder.panHandlers}
    bounces={false}
    contentOffset={this.state.contentOffset}
    onScroll={() => {
      this.scrollIsScrolling = true;
    }}
    onTouchEnd={() => {
      this.scrollIsScrolling = false;
    }}
    onMomentumScrollEnd={() => {
      this.scrollIsScrolling = false;
    }}
    scrollEnabled={this.state.scrollEnabled}
    removeClippedSubviews={false}
    enableEmptySections
    style={styles.listView}
  >
    {this.props.settings.map((setting, i) => {
      return (
        <IntegrationSlideupCell
          key={i}
          title={setting.title}
          selected={this.state.selectedSetting === i}
          selectedGradient={this.props.integration.selectedGradient}
          onPress={handlePress.bind(this)}
        />
      );
    })}
  </ScrollView>
   
   
this.state={
contentOffset:{y:0},
}
功能手柄{
偏移=容器的高度;
newOffset=this.state.contentOffset.y+offset;
this.setState({contentOffset:{y:newOffset},selectedSetting:i});
} 
{
this.scrolliscrolling=true;
}}
onTouchEnd={()=>{
this.scrolliscrolling=false;
}}
onMomentumScrollEnd={()=>{
this.scrolliscrolling=false;
}}
scrollEnabled={this.state.scrollEnabled}
removeClippedSubviews={false}
使能排空
style={styles.listView}
>
{this.props.settings.map((设置,i)=>{
返回(
);
})}

您是否尝试在scrollview上的ContentSizeChange上保存内容大小?不,我没有。但iOS滚动视图(本机视图)即使大小改变也会保持不变。所以我也期待着同样的结果。但是我会尝试的,谢谢你的建议。为什么不引入
scrollToIndex()
功能呢?目前通过在使用setState之前存储偏移量来修复。但是继续调查。