React-native-navigation: Get the name of the current screen?

Created on 6 Apr 2017  路  15Comments  路  Source: wix/react-native-navigation

Hi

From within a screen/component. Is there a way, I can fetch the "name" of the screen. Maybe from the navigator prop ?

this.props.navigator.getScreen()

馃彋 stale

Most helpful comment

I'm thinking about adding something like that in a future version

All 15 comments

You mean the identifier that you use when registering a screen? What is the use case for this? :D

Yes, exactly. The identifier.

Well :) Little tough to explain. So I want to maintain a configuration/list of which screen comes after which. And from within a screen I'd like to just call a function that returns the next screen. That function needs to take the current screen identifier as an option.

Hey @prakashraman ,
have you get the solution for this?? I am also in same issue.
Please let me know how you solve this.

Thanks.

Hey @sourabhkheterpal no, I did not unfortunately. Although, what I did do is
I created a static variable in each component/screen/class called "screenName" and just accessed it everywhere via

Component.screenName

Kinda did the job :)

@prakashraman Thanks for the reply.
I have to think some thing else for my case. i need current screen name at global level so i have to maintained it there.

Ah ok. Yep :) Hope there is a way to query the framework itself.

Maybe, you could write a wrapper to the this.props.navigator.push and maintain the screen name in the store or static member?
Just a thought :)

It would be nice if we could get the current screen id, it is necessary to check as active the current screen in the drawer.

For achieving this i have to maintained at stack of screenIDs at global level by storing it in global scope of react native which is available throughout the app.

I am pushing screenID to global at componentDidMount and pop it when componentWillUnmount is called.

another thing you can do is to use decorator. Please check https://github.com/wix/react-native-navigation/issues/1118#issuecomment-296578643

Thanks.

I'd like this so that when tracking an analytic I can record on which screen the interaction happened.

Seems like most people are tracking this outside of the library, but IMO getting the identifier of the current screen from the navigator object would be more logical.

I'm thinking about adding something like that in a future version

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 version and report back. Thank you for your contributions.

The issue has been closed for inactivity.

@DanielZlotin Any update for this in V2?

You can get info by listening for Navigation.events().registerComponentDidAppearListener.

https://wix.github.io/react-native-navigation/#/docs/events?id=componentdidappear

I have proposed a workaround for this issue in another one, if you guys want, you can take a look:
https://github.com/wix/react-native-navigation/issues/75#issuecomment-562579897

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiennguyen9988 picture tiennguyen9988  路  31Comments

yusufyildirim picture yusufyildirim  路  53Comments

gtchance picture gtchance  路  57Comments

perrosnk picture perrosnk  路  36Comments

harveyconnor picture harveyconnor  路  57Comments