react-navigation

Couldn't get param in my tabs

*爱你&永不变心* 提交于 2019-12-10 18:27:31
问题 I have Login and MAIN screen with 2 tabs...I'm passing user to MAIN screen with navigate('MAIN',{user: user} and I couldn't get that user in my MAIN with this.props.navigation.getParam('user'). My error is: undefined When I debug with : Reactotron.log(this.props); I'm getting undefined in my Main screen in constructor. My code in App.js where is routes const Routes = createStackNavigator( { Login: { screen: Login, navigationOptions: ({ navigation }) => ({ header: null, }), }, Main: { screen:

Set initial state from navigation props

二次信任 提交于 2019-12-10 17:39:32
问题 I am using React Navigation to route between screen. I have an initial screen which contains a FlatList , onclick of an item I route to a new screen while passing params like this. props.navigation.navigate('Details', { id: props.id, title: props.title }); In the Details screen I can receive it using the following code but how do I set the state considering it's a static function and I do not have access to this.setState() . static navigationOptions = ({navigation}) => { const {params} =

Using React Navigation, how can I force the drawer navigator to pop to the top of the stack?

允我心安 提交于 2019-12-10 17:29:16
问题 I'm using React Navigation and have a drawer navigator which contains several Stack Navigators as its items. When i open the drawer navigator and click on an item, it shows the first screen in the stack I clicked on. When I go to the second screen in the stack and then open the drawer and click on the same drawer link for the active stack, I want it to show the first screen of the stack, but instead it currently does nothing. How can I make that happen? Here's a snack which shows the issue:

React Native - Reset child stackNavigator to initial screen onPress of parent tabNavigator

不羁的心 提交于 2019-12-10 17:10:44
问题 I have a simple navigation structure set up with 4 primary screens that the user navigates between using react-navigation/TabNavigator. Within each of those primary screens the user can navigate to the secondary screen using react-navigation/StackNavigator. The secondary screen is the same component for all 4 primary screens, as the content is loaded dynamically depending on which is selected using redux to change the state of the content. You can see the structure in the diagram below. The

How to send data back to previous sceen when using navigation.goBack()?

时间秒杀一切 提交于 2019-12-10 16:16:26
问题 I've got screen 1 from which I navigate to screen 2 using: navigation.navigate('Screen2') From this screen, I would like to go to the previous one, which simple: navigation.goBack() However I'm wondering how can I pass some data back to Screen1? Something like wouldn't work navigation.goBack({ myData: 'something' }) so I'm wondering what is the recommended way to do this in general? 回答1: You can solve it with 2 ways : 1 : Using navigation method Pass a method when you are calling that screen

React Navigation Reset Can add parameters?

江枫思渺然 提交于 2019-12-10 16:09:21
问题 I am still new to react navigation. I wish to reset the route information after login successfully. However there is some parameters like login information I wish to pass to the main page. import { NavigationActions } from 'react-navigation' const resetAction = NavigationActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: 'Profile', params:{user:this.state.username}}) ] }) this.props.navigation.dispatch(resetAction) In the Profile page, I want to get access to the

How to update state from other component?

喜夏-厌秋 提交于 2019-12-10 15:03:54
问题 I am using react native and react navigation for routing. How to update state from another component/page? HomeScreen export class HomeScreen extends Component { constructor(){ this.state = { test: '' } } updateState = ()=>{ this.setState({test:'new value'}); } } SideMenuScreen import { HomeScreen } from "./home"; export class SideMenuScreen extends Component { updateHomeState = ()=>{ let oHome = new HomeScreen(); oHome.updateState(); } } My App.js and routing and sidemenu config as below :

React Navigator StackNavigator: goBack does not work when called twice from the same scene

帅比萌擦擦* 提交于 2019-12-10 14:55:46
问题 Let's assume I want to implement a file explorer with directory structure. I created a React Native component that lists files and directories of a specific folder. When I click on a folder, I expect to go inside the new folder and list its files and folders. Obviously, I am hoping to be able to use the same React component to render the different folders. I use StackNavigator. Here is my code Here is my attempt which does not work: import React, { Component } from 'react'; import {

React Native disable swiping StackNavigator in TabNavigator

社会主义新天地 提交于 2019-12-10 14:49:56
问题 I have TabNavigator with screens 1 and 2 and inside screen 1 I have StackNavigator with screens 1.1 and 1.2. I have enabled swiping and gestures. From root I can swipe tabs between 1 and 2. When I'm on screen 1 and I open screen 1.1 I still can swipe to screen 2 and this ability I need to disabled somehow when the 1.1 screen is open. I need it to work just like Instagram app (ios). When you are on home screen (1) you can swipe left to see Direct screen (2). When you open friends profile from

Reset the TabNavigator history with react navigation

泪湿孤枕 提交于 2019-12-10 14:36:28
问题 I have the following structure: const routeConfiguration = { Login: { screen: Login }, Home: { screen: TabBar }, }; const stackNavigatorConfiguration = { headerMode: 'screen', navigationOptions: { header: { visible: false } } }; export const RootNav = StackNavigator(routeConfiguration, stackNavigatorConfiguration); My TabBar where each Tab has it's own StackNavigator: const routeConfiguration = { TabOneNavigation: { screen: TabOneNavigation }, TabTwoNavigation: { screen: TabTwoNavigation },