react-native-flags icon indicating copy to clipboard operation
react-native-flags copied to clipboard

How could a click event be implemented for the Flag?

Open DenisTis opened this issue 8 years ago • 3 comments

DenisTis avatar Nov 26 '17 11:11 DenisTis

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>

Buthrakaur avatar Nov 29 '17 08:11 Buthrakaur

I just submitted PR to support onPress event in the Flag component https://github.com/frostney/react-native-flags/pull/5

Buthrakaur avatar Nov 29 '17 09:11 Buthrakaur

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

DenisTis avatar Nov 30 '17 12:11 DenisTis