react-native-phone-input icon indicating copy to clipboard operation
react-native-phone-input copied to clipboard

TypError: undefined is not an object (evaluating 'this.countryPicker.openModal')

Open meliodev opened this issue 5 years ago • 3 comments

When I invoke onPressFlag(){ this.countryPicker.openModal() } by pressing the country flag, I get undefined. Here is the code below:

`import React, { Component } from 'react'; import { StyleSheet, View } from 'react-native';

import PhoneInput from 'react-native-phone-input'; import CountryPicker from 'react-native-country-picker-modal';

export default class Test4 extends React.Component { constructor() { super();

this.onPressFlag = this.onPressFlag.bind(this);
this.selectCountry = this.selectCountry.bind(this);
this.state = {
  cca2: 'US',
};

}

componentDidMount() { this.setState({ pickerData: this.phone.getPickerData(), }); }

onPressFlag(){ this.countryPicker.openModal() }

selectCountry(country){ this.phone.selectCountry(country.cca2.toLowerCase()) this.setState({cca2: country.cca2}) }

render(){ return( <View style={styles.container}> <PhoneInput ref={(ref) => { this.phone = ref; }} onPressFlag={this.onPressFlag} />

        <CountryPicker
            ref={(ref) => { this.countryPicker = ref; }}
            onChange={(value)=> this.selectCountry(value)}
            translation='eng'
            cca2={this.state.cca2}
        >
            <View></View>
        </CountryPicker>
    </View>
)

} }

let styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', padding: 20, paddingTop: 60, }, });`

meliodev avatar Jan 23 '20 12:01 meliodev

I have the same issue. please, anyone has the solution?. thanks.

saidhappy010 avatar Jan 29 '20 12:01 saidhappy010

Please refer to this my friend. https://github.com/xcarpentier/react-native-country-picker-modal/issues/270#issuecomment-569040444

daviedgie avatar Feb 11 '20 03:02 daviedgie

I have the same issue. I am using this with expo application . Please anyone help. Its urgent.

Thanks in andvance

sargamverma avatar Jul 01 '20 16:07 sargamverma