Skip to content

[Android] No API for updating props on android root component #6303

Closed

Description

@jaredly

In iOS, you can do rctRootView.appProperties = newProps, and it will update the root view with new props. On android it doesn't seem to be implemented.

This behavior is critical for my use case of incrementally adopting react native in a large android app.

I think I want a function like ReactRootView.updateProps(Bundle props) that would look something like

public void updateProps(Bundle newProps) {
  WritableNativeMap appParams = new WritableNativeMap();
  Double rootTag = MagicallyGetTheRootTag() // <- the rootTag isn't actually stored anywhere at the moment
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", newProps);
  final CatalystInstance catalystInstance = mReactInstanceManager.getCurrentReactContext().getCatalystInstance();
  String jsAppModuleName = this.getJSModuleName();
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
}

based on the startReactApplication fn

Before I made a PR I wanted to check my direction -- does it look reasonable? I think I'll have to store the rootTag on the ReactRootView instance, b/c I can't find anywhere else that it's already stored.

Activity

  1. changed the title [-]No API for updating props on android root component[/-] [+][Android] No API for updating props on android root component[/+] on Mar 4, 2016
  2. brentvatne commented on Mar 6, 2016

    @brentvatne
    Collaborator

    @bestander - could you check this out to see if it's reasonable? This is part of getting parity with iOS, cc @mkonicek

  3. bestander commented on Mar 6, 2016

    @bestander
    Contributor

    Will do on Tuesday

    On Sunday, 6 March 2016, Brent Vatne notifications@github.com wrote:

    @bestander https://github.com/bestander - could you check this out to
    see if it's reasonable? This is part of getting parity with iOS, cc
    @mkonicek https://github.com/mkonicek

    —
    Reply to this email directly or view it on GitHub
    #6303 (comment)
    .

  4. brentvatne commented on Mar 6, 2016

    @brentvatne
    Collaborator

    🚀

  5. bestander commented on Mar 8, 2016

    @bestander
    Contributor

    @jaredly go for it, we would appreciate this feature.
    Ping me with the PR.

  6. jaredly commented on Mar 9, 2016

    @jaredly
    ContributorAuthor

    ok so my initial attempt was unsuccessful (pretty much doing what I outlined above), and we've decided not to invest in RN yet, so it's unlikely I'll dig into this further in the near future

  7. bestander commented on Mar 10, 2016

    @bestander
    Contributor

    No worries, we'll do it eventually.
    Would you mind giving feedback why you have decided to not proceed with RN right now?
    Any particular pain or aspect you think we should address?

  8. jaredly commented on Mar 10, 2016

    @jaredly
    ContributorAuthor

    mostly immaturity of android, and to a lesser extent iOS. We have large apps that we're thinking of integrating react native into incrementally, which definitely isn't a well-documented use case. we're planning on doing further investigation in a few months and might have a different decision depending on how things have matured.

  9. bestander commented on Mar 10, 2016

    @bestander
    Contributor

    👍
    Thanks, this gives some very important feedback.

  10. MikeOrtiz commented on Jun 7, 2016

    @MikeOrtiz
    Contributor

    @bestander What is the status of this feature request? My use case requires inserting a RN view in a native ListView. Removing and creating new react views doesn't allow for smooth scrolling and emitting events with prop updates sends the same props to all children.

    Is the feature currently being worked on? If not, what might it involve to implement?

  11. satya164 commented on Jun 7, 2016

    @satya164
    Contributor

    @MikeOrtiz nobody is working on it right now. feel free to send a pull request.

  12. skeyboy commented on Aug 25, 2016

    @skeyboy

    I want to get a data from Java to JS

    bundle.putString("value", "aValue");
    mReactRootView.startReactApplication(mReactInstanceManager, "IndexActivity", bundle);

    but, I can not get the value from this.props.value

  13. lacker commented on Nov 30, 2016

    @lacker
    Contributor

    It sounds like this issue has played out, and we are keeping issues focused on bugs rather than feature requests at the moment, so I am going to close this issue. Feel free to send a pull request improving this though!

  14. jaredly commented on Feb 23, 2017

    @jaredly
    ContributorAuthor

    @brentvatne bump :P this is totally basic for having sane integration with an existing app

  15. tianxind commented on Mar 9, 2017

    @tianxind

    Bump this feature request. @brentvatne Or at least I think the lack of this feature on Android should be mentioned here: https://facebook.github.io/react-native/docs/communication-ios.html It will save people from mistakenly assuming that it exists for Android.

  16. SunburtReynolds commented on Mar 20, 2017

    @SunburtReynolds

    +1

  17. tommasoresti commented on Jun 7, 2017

    @tommasoresti

    Hi guys. Thank you for the amazing work you are doing with react.

    Anyway i agree with @tianxind, someone should mention that Android is not ready to update props of a running component. I've lost half of my brain looking for a solution then a came here XD

  18. boliveira commented on Jul 12, 2018

    @boliveira

    Hi,

    There is a method in ReactRootView called setAppProperties that does what is intended, I believe.
    The problem is, like in iOS, the root component gets recreated instead of just updated (componentWillUnmount will be called and then the component will be recreated). Is this the intended behavior? Is there any way to just re-render the root component?

  19. locked as resolved and limited conversation to collaborators on Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Resolution: LockedThis issue was locked by the bot.Type: EnhancementA new feature or enhancement of an existing feature.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions