Stack navigation and navigator

 app.js

import React from 'react';
import {View, Text, StyleSheet, Pressable} from 'react-native';
import {createStackNavigator} from '@react-navigation/stack';
import {NavigationContainer} from '@react-navigation/native';
import ScreenA from './Components/ScreenA';
import ScreenB from './Components/ScreenB';

const Stack = createStackNavigator();

// const ScreenA = ({navigation}) => {
//   return (
//     <View style={Styles.container}>
//       <Text style={Styles.txt}>ScreenA</Text>
//       <Pressable style={({pressed})=>({backgroundColor:pressed ?'#ffffffff':'#ff5',
//       borderWidth:5,borderRadius:30})}
//       onPress={()=>navigation.navigate('ScreenB')}>
//         <Text style={Styles.txt}>Go To ScreenB</Text>
//       </Pressable>
//     </View>
//   );
// };
// const ScreenB = () => {
//   return (
//     <View style={Styles.container}>
//       <Text style={Styles.txt}>ScreenB</Text>
//     </View>
//   );
// };

const App = () => {
  return (
    <NavigationContainer>
      <Stack.Navigator screenOptions={{header:()=>null}}>
        <Stack.Screen
          name="ScreenA"
          component={ScreenA}
          options={{header: () => null}}
        />
        <Stack.Screen
          name="ScreenB"
          component={ScreenB}

        />
      </Stack.Navigator>
    </NavigationContainer>
  );
};

const Styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  txt: {
    fontSize: 50,
    marginBottom: 20,
  },
});
export default App;
************************************************
screenA
index.js
import React from 'react'
import { View, Text,Pressable } from 'react-native'
import Styles from './style';
const ScreenA = ({navigation}) => {
    const onPressHandler =()=>{
      navigation.navigate('ScreenB')
    }
    return (
      <View style={Styles.container}>
        <Text style={Styles.txt}>ScreenA</Text>
        <Pressable style={({pressed})=>({backgroundColor:pressed ?'#ffffffff':'#ff5',
        borderWidth:5,borderRadius:30})}
        onPress={onPressHandler}>
          <Text style={Styles.txt}>Go To ScreenB</Text>
        </Pressable>
      </View>
    );
  };

export default ScreenA
screenA
styles.js
import { StyleSheet } from "react-native";

const Styles = StyleSheet.create({
    container: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center',
    },
    txt: {
      fontSize: 50,
      marginBottom: 20,
    },
  });
  export default Styles;
*******************************************************
screenB
index.js
import React from 'react';
import { View, Text, Pressable } from 'react-native';
import Styles from './styles';
const ScreenB = ({ navigation }) => {
    const onPressHandler2 =()=> {
        navigation.navigate('ScreenA')
    }
    return (
        <View style={Styles.container}>
            <Text style={Styles.txt}>ScreenB</Text>
            <Pressable
                style={({ pressed }) => ({
                    backgroundColor: pressed ? '#ffffffff' : '#ff5',
                    borderWidth: 5,
                    borderRadius: 30,
                })} onPress={onPressHandler2}>
                <Text style={Styles.txt}>Go To ScreenA</Text>
            </Pressable>
        </View>
    );
};

export default ScreenB;

screenB
styles.js
import { StyleSheet } from "react-native";

const Styles = StyleSheet.create({
    container: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center',
    },
    txt: {
      fontSize: 50,
      marginBottom: 20,
    },
  });
  export default Styles;
**********************************************
pkg.json

  "dependencies": {
    "@react-native-masked-view/masked-view": "^0.2.6",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/stack": "^6.0.7",
    "react": "17.0.2",
    "react-native": "0.65.1",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "^3.7.2"
  },

Comments

Popular posts from this blog

Privacy Policy for Live Weather Forecast - Realtime app

NFC Checker App Privacy Policy

FlatList