Skip to content

Commit 45887b4

Browse files
authored
Fix incorrect values for modal sizing (#45)
This fixes an issues where the fabric renderer would get the correct sizing via onSizeChanged, write it to the shadow tree generating a state update callback and then setting the wrong size using ModalHostManager. Once onSizeChanged is fired by the OS it is treated as the definitive source of truth for sizing.
1 parent 5dbedec commit 45887b4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,21 @@ public void runGuarded() {
489489
}
490490
}
491491

492+
/**
493+
* Updates the shadow tree via the local fabric view state manager. Can noop if the same values
494+
* are passed multiple times. Can also ignore params if the local variables for viewWidth &
495+
* viewHeight are non-zero.
496+
*
497+
* @param width target width of the container as pixels. Will be converted to DIP.
498+
* @param height target height of the container as pixels. Will be converted to DIP.
499+
*/
492500
@UiThread
493501
public void updateState(final int width, final int height) {
494-
final float realWidth = PixelUtil.toDIPFromPixel(width);
495-
final float realHeight = PixelUtil.toDIPFromPixel(height);
502+
// Once viewWidth & viewHeight are set by an onSizeChanged callback they become our source
503+
// of truth. This makes the fabric renderer function like the paper renderer is currently
504+
// functioning.
505+
final float realWidth = PixelUtil.toDIPFromPixel((viewWidth > 0) ? viewWidth : width);
506+
final float realHeight = PixelUtil.toDIPFromPixel((viewHeight > 0) ? viewHeight : height);
496507

497508
// Check incoming state values. If they're already the correct value, return early to prevent
498509
// infinite UpdateState/SetState loop.

0 commit comments

Comments
 (0)