Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

How to open new screen in with onPress in React Native?

$
0
0

I dont have any errors but I still cant open screen that I want. I find out and I think I need navigation but I dont know how to implement it. Here is my FlatList item:

let categories = [         {            screenName : Player,            name : "Category 1",            img : require("../Assets/Slika.jpg"),        },

Here is TouchableOpacity with onPress

return (<View style={styles.container}><FlatList            data={categories}            showsHorizontalScrollIndicator={false}            numColumns={categories.length / 5}            showsVerticalScrollIndicator={false}            keyExtractor={(item, index) => index.toString()}            renderItem = {({item, index}) => {                return (<TouchableOpacity onPress={() => item.screenName}><Surface style={styles.surface}><ImageBackground                    source={item.img}                     style={styles.img}                    blurRadius={0.5}><Icon name="music" color="#fff" size={22}/><Text style={styles.name}>{item.name}</Text></ImageBackground></Surface></TouchableOpacity>                );            }}        /></View>

Here is some code for function I get:

import { useNavigation } from '@react-navigation/native';...export default function ClassName() {const navigation = useNavigation();function navigateTO(pageName) { navigation.navigate(pageName);}<TouchableOpacity onPress={navigateTO(item.screenName})>

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>