react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

passProps not being passed when react-native-navigation used with redux

Open AnmolShrma opened this issue 7 years ago • 13 comments

Issue Description

passProps not being passed when react-native-navigation used with redux

Steps to Reproduce / Code Snippets / Screenshots

Navigation.push("FamilyStack", { component: { name: "com.radarx.FamilyFormScreen", passProps: { text: "Pushed screen" }, options: { topBar: { title: { text: "Pushed screen title" } } } } });

When I call the props I get Undefined as the error

Environment

  • React Native Navigation version: ^2.0.2641
  • React Native version: 0.57.5
  • Platform(s) (iOS, Android, or both?): Android
  • Device info (Simulator/Device? OS version? Debug/Release?): Device

AnmolShrma avatar Dec 06 '18 10:12 AnmolShrma

Uhmm, are you sure you aren't doing something incorrectly? It's working fine for me with RNN 2.2.0 and RN 0.57.7

ItsNoHax avatar Dec 06 '18 13:12 ItsNoHax

I am seeing same behaviour using Navigation.showOverlay, all props are undefined. Navigation.push is working properly at least for now. Haven't got everything migrated from v1 yet.

NirpE avatar Dec 09 '18 07:12 NirpE

This was working for me with rn v55 and navigation 2.0.2381, but it seems there is a regression with v57 and 2.2.0. I don't think this is connected with redux in any way. The easiest way to reproduce is to hook up to the registerCommandListener and issue a push, the passProps always comes undefined.

Navigation.events().registerCommandListener((name, params) => {
   console.log(params.layout.data.passProps) // always undefined
});

And:

Navigation.push(this.props.componentId, {
   component: {
     name: 'example.PushedScreen',
     passProps: {
       text: 'Will not pass this'
     }
   }
})

mkrawiec avatar Dec 09 '18 13:12 mkrawiec

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

stale[bot] avatar Jan 08 '19 13:01 stale[bot]

The problem with me was that I had more then one HOC on top of my ScreenComponent and had to manually do {...this.props} on my ScreenComponent. This can be probably avoided with the new context API. But anyway. I don't think it's a RNN bug.

thinklinux avatar Jan 18 '19 13:01 thinklinux

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

stale[bot] avatar Feb 17 '19 14:02 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Feb 24 '19 14:02 stale[bot]

Sorry, but is there a solution to this? I'm experiencing the same problem

krookten14 avatar Apr 06 '19 12:04 krookten14

I think you are not registering the screen correctly please check if you are calling this function to register the screens with redux.

Navigation.registerComponentWithRedux('com.app.ScreenName', ()=> ScreenName, Provider, store);

On Sat, 6 Apr 2019, 17:47 krookten14, [email protected] wrote:

Sorry, but is there a solution to this? I'm experiencing the same problem

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wix/react-native-navigation/issues/4406#issuecomment-480499556, or mute the thread https://github.com/notifications/unsubscribe-auth/AmOyICXpbRCoN5SNlJYNaoLDkN2WFxQjks5veJBHgaJpZM4ZGQsA .

AnmolShrma avatar Apr 06 '19 14:04 AnmolShrma

I think you are not registering the screen correctly please check if you are calling this function to register the screens with redux. Navigation.registerComponentWithRedux('com.app.ScreenName', ()=> ScreenName, Provider, store); … On Sat, 6 Apr 2019, 17:47 krookten14, @.***> wrote: Sorry, but is there a solution to this? I'm experiencing the same problem — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#4406 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AmOyICXpbRCoN5SNlJYNaoLDkN2WFxQjks5veJBHgaJpZM4ZGQsA .

Hello @AnmolShrma! Is that really how a component should be registered on the latest update? because I've followed their documentation and it noted that Navigation.registerComponentWithRedux() is deprecated and it should actually be like this now:

Navigation.registerComponent('example.ComponentName', () => () => 
  (
    <Provider store={store}>
      <ComponentName {...props}/>
    </Provider>
  ), () => ComponentName);

I've tried registering other components with this without putting any props and it works. But my real problem Is this...

FindPlace.js

...
    itemSlectedHandler = key => {
        const selPlace = this.props.places.find(place => {
            return place.key === key;
        });

        Navigation.push('route-builder.FindPlaceScreen', {
            component: {
                id: 'route-builder.PlaceDetailScreen',
                name: 'route-builder.PlaceDetailScreen',
                passProps: {
                    selectedPlace: selPlace
                },
                options: {
                    topBar: {
                        title: {
                            text: selPlace.name
                        }
                    }
                }
            }
        });

    };

    render() {
        console.log(this.props);
        return(
            <View>
                <PlaceList places={this.props.places} onItemSelected={this.itemSlectedHandler} /> 
            </View>

        );
    }
...

App.js

Navigation.registerComponent('route-builder.PlaceDetailScreen', () => () => 
  (
    <Provider store={store}>
      <PlaceDetailScreen />
    </Provider>
  ), () => PlaceDetailScreen);

PlaceDetail.js

import React, {Component} from 'react';
import { View, Image, Text, StyleSheet, TouchableOpacity} from 'react-native';
import {connect} from 'react-redux';

import Icon from 'react-native-vector-icons/Ionicons';
import {deletePlace} from '../../store/actions/index';
...
render() {
        console.log(this.props);
        return (
            <View style={styles.container}>
                <View>
                    <Image 
                    source={this.props.selectedPlace.image} 
                    style={styles.placeImage} />
                    <Text style={styles.placeName}>{this.props.selectedPlace.name}</Text>
                </View>
                <View>
                    <TouchableOpacity onPress={this.placeDeletedHandler}>
                        <View style={styles.deleteButton}>
                            <Icon size={30} name="ios-trash" color="red" />
                        </View>
                    </TouchableOpacity>
                </View>
            </View>
        );
    };
...

const mapDispatchToProps = dispatch => {
    return {
        onDeletePlace: (key) => dispatch(deletePlace(key))
    };
};

export default connect(null, mapDispatchToProps)(PlaceDetail);

I've run this without redux and it worked, but when I tried adding redux, it only got the onDeletePlace as props and didn't really get the passProps when navigation pushed the screen to the component.

I hope this would be understandable enough, I just want some help. Thank you good people!

krookten14 avatar Apr 06 '19 16:04 krookten14

Please try this code in app.js

Navigation.registerComponent('route-builder.PlaceDetailScreen', () => (props) => ( <PlaceDetailScreen {...props} /> ), () => PlaceDetailScreen);

On Sat, 6 Apr 2019, 21:34 krookten14, [email protected] wrote:

I think you are not registering the screen correctly please check if you are calling this function to register the screens with redux. Navigation.registerComponentWithRedux('com.app.ScreenName', ()=> ScreenName, Provider, store); … <#m_-8031309654983481754_> On Sat, 6 Apr 2019, 17:47 krookten14, @.***> wrote: Sorry, but is there a solution to this? I'm experiencing the same problem — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#4406 (comment) https://github.com/wix/react-native-navigation/issues/4406#issuecomment-480499556>, or mute the thread https://github.com/notifications/unsubscribe-auth/AmOyICXpbRCoN5SNlJYNaoLDkN2WFxQjks5veJBHgaJpZM4ZGQsA .

Hello @AnmolShrma https://github.com/AnmolShrma! Is that really how a component should be registered on the latest update? because I've followed their documentation and it noted that Navigation.registerComponentWithRedux() is deprecated and it should actually be like this now:

Navigation.registerComponent('example.ComponentName', () => () => ( <ComponentName {...props}/> ), () => ComponentName);

I've tried registering other components with this without putting any props and it works. My real problem is when Is this...

FindPlace.js ` ... itemSlectedHandler = key => { const selPlace = this.props.places.find(place => { return place.key === key; });

Navigation.push('route-builder.FindPlaceScreen', {

    component: {

        id: 'route-builder.PlaceDetailScreen',

        name: 'route-builder.PlaceDetailScreen',

        passProps: {

            selectedPlace: selPlace

        },

        options: {

            topBar: {

                title: {

                    text: selPlace.name

                }

            }

        }

    }

});

};

render() {

console.log(this.props);

return(

    <View>

        <PlaceList places={this.props.places} onItemSelected={this.itemSlectedHandler} />

    </View>



);

}

... `

App.js Navigation.registerComponent('route-builder.PlaceDetailScreen', () => () => ( ), () => PlaceDetailScreen);

PlaceDetail.js ` import React, {Component} from 'react'; import { View, Image, Text, StyleSheet, TouchableOpacity} from 'react-native'; import {connect} from 'react-redux';

import Icon from 'react-native-vector-icons/Ionicons'; import {deletePlace} from '../../store/actions/index'; ... render() { console.log(this.props); return (

{this.props.selectedPlace.name}

); }; ...

const mapDispatchToProps = dispatch => { return { onDeletePlace: (key) => dispatch(deletePlace(key)) }; };

export default connect(null, mapDispatchToProps)(PlaceDetail); `

I've run this without redux and it worked, but when I tried adding redux, it only got the onDeletePlace as props and didn't really get the passProps when navigation pushed the screen to the component.

I hope this would be understandable enough, I just want some help. Thank you good people!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wix/react-native-navigation/issues/4406#issuecomment-480515609, or mute the thread https://github.com/notifications/unsubscribe-auth/AmOyINC8nTMcuTNgdnxFb2oY57u5FrXQks5veMWCgaJpZM4ZGQsA .

AnmolShrma avatar Apr 06 '19 16:04 AnmolShrma

@AnmolShrma omfg, it worked! thank you. Not all heroes wear capes.

krookten14 avatar Apr 08 '19 03:04 krookten14

I have a similar problem on Android. Initially, when I do a Navigation.setRoot() the mounted screens get the props that are passed to them.

Later on when a user actions triggers an app-reinit, I call the same setup function, which invokes the same Navigation.setRoot() again but this time, the HomeScreen won't receive any passed props.

I register the screen using this code:

  Navigation.registerComponentWithRedux(
    ScreenNames.HomeScreen,
    () => HomeScreen,
    Provider,
    store
  )

It works fine on iOS but I have the problem on Android 7.0 and 5.1, tested with both RNN 2.19 and 2.22.3

Here's my setup:

 await Navigation.setRoot({
      root: {
        bottomTabs: {
          children: [
            {
              stack: {
                children: [
                  {
                    component: {
                      id: ScreenNames.HomeScreen,
                      name: ScreenNames.HomeScreen,
                      passProps: homeScreenNavigationProps,
                      options: {
                        bottomTab: {
                          ...defaultTabOptions,
                          icon: require('../../../assets/icons/navigation/calendar.png'),
                          text: translate('topNavigation.home'),
                        },
                      },
                    },
                  },
                ],
              },
            },
          ],
          options: {
            bottomTabs: {
              currentTabIndex: DEFAULT_TAB,
              titleDisplayMode: 'alwaysShow',
              backgroundColor: colors.navigationBackground,
            },
          },
        },
      },
    })
  }
}

Here's the props I pass

export const homeScreenNavigationProps: HomeScreenNavigationProps = {
  onSelectMatch: (match: MatchListItem) =>
    Navigation.push(ScreenNames.HomeScreen, {
      component: {
        name: ScreenNames.MatchScreen,
        id: ScreenNames.MatchScreen,
        passProps: matchScreenNavigationProps(match),
      },
    }),
  onSelectSearch: () => showSearchOverlay({}),
}

esbenvb avatar Jul 05 '19 13:07 esbenvb