From bd77f622a872292103a429127e42e70f9cb99a71 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 17 May 2021 09:07:04 -0500 Subject: [PATCH] Fixed dynamic behavior of on Android This PR fixes #30717, a bug in `` implementation that prevents it from adjusting text size dynamically on Android. The way `adjustsFontSizeToFit` was implemented in #26389 (and the design of ReactTextShadowNode) implies that Yoga will call `onMeasure` on every size change of a `` component, which is actually not the case (Yoga can cache the results of the measures, call the function multiple times or do not call at all inferring the size from the size constraints). The implementation of `adjustsFontSizeToFit` computes the adjusted string inside the measure function and then eventually passes that to the view layer where it's being rendered. The proper fix of this issue requires the full redesign of the measure and rendering pipelines and separating them, and that... would be too invasive. And, I believe, this issue is already fixed in Fabric where this part is already designed this way. Instead, this diff implements a small workaround: if `adjustsFontSizeToFit` is enabled, we manually dirty the Yoga node and mark the shadow node updated to force remeasuring. --- .../com/facebook/react/views/text/ReactTextShadowNode.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index f350bccf872f..ae6502b1a835 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -327,6 +327,11 @@ public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) { mJustificationMode); uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), reactTextUpdate); } + + if (mAdjustsFontSizeToFit) { + // Nodes with `adjustsFontSizeToFit` enabled need to be remeasured on every relayout. + markUpdated(); + } } @ReactProp(name = "onTextLayout")