From c969d8c8dd21e9fcdf33eb92bd4bfd6bd23f75ac Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Wed, 4 Oct 2023 14:43:01 -0700 Subject: [PATCH] Turn CXX implementation of TextLayoutManager into interface (#39805) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39805 ## Changelog: [Internal] - This makes corresponsing text measure methods inside `TextLayoutManager` overridable, so that it can be substituted with a custom implementation without introducing a new "platform". Rationale: CXX platform is rather general and less specific than Android or iOS, so we may potentially have multiple alternative implementations of text layout there. An alternative could be making `TextLayoutManager` an interface across all the platforms, and actual implementations called e.g. `TextLayoutManagerImpl` in each of them, however this would be quite a bit bigger blast radius without much added benefit for Android/iOS. Reviewed By: christophpurrer Differential Revision: D49907594 fbshipit-source-id: dc8213ddb2313adaa86c2852d23bb038d80ac244 --- .../textlayoutmanager/platform/cxx/TextLayoutManager.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/TextLayoutManager.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/TextLayoutManager.h index a8b454814b5..84ffee6bf33 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/TextLayoutManager.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/cxx/TextLayoutManager.h @@ -29,10 +29,12 @@ class TextLayoutManager { public: TextLayoutManager(const ContextContainer::Shared& contextContainer) {} + virtual ~TextLayoutManager() = default; + /* * Measures `attributedStringBox` using native text rendering infrastructure. */ - TextMeasurement measure( + virtual TextMeasurement measure( AttributedStringBox attributedStringBox, ParagraphAttributes paragraphAttributes, LayoutConstraints layoutConstraints, @@ -42,7 +44,7 @@ class TextLayoutManager { * Measures lines of `attributedString` using native text rendering * infrastructure. */ - LinesMeasurements measureLines( + virtual LinesMeasurements measureLines( AttributedString attributedString, ParagraphAttributes paragraphAttributes, Size size) const; @@ -53,7 +55,7 @@ class TextLayoutManager { */ void* getNativeTextLayoutManager() const; - std::shared_ptr getHostTextStorage( + virtual std::shared_ptr getHostTextStorage( AttributedString attributedStringBox, ParagraphAttributes paragraphAttributes, LayoutConstraints layoutConstraints) const;