React native screen navigation is slow - react-native

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.

Related

Structure for nested navigation with react-native-navigation

I am currently building my first app using react-native and i am struggeling with the right structure for nested navigation using react-native-navigation .
My app should be navigatable using a Tab-bar. On every screen of that Tab-bar I might need to have a Stack navigation available.
App.js:
<NavigatonContainer>
<BottomTab.Navigator>
<BottomTab.Screen name="Screen1" component={Screen1}/>
<BottomTab.Screen name="Screen2" component={Screen2}/>
<BottomTab.Screen name="Screen3" component={Screen3}/>
<BottomTab.Navigator/>
<NavigationContainer/>
Now if i want to use a Stack navigation inside Screen1, what would be the best approach? My approach would be to move all content that should be display when the first Tab is active to a new screen called "Screen1Start" and then having following code on "Screen1".
Screen1.js:
<Stack.Navigator>
<Stack.Screen name="Screen1Start" component={Screen1Start}/>
<Stack.Screen name="Screen1Settings" component={Screen1Settings}/>
<Stack.Screen name="Screen1Details" component={Screen1Details}/>
</Stack.Navigator>
Is that the right thing to do? Are there better approaches to this? Thanks for your help!
You can have a stack inside of a stack and then navigate to each individually with navigation.navigate('name'). In the react navigation docs you can read more about navigating inside nested navigators here.
Pretty quick example would be:
function Home() {
return (
<Tab.Navigator>
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Messages" component={Messages} />
</Tab.Navigator>
);
}
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={{ headerShown: false }}
/>
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
</NavigationContainer>
);
}
Here you can see that Home is a stack of feed and messages and then you have individual screens for Profile and Settings. Like so you can have another stack instead of Profile or Settings binded by another navigator such as toptab or bottomtab.
The react navigation docs explain this very detailed and easy to understand. I would recommend you to read from start to finish so you have a deeper understanding of the navigation.

Render one component over another at a certain route with react-navigation

I have a stack navigator with react router, using #react-navigation/native-stack. My home screen is a map, and I have a few menu components:
export const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ headerShown: false }}
component={Home}
/>
<Stack.Screen
name="SignIn"
component={SignIn}
/>
</Stack.Navigator>
</NavigationContainer>
)
}
Home is the map component, and SignIn, as well as some other components, are menu components that take over the screen when navigated to, pushing Home out of the way, as expected.
I want to be able to 'navigate' to another component at a certain route, call it Overlay. When routed here, I want to show the home screen, with an Overlay component laid over the top of part of the Home component, while still maintaining interactivity with the part of the Home screen that is not covered. However, if I do this:
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
options={{ headerShown: false }}
component={Home}
/>
<Stack.Screen
name="Overlay"
component={Overlay}
/>
</Stack.Navigator>
Then the Home screen moves away, and is replaced by Overlay.
How can I show a component overlaid over the top of my Home screen when the user is routed to a certain route? This is something easily done with react-router, but I'm not sure if there is a parallel in react-navigation. Is react-navigation not the right approach for this? Is it better to conditionally render the Overlay component based on a state/redux variable?

gestureResponseDistance does not work in React Navigation

I'm trying to create a Sheets type modal in ReactNative, but I can't close the screen with a swipe gesture because gestureResponseDistance doesn't work.
The code looks like the following, but what is causing it to not work?
Example of not responding to any part of the screen
const Stack = createStackNavigator();
<NavigationContainer>
<Stack.Navigator screenOptions={globalScreenOptions}>
<Stack.Screen name="TestPage" component={TestPage} />
<Stack.Screen
name="Setting"
component={Setting}
options={{
...TransitionPresets.ModalPresentationIOS,
cardOverlayEnabled: true,
gestureEnabled: true,
gestureResponseDistance: {
vertical: 800,
},
}}
/>
</Stack.Navigator>
</NavigationContainer>;
Example of only one part of the upper part of the screen responding
const Stack = createStackNavigator();
<NavigationContainer>
<Stack.Navigator screenOptions={globalScreenOptions}>
<Stack.Screen name="TestPage" component={TestPage} />
<Stack.Screen
name="Setting"
component={Setting}
options={{
...TransitionPresets.ModalPresentationIOS,
cardOverlayEnabled: true,
gestureEnabled: true,
}}
/>
</Stack.Navigator>
</NavigationContainer>;
The code is somewhat abbreviated.
After trying various things, it seems that adding gestureResponseDistance makes it unresponsive, but how can I make it so that the modal closes no matter where I swipe on the screen?
I'm a foreigner and I'm using a translation, so the language may be a little strange, but I would appreciate it if you could tell me more about it.
vartion
"react": "17.0.1",
"#react-navigation/native": "^6.0.0",
"#react-navigation/stack": "^6.0.0",
The value of gestureResponseDistance is a number not an object
In your case it should be
gestureResponseDistance: 800

Navigate to subsequent screen React Navigation 6 / 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.

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?