i try to make an app on react-native for the first time and I have a problem.
I code a component who show a screen with some text and a button but they didn't shown on the app and I don't know why.
I code on snack.expo.dev, i'm new on this but i try to learn a lot about that informatic language.
import * as React from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import { StartScreen } from "./routes/Start_page";
function HomeScreen() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
/*const StartScreen = () => {
return(
<View>
<Text>(Screen 1)</Text>
<Text>Welcome to My App</Text>
<Button
title="Start!"
onPress={() => {}}
>
</Button>
</View>
);
}*/
const DashboardScreen = () => {
return(
<View>
<Text>(Screen 2)</Text>
<Text>Dashboard</Text>
<Button
title="Back"
onPress={() => {}}
>
</Button>
</View>
);
}
const Stack = createNativeStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={"Start"}>
<Stack.Screen name="Start" component={StartScreen} />
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Dashboard" component={DashboardScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
/*const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});*/
import * as React from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
const StartScreen = () => {
return(
<View>
<Text>(Screen 1)</Text>
<Text>Welcome to My App</Text>
<Button
title="Start!"
onPress={() => {}}
>
</Button>
</View>
);
}
I try to add more text to post xD
You just forgot to export the const StartScreen in the file ./routes/Start_page/index.tsx. It will be like this:
import * as React from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
export const StartScreen = () => {
return(
<View>
<Text>(Screen 1)</Text>
<Text>Welcome to My App</Text>
<Button
title="Start!"
onPress={() => {}}
>
</Button>
</View>
);
}
Related
App.js
import React from'react';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator, Header } from '#react-navigation/stack';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import Todo from './Todo';
import Done from './Done';
import Entrypage from './Entrypage';
import Addtask from './Addtask';
import Fontawesome5 from 'react-native-vector-icons/FontAwesome5';
import { StatusBar } from 'react-native';
const Tab = createBottomTabNavigator();
const Hometabs = () => {
return(
<NavigationContainer
independent={true}
>
<Tab.Navigator
screenOptions={({route})=>({
tabBarActiveTintColor:('#4682b4'),
tabBarLabelStyle:{fontSize:13,fontWeight:'bold'},
tabBarIcon:({focused,size,color,}) =>{
let iconname;
if(route.name==='To-do'){
iconname='clipboard-list';
color=focused? '#383':'#555';
size=focused? 26 : 25;
}else if(route.name==='Done'){
iconname='clipboard-check';
color=focused? '#383':'#555';
size=focused? 26 : 25;
}
return(
<Fontawesome5
name={iconname}
color={color}
size={size}
/>
)
}
})}
>
<Tab.Screen
name="To-do"
component={Todo}
options={{header:() => null}}
/>
<Tab.Screen
name="Done"
component={Done}
options={{header:() => null}}
/>
</Tab.Navigator>
</NavigationContainer>
)
}
const RootStack = createStackNavigator();
const App = () =>{
return(
<NavigationContainer>
<RootStack.Navigator
initialRouteName="Entry"
>
<RootStack.Screen
name="Entry"
component={Entrypage}
options={{
header:() => null
}}
/>
<RootStack.Screen
name="Tasks"
component={Hometabs}
options={{headerStyle:{backgroundColor:'#4682b4'},
headerTintColor:'#fff',
headerTitleAlign:'center',
}}
/>
<RootStack.Screen
name="AddTask"
component={Addtask}
/>
</RootStack.Navigator>
</NavigationContainer>
)
}
export default App;
Entrypage:
import React, { useEffect } from 'react';
import{
View,
Text,
Image,
StyleSheet,
StatusBar,
}from 'react-native';
export default function Enrtypage({navigation}) {
useEffect(()=>{
setTimeout(()=>{
navigation.replace('Tasks');
},2000);
},[]);
return(
<View style={styles.body}>
<StatusBar
backgroundColor={'#4682b4'}
/>
<Image
style={styles.logo}
source={require('../assests/write.png')}
/>
<Text style={styles.Text}>
To-Do List
</Text>
</View>
)
}
const styles = StyleSheet.create({
body:{
flex:1,
backgroundColor:'#4682b4',
alignItems:'center',
justifyContent:'center',
},
Text:{
fontSize: 35,
fontWeight:'900',
margin:15,
color:'#fff'
},
logo:{
height:150,
width: 150,
},
})
Todo:
import React from 'react';
import{
View,
Text,
StyleSheet,
TouchableOpacity,
Button,
}from 'react-native';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
export default function Todo ({navigation}) {
return(
<View style={styles.body}>
<TouchableOpacity style={styles.button}
onPress={()=>{
navigation.navigate('AddTask');
}}
>
<FontAwesome5
name='pen'
color='#fff'
size={23}
/>
</TouchableOpacity>
</View>
)
}
const styles = StyleSheet.create({
body:{
flex:1,
},
text:{
color:'#000',
},
button:{
width:60,
height:60,
backgroundColor:'#4682b4',
borderRadius: 50,
borderColor:'#000',
justifyContent:'center',
alignItems:'center',
position:'absolute',
bottom:20,
right: 20,
},
})
Done:
import React from 'react';
import{
View,
Text,
StyleSheet,
}from 'react-native';
export default function Done () {
return(
<View style={styles.body}>
<Text style={styles.text}>
Done
</Text>
</View>
)
}
const styles = StyleSheet.create({
body:{
flex:1,
},
text:{
color:'#000',
}
})
Addtask:
import React from 'react';
import{
View,
StyleSheet,
} from 'react-native';
import { TextInput } from 'react-native-gesture-handler';
export default function Addtask () {
return(
<View>
<TextInput/>
</View>
)
}
const style=StyleSheet.create({
body:{
flex:1,
},
})
The Button in Todo is not navigating to Addtask page.
I have a signup page with 4 steps (4 separate screens). On the first page, the user enters their username in a field, on the second page a display name, on the third their birthday, and on the fourth their password.
Here's my current signup screen file:
import React from 'react';
import { View, Text, Button } from 'react-native';
const SignupScreen = () => {
return (
<View>
<Text>First step</Text>
<Button
title="Next step"
/>
</View>
);
}
export default SignupScreen;
But I'm a bit confused as to how to present the next screen when the user taps the Button. How do I create a Stack here? Or would I do it in the App.js file?
Here is my App.js:
import { StatusBar } from 'expo-status-bar';
import { FlatList, StyleSheet, Text, View, TouchableHighlight } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import {
RootStack,
TabsStack,
SignupStack
} from './navigation/navigation';
export default function App() {
return (
<NavigationContainer>
<RootStack.Navigator>
<RootStack.Screen
name="Tabs"
options={{ headerShown: false }}
component={TabsStack}
/>
<RootStack.Screen
name="SignupStack"
options={{ headerShown: false }}
component={SignupStack}
/>
</RootStack.Navigator>
</NavigationContainer>
);
}
And here is my navigation.js file:
import React from 'react';
import { FlatList, StyleSheet, Text, View, TouchableHighlight } from 'react-native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import SignupScreen from '../screens/SignupScreen';
export const RootStack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const SignupNav = createNativeStackNavigator();
export const TabsStack = () => (
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="History" component={SecondScreen} />
<Tab.Screen name="Third" component={ThirdScreen} />
<Tab.Screen name="Fourth" component={FourthScreen} />
</Tab.Navigator>
);
export const SignupStack = () => (
<SignupNav.Navigator>
<SignupNav.Screen
name="Signup"
component={SignupScreen}
options={{ headerTitle: 'Sign up' }}
/>
</SignupNav.Navigator>
);
function HomeScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home</Text>
</View>
);
}
function SecondScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Second</Text>
</View>
);
}
function ThirdScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Third</Text>
</View>
);
}
function FourthScreen({ navigation }) {
function onPressButton() {
navigation.navigate('SignupStack');
}
return (
<View>
<FlatList
data={[
{key: 'Signup'},
]}
renderItem={({item}) => <TouchableHighlight onPress={onPressButton} underlayColor="white"><Text>{item.key}</Text></TouchableHighlight>}
/>
</View>
);
}
What's the correct way of doing this?
Thank you
the best way that i know, make all the screen as component and import it in the signup screen
signup.js
/*
import all you component(pages) here...
*/
const [screen, setScreen] = useState(1)
{screen == 1 ? (
<ScreenOne
onNext={()=>setScreen(2)}
/>
) : screen == 2 ? (
<ScreenTwo
onNext={()=>setScreen(3)}
/>
) : screen == 3 ? (
<ScreenThree
onNext={()=>setScreen(4)}
/>
)
}
You can pass all your state and callback function from signup page to all the component get value from the component
The code is working in web version of react native but not in expo The array values are showing unefined but they are working fine in web version.Please tell me what is wrong here
import { View, Text, StyleSheet } from "react-native"
import React from "react"
import { FontAwesomeIcon } from "#fortawesome/react-native-fontawesome"
import { faEdit, faMinusSquare } from "#fortawesome/free-regular-svg-icons"
function List({ todoArr, handleModalOpen, removeItem }) {
console.log(todoArr)
return (
<>
{todoArr.map((item, index) => {
console.log(index)
return (
<View>
<Text key={item} style={styles.item}>{item}</Text>
<Text onPress={() => handleModalOpen(index, item)}>
<FontAwesomeIcon icon={faEdit} />
</Text>
<Text onPress={() => removeItem(index)}>
<FontAwesomeIcon icon={faMinusSquare} />
</Text>
</View>
)
})}
</>
)
}
const styles = StyleSheet.create({
item: {
fontSize: 20
},
})
export default List
import { ScrollView, StyleSheet, Text, View } from 'react-native';
import Buttons from './components/Add and Del Btn';
import EditModal from './components/EditModal';
import Heading from './components/Heading';
import Input from './components/Input';
import List from './components/List';
import Todo from './todo';
export default function App() {
let [indexNo , inpVal,updInpVal , todoArr,modalVisible ,setUpdInpVal , getInp, add, delAll, removeItem, editItem , handleModalClose , handleModalOpen] = Todo();
return (
<View style={styles.container}>
<EditModal modalVisible = {modalVisible} updInpVal={updInpVal} setUpdInpVal = {setUpdInpVal} editItem = {editItem} indexNo = {indexNo}/>
<View>
<Heading />
<View>
<Input getInp={getInp} inpVal={inpVal} />
<Buttons add={add} delAll={delAll} />
</View>
<View>
<List todoArr={todoArr} handleModalOpen={handleModalOpen} removeItem={removeItem} />
</View>
</View>
</View >
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
I'm korean. and Im not good at english. please understand about this.
i want if i push the button, move the page.
but
got an invalid value for 'component' prop for the screen
this error keep appear in StyleScreen.
I'm defintly beginner, so if you upload full code, I'm so appreciate that.
this is my App.js code:
import * as React from 'react';
import { useState } from 'react';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import MainScreen from './MainScreen';
import DetailScreen from './DetailScreen';
import StyleScreen from './StyleScreen';
const Stack = createStackNavigator();
const App = () => {
const [overlay, setOverlay] = useState(false);
const toggleOverlay = () => {
setOverlay(!overlay);
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="MAIN">
<Stack.Screen name="MAIN" component={MainScreen}
options={{
title: '예산'
}}/>
<Stack.Screen name="DETAIL" component={DetailScreen}
options={{
title: '색'
}}/>
<Stack.Screen name="STYLE" component={StyleScreen}
options={{
title: '스타일'
}}/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
this is StyleScreen.js :
import React, { Component } from 'react';
import { useState } from 'react';
import { StatusBar } from 'expo-status-bar';
import { Button, StyleSheet, Text, Dimensions, View, ScrollView, Image, navigation } from 'react-native';
let natural = require('./내추럴.png');
let modern = require('./모던.jpg');
let romantic = require('./로맨틱.jpg');
let NEurope = require('./북유럽.png');
let junk = require('./정크4.jpg');
let minimal = require('./미니멀.jpg');
const HomeScreen=({navigation}) => {
return (
<View style={styles.container}>
<StatusBar style="block"></StatusBar>
<View style={styles.ask1}>
<Text style={styles.askcolor}>선호하는 스타일을</Text>
<Text style={styles.askcolor}>선택해주세요</Text>
</View>
<View style={styles.day2}>
<View style={styles.day}>
<Image style={styles.image} source={modern}/>
<Image style={styles.image2} source={NEurope}/>
</View>
<View style={styles.day}>
<Text style={styles.colorname}> 모던</Text>
<Text style={styles.colorname}> 북유럽</Text>
</View>
<View style={styles.day}>
<Image style={styles.image} source={minimal}/>
<Image style={styles.image2} source={natural}/>
</View>
<View style={styles.day}>
<Text style={styles.colorname}> 미니멀</Text>
<Text style={styles.colorname}> 내추럴</Text>
</View>
<View style={styles.day}>
<Image style={styles.image} source={romantic}/>
<Image style={styles.image2} source={junk}/>
</View>
<View style={styles.day}>
<Text style={styles.colorname}> 로맨틱</Text>
<Text style={styles.colorname}> 정크</Text>
</View>
</View>
<View style={styles.button}>
<Button onPress={() => navigation.navigate('DETAIL')} title='다음으로'/>
</View>
</View>
);
}
const styles = StyleSheet.create({
container:{
flex:1,
backgroundColor:"white"
},
ask1:{
flex:0.3,
justifyContent:"center",
marginTop:70,
marginBottom:40,
},
askcolor:{
fontSize:34,
fontWeight:"900",
paddingHorizontal:30,
},
image:{
height: 130,
width: 158,
borderRadius:10,
backgroundColor:"black"
},
image2:{
height: 130,
width: 158 ,
borderRadius:10,
marginLeft:28,
},
day:{
flexDirection: 'row',
},
day2:{
flex:3,
paddingHorizontal:30,
},
colorname:{
fontSize:17,
fontWeight:"300",
paddingHorizontal:23,
paddingVertical:13,
},
button:{
flex:0.43,
marginLeft:286,
}
})
i think you have not exported your styleScreen component, that might be the issue here and also your "StyleScreen" component is named "HomeScreen" so I would suggest rename is properly and export it by default.
In StyleScreen component, you have imported "navigation" from "react-native" which I think is not correct.
You didn't export StyleScreen component.
Add this at bottom line of your StyleScreen.js.
export default StyleScreen;
try to replace code
const HomeScreen=({navigation}) => {
with
export default StyleScreen =({navigation}) => {
Okay so I'm just jumping into React Native and I'm going through the docs with the react-navigation package. Whenever a screen is pushed onto the stack, the animation goes from right-left by default—Also I'm noticing the back button is on the right side of the appbar instead of the left be default. Is this by design or have I set something up incorrectly?
Also ignore the FC I'm using, I know it's not recommended but I'm just getting a feel for RN 😅
See image and code below:
import { StatusBar } from "expo-status-bar";
import { Button, StyleSheet, Text, View } from "react-native";
import { createNativeStackNavigator } from "#react-navigation/native-stack";
import { BaseNavigationContainer } from "#react-navigation/native";
import { FC } from "react";
import { StackScreenProps } from "./Types";
const Home: FC<StackScreenProps> = ({ navigation }) => {
return (
<View style={styles.container}>
<Text>Hello World </Text>
<Button
title="Switch Page"
onPress={() => {
navigation.navigate("About");
}}
/>
</View>
);
};
const About: FC<StackScreenProps> = ({ navigation }) => {
return (
<View style={styles.container}>
<Text>Learn the Process First</Text>
<Button title="Go Back" onPress={() => navigation.goBack()} />
</View>
);
};
const Stack = createNativeStackNavigator();
export default function App() {
return (
<BaseNavigationContainer>
{/* #ts-ignore */}
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="About" component={About} />
</Stack.Navigator>
</BaseNavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});