react-native-flags
react-native-flags copied to clipboard
How could a click event be implemented for the Flag?
I tried to achieve this too, but got errors when I just wrapped the Flag component inside TouchableOpacity to attach onPress event handler. The easiest but little bit dirty solution I came up with is just omit the Flag component and build your own:
import * as allFlags from 'react-native-flags/flags/flat/64'
...
<TouchableOpacity onPress={() => console.log(countryCode)}>
<Image source={allFlags[countryCode] || allFlags.unknown} style={{ width: 64, height: 64 }} />
</TouchableOpacity>
I just submitted PR to support onPress event in the Flag component https://github.com/frostney/react-native-flags/pull/5
Thank you for the proposal, I was able to implement it in the meantime:
<TouchableOpacity onPress={this.onFlagClick.bind(this, 'de')}>
<Flag style={styles.flagToolbar} code="DE" size={48} />
</TouchableOpacity>
But I like your way too and probably will switch to it