android - React native onStartShouldSetResponder 参数不适用于 AutoCompeletInput 插件

标签 android react-native react-native-scrollview

我正在使用自动完成输入插件。 我已将此组件放在 Scrollview 中。它的其他行为很好,例如使用我们的自定义设计在弹出窗口中显示建议列表。

推荐插件:- Plugin

但是onStartShouldSetResponder{()=>true} 不工作。 因此,我无法滚动我的建议列表。

这是我实现的代码=>

<ScrollView keyboardShouldPersistTaps='always' style={[commonstyles.mainContainer,styles.mainContainer,{marginBottom:20}]}>
            <View style={{width:width-30,height:45}}>
            <Autocomplete
              autoCapitalize="none"
              autoCorrect={false}
              hideResults={false}
              containerStyle={{flex: 1,left: 10,position: 'absolute',right: 10,top: 0,zIndex: 1}}
              data={films.length === 1 && comp(query, films[0].name) ? [] : films}
              defaultValue={query}
              onChangeText={text => this.setState({ query: text })}
              placeholder="Select Contact"
              renderItem={({ id,name }) => (
                <TouchableOpacity onStartShouldSetResponder={()=>{return true;}} activeOpacity={1} onPress={() => this.setState({ query: name })}>
                  <Text style={{fontSize:Global.DESCRIPTION_FONT_SIZE,color:Global.APP_BLACK_COLOR,borderBottomWidth:0.5,borderColor:Global.APP_BLACK_COLOR,padding:5}}>
                    {id} {name}
                  </Text>
                </TouchableOpacity>
              )}
            />
            </View>

</Scrollview>
  • 如果我做错了什么,请告诉我。
  • 我也无法理解 onStartShouldSetResponder() 函数的实现。
  • 建议在 React Native 中使用类似于 Android AutoCompleteTexview 组件的自动完成输入示例。

最佳答案

scrollEnabled 参数添加到您的 ScrollView 。

试试下面的代码

<ScrollView scrollEnabled={this.state.enableScrollViewScroll} keyboardShouldPersistTaps='always' style={[commonstyles.mainContainer,styles.mainContainer,{marginBottom:20}]}>
    <View style={{width:width-30,height:45}}>
    <Autocomplete
      autoCapitalize="none"
      autoCorrect={false}
      hideResults={false}
      onStartShouldSetResponderCapture={() => {
         var self=this;
         this.setState({ enableScrollViewScroll: false });
         console.log("Here==>",self.state.enableScrollViewScroll);
      }}
      containerStyle={{flex: 1,left: 10,position: 'absolute',right: 10,top: 0,zIndex: 1}}
      data={films.length === 1 && comp(query, films[0].name) ? [] : films}
      defaultValue={query}
      onChangeText={text => this.setState({ query: text })}
      placeholder="Select Contact"
      renderItem={({ id,name }) => (
        <TouchableOpacity  activeOpacity={1} onPress={() => this.setState({ query: name,enableScrollViewScroll:true })}>
          <Text style=                {{fontSize:Global.DESCRIPTION_FONT_SIZE,color:Global.APP_BLACK_COLOR,borderBottomWidth:0.5,borderColor:Global.APP_BLACK_COLOR,padding:5}}>
        {id} {name}
          </Text>
        </TouchableOpacity>
      )}
    />
    </View>

</Scrollview>

关于android - React native onStartShouldSetResponder 参数不适用于 AutoCompeletInput 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52254242/

相关文章:

android - 如何从 RecyclerView 清除数据监听器/订阅?

javascript - 在 ES6 中追加对象?

android - 在不同选项卡之间滑动很流畅,但选项卡的更改非常慢

android - 移动设备使用 PGP 会不会太过分了?

android - 在 LinearLayout 中添加多个 TextView 会导致 stackOverflowError

react-native - 在 React Native 应用程序上没有远程调试器时无法调用 web3.eth.accounts.create()

javascript - React-Native native-base 如何减小卡片项之间的间距?

reactjs - 向上拖动 ScrollView,然后在 React Native 中继续滚动

react-native - 如何确定 ScrollView (或 ListView )子项是否在 React Native 的 View 中

java - 为什么多次使用Notification.Builder会使应用程序崩溃?