Search code examples
androidreact-nativereact-native-scrollview

React native onStartShouldSetResponder parameter not working for AutoCompeletInput plugin


I am using plugin for Autocomplete Input. I have placed this component in Scrollview. It's other behaviour is fine like displaying suggestion list in popup with our custom design.

Referred Plugin:- Plugin

But onStartShouldSetResponder{()=>true} not working. Because of that I am unable to scroll my suggestion list.

Here is my implemented code =>

<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>
  • Please let me know if I am doing something wrong.
  • Also I am unable to understand implementation of onStartShouldSetResponder() function.
  • Suggest Autocomplete input example in react native which work like Android AutoCompleteTexview component.

Solution

  • Add scrollEnabled parameter to your Scrollview.

    Try with below code

    <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>