Can't properly render ReactRootView if it is inside Scrollable ViewGroup.
See original GitHub issueDescription
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 ReactRootView
with 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:
- Created 7 years ago
- Reactions:4
- Comments:9 (1 by maintainers)
@fxkopp where exactly do you use
float
instead ofint
? If you setlineHeight
as hardcoded value (not dynamically calculated) then it will work. In my case I do not know height for thereactview
, it is calculated based on the content.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:
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.