-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NavigatorIOS] doesn't update when passProps update #795
Comments
I don't know |
The reason we don't do this is we don't want to re-render all of the scenes every time you re-render
I'm still trying to figure out the ideal pattern for re-rendering internal scenes. Feedback and ideas are welcome! |
@ericvicenti Oh, I totally forgot I can use For the Thanks for your elaborating. |
I too ran into this when I first started writing a RN app. Is there any way that calling setState can update props to any potential children on the same route like with React? e.g. _buttonPress() {
this.setState({
input: 'heyo'
})
},
render() {
return (
<View>
<ChildComponent input={this.state.input} /> // input prop change will be heard by Child
</View>
)
} I understand that on mobile you're probably not building as complex UI Component structures for a given single route. I'm not sure what the benefits/trade-offs is/are here. |
@mjw56, That code should work, the input prop would be updated when setState is called. Are you having difficulties when putting ChildComponent inside a Navigator or NavigatorIOS? @lazywei, I agree that it would be nicer to re-render the scene when the NavigatorIOS gets re-rendered. It would be great if somebody could implement When it comes to slowness from re-rendering in You might run into issues if you want to re-render aggressively, but you could always improve the |
It also doesn't update when navigationBarHidden is changed, see #846 |
Still an issue with React Native 0.6rc. Workaround is calling |
may be this PR can solved your issue ? |
@mars: It's a Workaround if you haven't got anything in NavigatorIOS. What if you have pushed several routes? I am trying to use resetTo() in order to reset the whole thing every time new props come in. (http://stackoverflow.com/questions/31320583/invariant-violation-calling-pop-to-route-for-a-route-that-doesnt-exist) Any idea? |
@edo1493 I ended up using the more manual but less limiting |
@ericvicenti have you seen this? Thanks. |
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed. |
Is this issue about For clarification about the difference, check out @brentvatne's comparison |
@ericvicenti this issue is w/ Using the |
The issue is with NavigatorIOS. |
Ok, that sounds like a reasonable workaround for now. We currently don't use |
@ericvicenti @vjeux @brentvatne this may sound crazy but should react native move It can live in userland and will be better supported i guess if it's in userland. |
Yes. Please either remove it so people don't get confused or put a big red warning in the docs saying "this component breaks the underlying working of react". Wasted time until I found this bug. |
My original plan was to filter global state down through the component hierarchy, but given this bug: facebook/react-native#795 It seems that we need to inject state below the level of the ios navigator component.
I know this is a bit off-topic, but is there a way to update the props of each component in the stackRoute of Navigator? I am updating the state where Navigator is rendered, but the props don't seem to update. TabBar does this with StaticContainer, I am trying to find an Android workaround. I think forceUpdate() just made my day. 😄 Update: which doesn't seem to really work 😢 |
I use v0.13.1. For example, getRecentChats() {
return this.state.ChatListData.recentChats;
}
render() {
return (
<NavigatorIOS
style={{flex: 1}}
initialRoute={{
component: MyChatList,
title: "My Chat List",
passProps: {
recentChats: getRecentChats.bind(this),
renderRow: this.renderRecentChat,
},
}} />
);
} |
Summary: ping #795 (comment) Closes #3087 Reviewed By: svcscm Differential Revision: D2738947 Pulled By: mkonicek fb-gh-sync-id: e29dfd933a8da42551576bdb1fb5c270039722ee
I've been using |
@ericvicenti any idea why navigator.replace(newRoute) does't work in RN version 17 and 16? going back to version 14 now :( |
It might be due to changes on the native side. I don't really work with NavigatorIOS, so I'm not sure |
* Allows internal scenes to react to changes in their passed properties. * By default, NavigatorIOS (and Navigator, to a lesser extent) doesn't play super nicely with flux's concept of unidirectional data flow. When a property in a route's `passProps` changes, the route's scene is not re-rendered. * This patch allows route objects to optionally define their `passProps` property as a function that returns an hash of properties to use for rendering. * When a route's `passProps` property is a function, it will be evaluated each time NavigatorIOS is rendered. If the properties have changed, the route's scene will be re-rendered with the new properties. * Workaround for design decision described [here](facebook#795). * Facebook is putting resources into figuring out a better process to accomplish single-directional data flow with navigation components & patterns. I think we'll eventually be able to take advantage of that work. GitHub repo for that project is [here](https://github.com/ericvicenti/navigation-rfc).
* Allows internal scenes to react to changes in their passed properties. * By default, NavigatorIOS (and Navigator, to a lesser extent) doesn't play super nicely with flux's concept of unidirectional data flow. When a property in a route's `passProps` changes, the route's scene is not re-rendered. * This patch allows route objects to optionally define their `passProps` property as a function that returns an hash of properties to use for rendering. * When a route's `passProps` property is a function, it will be evaluated each time NavigatorIOS is rendered. If the properties have changed, the route's scene will be re-rendered with the new properties. * Workaround for design decision described [here](facebook#795). * Facebook is putting resources into figuring out a better process to accomplish single-directional data flow with navigation components & patterns. I think we'll eventually be able to take advantage of that work. GitHub repo for that project is [here](https://github.com/ericvicenti/navigation-rfc).
What happened with this? I'm also experiencing this error. Apparently we were going to see a response in 30 days but that was about 5 or 6 months ago. |
+1 |
1 similar comment
👍 |
+1 |
+1 |
Facebook don't support the native control (NavigatorIOS) - Navigator is their JS replacement and it works okay - try using that instead and it won't be full of bugs! |
I'm using version 0.34.0 and Navigator (not NavigatorIOS) and I'm having this exact problem. State changes in my parent screens get passed into child/sibling screens via passProps, but the child/sibling screens don't get re-rendered. I have to call this.forceUpdate() on my child/sibling screens after calling back to the parent screen. It works fine, but it's not very "Reacty". |
I am also experiencing the issue described by @Gagege, which is very easy to reproduce. It is counter intuitive because with all react components, you expect that props passed to a child will automatically re-render the child when they are updated in the parent via setState(). The use of Navigator's passProps functionality breaks this pattern and makes it difficult to update any view that is a child of a navigator. I am going to try using NavigationExperimental to see if it has the same issue |
This issue seems like it is now a bunch of different issues combined. @felipemullen I suggest trying ExNavigation and complaining to @skevy if it is not good enough, rather than NavigationExperimental which we are figuring out how to combine with ExNavigation soon. I'm going to close this issue, and I suggest if people continue to have similar problems they open a new issue and be very clear about whether the problem applies to |
I'm not sure if this is a feature or a bug:
When I change the value of
passProps
of a navigator, I expect it would re-render again, just like other react components do. However, it seems it will not do so.For example,
When the state
ChatListData
(which comes from flux) updates, the navigator will not update it self correspondly.The text was updated successfully, but these errors were encountered: