thegamenicorus / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
394 stars 447 forks source link

getFlag returns number instead of image #109

Closed NxRoot closed 4 years ago

NxRoot commented 5 years ago

getFlag always returns a number how am i supposed to use that as an image?

console.log(this.input.getFlag("gb")) returns 79

<Image source={79} ????? how does this work

jaydenwindle commented 4 years ago

Hey @preto89! This is the expected behavior here. Since the flag images are loaded using require in resources/flags/index.js, the getFlag function returns the asset reference (which is a number). This is the same value that is returned by requireing the image directly.

this.input.getFlag("gb") === require('react-native-phone-input/lib/resources/flags/images/gb.png')

You should be able to pass this value directly to Image.source, or you can use resolveAssetSource if you need to access the uri, width, or height of the image. You can read more about how RN handles images in the docs.