React-native-google-places-autocomplete: Style clear button

Created on 10 Oct 2017  路  4Comments  路  Source: FaridSafi/react-native-google-places-autocomplete

Is there a way to add styles to the clear button? With my current styling it is not visible, so I need to style it individually.

Most helpful comment

@NelsonPetitos You don't need to modify the source component, just pass this as a prop to your component (instead of step 1 above): textInputProps={{ clearButtonMode: 'never' }}

All 4 comments

Same issue. Found any solution ?

Find a solution but you will have to change the react-native-google-places-autocomplete component.
1 - Change clearButtonMode="while-editing" to clearButtonMode="never" in GooglePlacesAutocomplete.js file
2 - Use renderRightButton property to display may be an
//Don't forget to import { Icon } from 'react-native-elements'
3 - Add onPress property on that right button to clear the inputText

@NelsonPetitos You don't need to modify the source component, just pass this as a prop to your component (instead of step 1 above): textInputProps={{ clearButtonMode: 'never' }}

Hi all, I created my own clear button for android but i am facing an issue. Hoping that u guys can help me out.

Using this:

<GooglePlacesAutocomplete
                    minLength={2}
                    listViewDisplayed="auto"
                    autoFocus={false}
                    returnKeyType={'search'}
                    fetchDetails={true}
                    query={{
                        key: Config.GOOGLE_MAPS_KEY,
                        language: 'en'
                    }}
                    textInputProps={{
                        clearButtonMode: 'never',
                        ref: input => {
                            this.textInput = input;
                        }
                    }}
                    onPress={(data, details = null) => {
                        var coordinates = {
                            lat: details.geometry.location.lat,
                            lng: details.geometry.location.lng,
                            name: details.name
                        };
                        this.handleRelocation(coordinates, 'search');
                    }}
                    styles={searchBarStyle}
                    renderRightButton={() => (
                        <TouchableOpacity
                            style={styles.clearButton}
                            onPress={() => {
                                this.textInput.clear();
                            }}
                        >
                            <Icon
                                name="remove"
                                size={15}
                                style={styles.fabButton}
                            />
                        </TouchableOpacity>
                    )}
                />

Important thing: Using this.textinput.clear() for clearing the input box but i read the source code and inferred that actually there is a this.state.text where the text is stored and upon reloading the screen (having this <GooglePlacesAutocomplete /> component) the text reappears in the text input.

Any help?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RajanPN picture RajanPN  路  3Comments

biks152207 picture biks152207  路  4Comments

oporter1 picture oporter1  路  4Comments

DennisMuchiri picture DennisMuchiri  路  4Comments

macs03 picture macs03  路  3Comments