From 59021521e7aba0f70b91b5c7778ccdd1b30eaae4 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 24 Aug 2021 17:56:56 -0700 Subject: [PATCH] Fixed dynamic behavior of on Android (#31538) Summary: This PR fixes https://github.com/facebook/react-native/issues/30717, a bug in `` implementation that prevents it from adjusting text size dynamically on Android. The way `adjustsFontSizeToFit` was implemented in https://github.com/facebook/react-native/issues/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. ## Changelog [Android] [Fixed] - Fixed dynamic behavior of on Android Pull Request resolved: https://github.com/facebook/react-native/pull/31538 Test Plan: https://user-images.githubusercontent.com/22032/118508162-8c79cc80-b6f4-11eb-853f-a1a09f82935f.mov Reviewed By: mdvacca Differential Revision: D28631465 Pulled By: yungsters fbshipit-source-id: 7db1d22e2a5a464c7bf941d1d3df8e3fe8df66a2 --- .../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 95468c3a8fe510..46bc1e9b50054e 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")