Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete suggestions are not displaying (Android) #20

Closed
edwinjue opened this issue Sep 16, 2016 · 38 comments
Closed

Autocomplete suggestions are not displaying (Android) #20

edwinjue opened this issue Sep 16, 2016 · 38 comments

Comments

@edwinjue
Copy link

I tried running your Example.js on both a real device and an android emulator and the autocomplete window does not show up when I enter the letter 'P' in the input field. What I'm expecting is a dropdown that shows the 3 titles as per your animated gif. Is there a known issue with android or any reason why the example isn't working as expected?

I also tried adding a console.log to the 'onShowResult' event and it never outputs to Logcat (which makes me believe something isn't right)

Thanks in advance

@binzailani3136
Copy link

I also have same issue. If you solved it, let me know. I waste many time for fixing this issue.

@mrlaessig
Copy link
Collaborator

Thanks for reporting the issue! Android is such a PITA. Tried to run it in the emulator ether the app or the emulator os constantly crashing. As soon I have some more time I will investigate further.

@edwinjue
Copy link
Author

edwinjue commented Sep 19, 2016

Thanks @l-urence, I appreciate it. Until the fix is released, is there another branch or version you could point us to that works for Android?

@mrlaessig
Copy link
Collaborator

@edwinjue Maybe try to install v1.1.2

@edwinjue
Copy link
Author

edwinjue commented Sep 19, 2016

@l-urence, it works! But the "Autocomplete" component must be enclosed in a "View" component with style={{zIndex:1}} as per solution to #21. Please keep us updated when the fix is released. Thanks again buddy

@mrlaessig
Copy link
Collaborator

@edwinjue good to now. I will try to fix this latest next weekend.

@mrlaessig
Copy link
Collaborator

mrlaessig commented Sep 25, 2016

The problem with Android is that it doesn't support overflows (or at least not in RN). This is the reason why there is no suggestion list popping-up, because it is hidden by the parent view. Right now the best solution to go with Android is to use the v1.1.2 release until overflows are supported by RN for Android.

facebook/react-native#6802

@edwinjue
Copy link
Author

edwinjue commented Sep 25, 2016

Thanks @l-urence. v1.1.2 works pretty well actually.

@fab1an
Copy link

fab1an commented Oct 2, 2016

I'm afraid it's not possible to solve this using a single component.

The dropdown list needs to be neighbour to the TextInput in order to be able to overlap other content.

I don't think this will change in upcoming versions of RN.

@mrlaessig
Copy link
Collaborator

@fab1an just for Android? In iOS this works well.

@fab1an
Copy link

fab1an commented Oct 2, 2016

Android has a very different rendering system than iOS.

@DiegoGallegos4
Copy link

DiegoGallegos4 commented Dec 5, 2016

If Autocomplete is sibling of other views it does not either:

<View style={{flexDirection:'row', borderBottomWidth: 1, borderBottomColor: 'rgb(197,195,201)', alignItems: 'center', position: 'relative', zIndex: 1,backgroundColor: '#fff'}}>
            <View style={{flex: 1}}>
              ...
            </View>
              <Autocomplete
                autoCapitalize="none"
                autoCorrect={false}
                data={((visitors.length === 1 && comp(query, visitors[0].name)) || this.state.clicked) ? [] : visitors}
                defaultValue={query}
                containerStyle={{borderWidth: 0, zIndex: 1}}
                inputContainerStyle={{borderWidth: 0, margin: 0}}
                onChangeText={text => {this.setState({ query: text, clicked: false }); console.log(visitors)}}
                placeholder="Enter visitor name"
                listStyle={{zIndex: 1, position: 'absolute'}}
                style={{backgroundColor: 'transparent', fontSize: 14}}
                renderItem={({ name }) => (
                  <TouchableOpacity style={{padding: 5}} onPress={() => this.selectQueryListItem(query, true, name)}>
                    <Text>
                      {name} 
                    </Text>
                  </TouchableOpacity>
                )}
              />
            <TouchableOpacity 
              style={{backgroundColor: '#18AEC3', padding: 10}}
              onPress={()=>...}
            >
              ...
            </TouchableOpacity>
</View>

Had to add zIndex to listStyle and containerStyle because other siblings would overlap it.

@bozzmob
Copy link

bozzmob commented Dec 19, 2016

@mrlaessig
Copy link
Collaborator

v3.0.0 will simplify the integration into Android.

I will close this issue for now, because this is not going to change until there is some kind of support for overflows in RN for Android.

@gitpushdev
Copy link

gitpushdev commented Mar 6, 2018

I'm still facing issue making it work, I'd appreciate if anyone can spot where I'm going wrong, auto complete list is displaying inside the container view and not outside of it. Working as expected on iOS

This is my code:

<Autocomplete data={['data']}
                defaultValue={[]}
                hideResults={true}
                placeholder={strings.search_countries}
                listContainerStyle={{ width: '107.9%', zIndex: 99999999 }}
                underlineColorAndroid='transparent'
                containerStyle={{ width: '90%', borderWidth: 0, borderColor: 'transparent' }}
                inputContainerStyle={{ paddingLeft: 5, borderWidth: 0, borderColor: 'transparent' }}
                onChangeText={this.handleOnChange}
                renderItem={
                    item => (/.Item Component./)
                }
            />

<View style={[styles.contentContainer, { zIndex: 2 }]}>
<View style={[styles.cardRow, { zIndex: 2 }]}>
<View style={[styles.cardRow, { zIndex: 2 }]}>
~~~ AUTO COMPELTE IS RENDERED HERE ~~~~
</View>
</View>
</View>

Card Row style:

flexDirection: 'row',
       height: 40,
       justifyContent: 'center',
       alignContent: 'center',
       alignItems: 'center',
       width: '100%',
       backgroundColor: '#FFFFFF',
       shadowOpacity: 1,
       shadowColor: '#cccccc',
       shadowOffset: { width: 1, height: 1 },
       elevation: 1

contentContainer Style:

   contentContainer: {
        flex: 1,
        flexDirection: 'column',
        justifyContent: 'flex-start',
        alignContent: 'center',
    },

@Johnscorps
Copy link

Johnscorps commented Mar 7, 2018

I added this line to the Autocomplete props, and it worked like a charm, hope this works for you too!

listStyle={{zIndex: 1, position: 'absolute'}}

@gitpushdev
Copy link

It was my messed up view, fixed my views layout and now all is working, sorry for false alarm :)

@vandiepbui
Copy link

I added this line to the Autocomplete props, and it worked like a charm, hope this works for you too!

listStyle={{zIndex: 1, position: 'absolute'}}

Not work for me ! Pls anyone help me

image

@fungilation
Copy link

Is the absolute positioning for Android in docs and examples in this repo still relevant? I see that overflow support has been added since RN 0.57: facebook/react-native@b81c8b5

@sorinbogdan95
Copy link

sorinbogdan95 commented Oct 28, 2019

Not working if it is put inside a parent component and the parent component has a sibling below it, even if autocomplete input's parent has position: absolute and zIndex set. Please reopen issue.

@Hashir524
Copy link

I have tried every possible solution, suggested here. My Component is working fine on ios. But on android list is showing , i can't click. TouchableOpacity is not working. Instead the scroll is getting all the touch events, and other components. Any help would be much appreciated.

@thanhluantl2304
Copy link

I have tried every possible solution, suggested here. My Component is working fine on ios. But on android list is showing , i can't click. TouchableOpacity is not working. Instead the scroll is getting all the touch events, and other components. Any help would be much appreciated.

Me too, any update on this? I'm still waiting for the final solution.

@sabres207
Copy link

I have tried every possible solution, suggested here. My Component is working fine on ios. But on android list is showing , i can't click. TouchableOpacity is not working. Instead the scroll is getting all the touch events, and other components. Any help would be much appreciated.

Me too, any update on this? I'm still waiting for the final solution.

same here, android fixes makes the options not clickable.

@sachin3072004
Copy link

Same here :(

@tayloraleach
Copy link

same

1 similar comment
@mixa63rus
Copy link

same

@isidore18
Copy link

isidore18 commented Jun 4, 2020

Suggestions were not showing either.
Fixed it by adding renderTextInput prop to the autocomplete props

My example here :

renderTextInput={(text) => (
<TextInput
placeholder={'Code postal*'}
style={{
flex: 1,
padding: 0,
color: 'lightgray',
marginTop: 7,
marginBottom: 5,
paddingRight: 11,
backgroundColor: '#f1f0f3',
borderRadius: scale(25),
width: '100%',
height: scale(50)
}}
onChangeText={(text) => {
setZipChoosen(false);
setZipCodeQuery(text);
testZipCode(text);
}}
value={zipCodeQuery}
defaultValue={zipCodeQuery}
/>
)}

I hope it does the job for you too

@MythriJL
Copy link

I have tried every possible solution, suggested here. My Component is working fine on ios. But on android list is showing , i can't click. TouchableOpacity is not working. Instead the scroll is getting all the touch events, and other components. Any help would be much appreciated.

I also have the same problem, can some one reopen this issue

@VivekVithlani
Copy link

Just add 1 line and problem solved.
listStyle={{ position: 'relative' }}

### Before
Simulator Screen Shot - iPhone 11 - 2020-12-16 at 16 01 38

After

Simulator Screen Shot - iPhone 11 - 2020-12-16 at 16 01 24

@msmfsd
Copy link

msmfsd commented Feb 11, 2021

Bump - @mrlaessig any updates on this issue? Adding above suggestions and still cant select a list item on Android

@IvanTrutnev
Copy link

Bump - @mrlaessig any updates on this issue? Adding above suggestions and still cant select a list item on Android

the same

@msmfsd
Copy link

msmfsd commented Feb 26, 2021

@mrlaessig @IvanTrutnev yes I managed to get it to work using different styles for iOS and android. For iOS follow normal guide and for android make sure your container has position relative and set an implicit height, then your inner container should have position absolute:
droidContainer: { position: 'relative', width: '100%', height: 120, }, droidView: { width: '100%', position: 'absolute', zIndex: 1, flex: 1, },

@jakobwak
Copy link

jakobwak commented Mar 19, 2021

This workaround might fit for some. The approach is to grow the height of the parent view together with the result List. It behaves a little bit like an accordion then. I had the best behaviour, when giving the listContainerStyle and listStyle a fixed height. If you need to have the result list as a real overlay, it is not an option.

<View style={[hideResults ? {height: 90} : {height: 280}]}>
<Autocomplete
onShowResult={() => this.showResultCheck()}
onChangeText={text => this.changeValue(text)}
listContainerStyle={{ height: 200, ...}}
listStyle={{ height: 185, ...}}
...
>

showResultCheck (){
this.setState({hideResults : true})
}

changeValue(text){
this.setState({ hideResults: false });
if (this.findItem(text).length == 0){
this.setState({hideResults : true});
}
...
}

In this way the result List does not Interfere with any touchable element in the background.

Bildschirmfoto 2021-03-19 um 18 48 46
Bildschirmfoto 2021-03-19 um 18 50 04

@rabidkitten
Copy link

This issue was opened in 2016 and it is now 2021 and the issue is still occurring. There needs to be a clear and concise fix. Like others have said, it appears that you can't click on an item on Android, whereas it works fine on iOS.

@mrlaessig
Copy link
Collaborator

@rabidkitten I checked this with example and it works at least on an emulator.
image

@rabidkitten
Copy link

@mrlaessig I had the latest and I used the android emulator as well and I couldn't click or tap on an item. The drop down was working, but I couldn't select an item by tapping or clicking. I just gave up on the component altogether.

@mrlaessig
Copy link
Collaborator

@rabidkitten This could happen if they keyboard is still open. Try to pass keyboardShouldPersistTaps: 'always' on flatListProps. See example.

@hlspablo
Copy link

I added this line to the Autocomplete props, and it worked like a charm, hope this works for you too!

listStyle={{zIndex: 1, position: 'absolute'}}

Thanks, worked Perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests