question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't properly render ReactRootView if it is inside Scrollable ViewGroup.

See original GitHub issue

Description

After update android react native lib from v0.24 to v0.38 I’m experience bug with rendering ReactRootView. I’m trying to use ReactRootView as an item for ListView(or RecyclerView, I tried both). Specifically: ReactRootView is being rendered to slowly, method onLayout (from javascript code) is called too many times (instead of one) and it takes 2-3 sec. I created github project to show how to reproduce the bug - Github page

Reproduction

I have simple react view that I’m trying to show in the list view inside the android app:

export default class Sample_2 extends Component {
  render() {
    return (
      <View style={styles.container} onLayout={this.onLayout.bind(this)} >
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Double tap R on your keyboard to reload,{'\n'}
          Shake or press menu button for dev menu
        </Text>
      </View>
    );
  }
  onLayout(e) {
    // here I'm sending (to the java code) new sizes for the item
    var dict = e.nativeEvent.layout;
    if (NativeModules.BridgeModule) {
      NativeModules.BridgeModule.onLayoutChanged(dict);
    }
  }
}

Then I compile local js and put bundle in the asset folder.
react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android/main.jsbundle

Then I set local js bundle to the reactInstanceManager and then start startReactApplication for the view .

 ReactInstanceManager reactInstanceManager = ReactInstanceManager.builder()
                    .setApplication(getApplication())
                    .setBundleAssetName("main.jsbundle")
                    //.... you can see details in github project
  mReactRootView.startReactApplication(reactInstanceManager, "Sample_2", null);

Result: huge delay in rendering. Is there any additional API that I’m not aware of that will help to fix that or does anybody have smart idea how to avoid that? P.S. I know that this is not very good idea to use ReactRootView for ListView item, but currently I have to stick with that approach. P.P.S. IOS react native libs works properly and method onLayout is called only once.

Update: Recently I discovered new bug. Application is crashing while it is trying to update ReactRootViewwith properties(again, ReactRootView is an item of RecyclerView/ListView). I guess it can be related to the first issue. I updated github repo, to reproduce the bug - launch second activity with RecyclerView. Stacktrace:

com.facebook.react.bridge.JSApplicationIllegalArgumentException: Error while updating property 'marginBottom' in shadow node of type: RCTText
at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateShadowNodeProp(ViewManagersPropertyCache.java:110)
at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackShadowNodeSetter.setProperty(ViewManagerPropertyUpdater.java:148)
at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps(ViewManagerPropertyUpdater.java:52)
at com.facebook.react.uimanager.ReactShadowNode.updateProperties(ReactShadowNode.java:246)
at com.facebook.react.uimanager.UIImplementation.createView(UIImplementation.java:186)
at com.facebook.react.uimanager.UIManagerModule.createView(UIManagerModule.java:235)
....

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NazarKacharabacommented, Feb 9, 2017

@fxkopp where exactly do you use float instead of int? If you set lineHeight as hardcoded value (not dynamically calculated) then it will work. In my case I do not know height for the reactview, it is calculated based on the content.

0reactions
hramoscommented, Jul 21, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll View inside view not working react native - Stack Overflow
I am rendering child component which has scrollview and also parent has scrollview. I am not able to properly handle this. Can you...
Read more >
Common bugs in React Native ScrollView and how to fix them
React Native's ScrollView component is ubiquitous, but its implementation can sometimes lead to mistakes. Learn what to look out for here.
Read more >
Use RecyclerView to display a scrollable list
In this codelab, you'll create an app that displays a list of text in a RecyclerView.
Read more >
Handling Scrolls with CoordinatorLayout - CodePath Cliffnotes
When a CoordinatorLayout notices this attribute declared in the RecyclerView, it will search across the other views contained within it for any related...
Read more >
ScrollView in Android Studio - YouTube
Well, in android, ScrollView is a view group that allows the child ... Android supports vertical scroll view as a default scroll view...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found