0

I need to show a flag icon along with the text. I have all the image stored in assets folder. These are the codes that I have tried so far. I have stored the icon in a const and which I later think of calling. I want to show icon and lang horizontally with icon at left side.

const language = [
    { lang: "English", code: "en", icon: require(`../assets/us.png`) },
    { lang: "French", code: "fr", icon: require(`../assets/th.png`) },
    { lang: "Japanese", code: "jp", icon: require(`../assets/jp.png`) },
]

class App extends Component {
    onSelectLanguage = () => {
        return (
            language.map((data, i) => {
                return (
                    <View key={i} style={styles.dropDownView}>
                        <TouchableOpacity onPress={() => this.onSelectedLang(data)}>
                            <Text style={styles.dropDownText}><Image source="{data.icon}" />{data.lang}</Text>
                        </TouchableOpacity>
                    </View>
                )
            })
        )
    }
}
1
  • use source={data.icon} Commented Sep 6, 2018 at 5:30

1 Answer 1

1

Try this code:

const language = [
{ lang: "English", code: "en", icon: require(`../assets/us.png`) },
{ lang: "French", code: "fr", icon: require(`../assets/th.png`) },
{ lang: "Japanese", code: "jp", icon: require(`../assets/jp.png`) },

]

class App extends Component {
onSelectLanguage = () => {
    return (
        language.map((data, i) => {
            return (
                <View key={i} style={styles.dropDownView}>
                    <TouchableOpacity onPress={() => this.onSelectedLang(data)}>
                        <Text style={styles.dropDownText}><Image source={data.icon} />{data.lang}</Text>
                    </TouchableOpacity>
                </View>
            )
        })
    )
}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.