-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Android native UI components are not re-layout on dynamically added views #17968
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We are running into the same problem while developing the react-native wrapper of our Android SDK. As far as I can tell the issue is that if you attach a
|
@charpeni what is your Android API? I also have an issue that is related with Fresco module. |
@efkan I've only used the default value of a RN project. Also, this bug doesn't only impact Fresco. @irgendeinich What's your workaround in PSPDFKit? |
@charpeni
|
Any news about this issue? |
Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest release, v0.55? Thank you for your contributions. |
with v0.55, this bug still appears. |
Is anyone currently working on this issue? |
it's not a bug it's a feature of react-native, but need more info about update customView in customModule with react-native flow. As workaround you can override requestLayout see here |
@Dimon70007 how this could be a feature? |
react-native does for you all dirty job to reach the best perfomance (but there is almost no documentation in react-native for situation when you want create native lib youself - assumed that you already have a good knoledges about android api) However needsCustomLayoutForChildren method should do this work |
This comment has been minimized.
This comment has been minimized.
I found a workaround. Whenever you want to refresh layout, you need to call below method with layout parent view argument.
|
@vKeyGeek thanks, worked for me |
I had this issue on android when creating a wrapper for the mapbox navigation SDK. Here is how I solved it - homeeondemand/react-native-mapbox-navigation@4fceba3 override fun requestLayout() {
super.requestLayout()
// This view relies on a measure + layout pass happening after it calls requestLayout().
// https://github.com/facebook/react-native/issues/4990#issuecomment-180415510
// https://stackoverflow.com/questions/39836356/react-native-resize-custom-ui-component
post(measureAndLayout)
}
private val measureAndLayout = Runnable {
measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY))
layout(left, top, right, bottom)
} |
I am creating RN wrapper for cameraX. I am getting ~5 fps rather than the 15 fps using above solution. Is anybody facing frame drops using with workaround solution? GPU Rendering for RN implementation: ( ~5 fps) This one clearly showed a huge portion of the rendering was colored in light green, which corresponds to Measure/Layout according to the documentation. @rossmartin solution has reduced more on the rendering stage for now. But there is no improvement on the fps. |
it's worked for me too, thanks |
any update about this bug? |
Unbelievable that this bug is still open. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Still a bug |
Still a bug |
Still a but, confirming again... |
Had similar issues trying to auto-size some content from a native Android View being hosted inside of a React Native view. Wanted to share the workaround approach that worked for me - involves similar usage of a In case it helps anyone else... override fun requestLayout() {
super.requestLayout()
post(measureAndLayout)
}
private val measureAndLayout = Runnable {
measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
)
layout(left, top, right, bottom)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
var maxWidth = 0
var maxHeight = 0
for (i in 0 until childCount) {
val child = getChildAt(i)
if (child.visibility != GONE) {
child.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED)
maxWidth = maxWidth.coerceAtLeast(child.measuredWidth)
maxHeight = maxHeight.coerceAtLeast(child.measuredHeight)
}
}
val finalWidth = maxWidth.coerceAtLeast(suggestedMinimumWidth)
val finalHeight = maxHeight.coerceAtLeast(suggestedMinimumHeight)
setMeasuredDimension(finalWidth, finalHeight)
(context as ThemedReactContext).runOnNativeModulesQueueThread {
(context as ThemedReactContext).getNativeModule(UIManagerModule::class.java)
?.updateNodeSize(id, finalWidth, finalHeight)
}
} |
I was still experiencing this issue in Solved it by wrapping my View class with a workaround:
classic rn madness |
Is this a bug report?
Yes.
Have you read the Contributing Guidelines?
Yes.
Environment
Environment:
OS: macOS High Sierra 10.13.2
Node: 8.9.4
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4 => 0.55.4
Description
The issue can be noticed if you bridge to React Native the following views:
A view with elements that have a visibility to
gone
on the initial render won't be displayed after you've set is visibility tovisible
.view.isShown()
will returntrue
, but it will not be there or it will be there but not really re-layout.A view with elements that are dynamically added, simply by
view.addView()
or let's say you want to load an image with Fresco it will only work if it was loaded on the initial render.I've noticed that native components are re-layout on hot reloading, but
this.forceUpdate()
or changing props won't trigger a re-layout. As an ugly workaround, if we interact with the native component height or width it will trigger a re-layout, so every time you want to toggle a visibility from gone to visible or dynamically adds views you can alter his size.I've also implemented
needsCustomLayoutForChildren
without notable change.Expected Behavior (Native)
Here's the native implementation directly inflated inside an Activity.
Actual Behavior (React Native)
Here's the exact same layout as above, but bridged to react native and inflated inside
SimpleViewManager
.Reproducible Demo
https://github.com/charpeni/react-native-android-visibility-issue
Related to #5531 (Already flagged in RN 0.18).
The text was updated successfully, but these errors were encountered: