-
Notifications
You must be signed in to change notification settings - Fork 199
isFocused is not set correctly when Scene is rendered as initialRoute on StackNavigation #107
Comments
I tried getting something running by looking at the AndroidBackButtonBehaviour. Since all Components through _makeRoute are focusAwareComponents. I added following
But on the first initialRoute in the Tab + StackNavigation in componentDidMount isFocused is false. Pusing a route, does not yield a unfocused either. BUT! Poping back to initialRoute now causes isFocused. I'm clearly missing something on the first render. |
Hi @ptomasroos -- Could you uncomment https://github.com/exponentjs/ex-navigation/blob/master/src/ExNavigationComponents.js#L236, https://github.com/exponentjs/ex-navigation/blob/master/src/ExNavigationComponents.js#L238, https://github.com/exponentjs/ex-navigation/blob/master/src/ExNavigationComponents.js#L243, and https://github.com/exponentjs/ex-navigation/blob/master/src/ExNavigationComponents.js#L245, and run your app with those changes, and then paste the output here? |
Sure thing! Already debugged that code to find out a part of the problem. The problem is that the event handler is subscribed after the scene is already mounted / rendered. |
@skevy truly sorry for delaying the output when requesting your attention So i created a example app demonstrating it for you. https://github.com/ptomasroos/minimalex react-native run-ios Notice that the first tab rendering has isFocused false. If you go to the stack on profile and click the "This works to push, click me" When a Component is rendered there is no way for it to be able to get isFocused true. |
Thanks for the repro case @ptomasroos. This is super helpful. I'm 90% sure I know what's going on, and I think it's a fundamental flaw in the isFocused implementation. Gonna think through this a bit now. |
while you think about it, it's worth thinking about how we can avoid that extra re-render those who don't care about isFocused. we discussed about pull model instead of push based. I suggest isFocused as a function :) |
You're welcome @skevy That could def be the case @chirag04 But I think a concept of rather onEnter / onExit as es6 class methods on the given Component would work good as well. Should remember that is too few life cycle hooks when it comes to app since much stuff is mounted almost forever :) Then one can decide to set the state if its needed for rendering or just call for Analytics screen tracking view or logging. |
or just let the user do |
i can imagine having to do |
My work-around for this was to create my own component wrapper which is then subclassed by each top-level view component that needs to know whether it's focused or not. The wrapper has an onFocusChange method which is called whenever the component is rendered using the following this._isFocused is set so that we make sure we only call focus or unfocus code when it's changed and not for repeat events. Whenever a component is focused, an event emitter is used to let other components know that they are now unfocused so they can do anything they need to. |
@lprhodes Would you mind sharing an example of your workaround? I am not sure where the wrapper should be given the stacknavigation syntax my redux store provider. |
Yeah, any help here would be really appreciated! |
Unfortunately I found too many issues and had to stop using onFocus type code sorry. I ended up defining callback methods and using event emitters to call them from views I'd pushed so I could perform an a top on the parent view when I did something in a child view. This got me most of the way. I'll be moving to https://reactnavigation.org asap |
No description provided.
The text was updated successfully, but these errors were encountered: