Navigate to subsequent screen React Navigation 6 / React Native - react-native

Can anyone tell me what I’m doing wrong with the below:
"#react-navigation/native": "^6.0.6",
"#react-navigation/native-stack": "^6.2.5",
"#react-navigation/stack": "^6.0.11",
I’ve got this in App.js (trimmed down of course):
const Stack = createStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
/>
<Stack.Screen
name="Groups"
component={Groups}
/>
<Stack.Screen
name="Group Detail"
component={GroupDetail}
/>
</Stack.Navigator>
</NavigationContainer>
}
Now, when I go from Home to Groups and then try to call navigation.navigate("GroupDetail");
I get this error:
The action 'NAVIGATE' with payload {"name":"GroupDetail"} was not handled by any navigator.
Do you have a screen named 'GroupDetail'?
Of course, I do have that screen and have checked the imports.
What am I missing here? I need to just push from Home, to Groups then to Group Detail.
I’ve tried the Nested Navigator documentation, but I think think it applies here (didn’t work anyway).

I had the name wrong.
Instead of Group Detail, it needed to be GroupDetail.

Related

React Navigation 6.x Initial Route Not Working

I'm using React Navigation 6.x's linking with Expo so that when a user clicks on a notification they are directed to the appropriate part of my application to interact with the new information. When my app is backgrounded (running in the background) and a user clicks on a notification they are redirected to the screen they need to be at, which works perfectly fine. However, when the app is killed and the user clicks on a notification, they are taken directly to the screen for which the url is provided and they cannot press back to navigate elsewhere in my application. I tried to resolve this by using the initialRouteName prop like is shown in the docs (link: https://reactnavigation.org/docs/configuring-links/#rendering-an-initial-route), but I cannot get it to work. For further clarification, when I mentioned above that I am able to get linking working it is in relation to the direct SettingsScreen, AddFriendScreen, and MessagingScreen links. What I cannot get working is the specific block of code inside the liking object that starts with HomeScreen. What I believe may be causing the issue is that I am trying to set my initialRoute as a screen within HomeScreen's Tabs.Navigator and then trying to route to a screen within my Stack.Navigator. However, the docs show that this is possible (link: https://reactnavigation.org/docs/configuring-links/#rendering-an-initial-route).
My code:
const linking = {
prefixes: [prefix],
config: {
screens: {
HomeScreen: {
initialRouteName: "Chats",
screens: {
AddFriendScreen: "addFriend",
CreateChatScreen: "createChatScreen",
Friends: "friends",
MessagingScreen: 'messagingScreen/:chatRoomId'
}
},
SettingsScreen: "SettingsScreen",
AddFriendScreen: "AddFriendScreen",
MessagingScreen: 'MessagingScreen/:chatRoomId'
},
}
};
<NavigationContainer linking={linking} theme={MyTheme} >
<Stack.Navigator>
{!authState.value ?
<>
<Stack.Screen name="LoginScreen" component={LoginScreen} />
<Stack.Screen name="SignUpScreen" component={SignUpScreen} />
<Stack.Screen name="ForgotPasswordScreen" component={ForgotPasswordScreen} />
</>
:
<>
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen name="MessagingScreen" component={MessagingScreen} />
<Stack.Screen name="SettingsScreen" component={SettingsScreen} />
<Stack.Screen name="CreateChatScreen" component={CreateChatScreen} />
<Stack.Screen name="AddFriendScreen" component={AddFriendScreen} />
</>
}
</Stack.Navigator>
</NavigationContainer>
const HomeScreen = () => {
return (
<Tabs.Navigator>
<Tabs.Screen name="Chats" component={ChatScreen} />
<Tabs.Screen name="Friends" component={FriendsScreen} />
<Tabs.Screen name="Profile" component={ProfileScreen} />
</Tabs.Navigator>
)
}
Hmm, I would put any screen that I would like to access in multiple navigators at the root level so that they can both reach it.
For my own project, I have a root stack with a dedicated auth stack and an app/home stack (which is a tab nav like your HomeScreen). And outside that I have all my modal and root screens that I'd like other navigators to access (Because I really have two Home tab navigators the user can switch between.)
Idk if putting all of your screens listed after HomeScreen outside of that object will help your situation, but you can try that.

React Native Navigation: Another Navigator is already registered for this container

I want my component to render a TopTab Navigator on the top and also a Drawer Navigator at the same time.
So something like
<TopTab.Navigator>
<TopTab.Screen />
</TopTab.Navigator>
<Drawer.Navigator>
<Drawer.Screen />
</Drawer.Navigator>
However I'm getting an error of "Another navigator is already registered for this container. You likely have multiple navigators under a single "NavigationContainer" or "Screen" Make sure each navigator is under a separate "ScreenContainer"
Why dont you try using it like this, drawerNavigator holds as the main wrapper and inside it topTab
const HomeScreen = () => {
return(
<TopTab.Navigator>
<TopTab.Screen />
</TopTab.Navigator>
)
}
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
</Drawer.Navigator>
</NavigationContainer>
)
}
This should work, feel free for doubts
You have to set Tab navigator inside drawer navigator, you can search to get better solutions like "how we use multiple navigator in react native?"
visit below link
https://dev.to/easybuoy/combining-stack-tab-drawer-navigations-in-react-native-with-react-navigation-5-da

How to make a stack navigator cover entire screen using React Navigation

I am building a React Native project with Expo. For navigation, I am using react-navigation 6.0 with the following code for my main component:
export default class App extends Component {
render() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={'SignIn'} screenOptions={{
headerShown: false
}}>
<Stack.Screen name="SignIn" component={SigninScr} />
<Stack.Screen name="SignUp" component={SignupScr} />
<Stack.Screen name="EmailVerification" component={EmailVerificationScr} />
</Stack.Navigator>
</NavigationContainer>
);
}
}
This works fine, but I haven't been able to make Stack.Navigator cover the entire screen. There is a weird area that's not covered by the Stack.Navigator:
I was reading through some of the documentation about stack navigator, but couldn't find any props or styling to force it to cover 100% of the screen. Does anyone know how to accomplish this?

Linking different screens in React Native

I wanted to open different screen if pressed the text. But unfortunately I don't understand this docs. Is there any other different option, like 'a href' in html? Or could anyone explain this to me?
Install react-navigation
Make edits to App.js
Wrap all of the JSX of App.js in a NavigationContainer with a Stack.Navigator nested under it
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
const Stack = createStackNavigator();
return (
<NavigationContainer>
<Stack.Navigator>
{Your Screens}
</Stack.Navigator>
</NavigationContainer>
);
Now we set up screens. Each screen will use the StackScreen component and needs a screen name and the screen component itself
<Stack.Screen
name="Home"
component={HomeScreen}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
/>
With this completed, each screen will now have a navigation prop. In the screen where you have your text button set your onPress to something like this:
<Button
title="Navigate to Home"
onPress={()=>props.navigation.navigate("Home")
/>
navigation.navigate identifies the screen you're trying to get to by using the name you provided in App.js Stack.Screen

React native screen navigation is slow

I using react navigation with functional components and i am facing a issue that screen when move from one screen to another. it is taking 1-2 seconds. Users are able to observe that something is loading. I am using
"#react-navigation/bottom-tabs": "^5.8.0",
"#react-navigation/native": "^5.7.1",
"#react-navigation/stack": "^5.7.1",
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name='HomeScreen' component={HomeScreen} options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
HomeScreen
<Tab.Navigator>
Some tabs
</Tab.Navigator>
So i am not able to know what is problem. i found some solution with Interaction manager. So please provide me a answer how can i do this in the functional components and increase navigation speed.