From 07d723cb72a34dfbec3e93dda10d27eb5b1fbe30 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Wed, 11 Dec 2024 23:45:21 -0800 Subject: [PATCH] Remove unused (Android) TextLayoutManager getter (#48208) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48208 [Changelog] [Internal] - Remove unused (Android) TextLayoutManager getter This getter ``` void* getNativeTextLayoutManager() const; ``` is not used on Android and different in signature to the iOS one: ``` std::shared_ptr getNativeTextLayoutManager() const; ``` Deleting it for now to make future code sharing between various platforms easier. This change removes further the by now discouraged pattern of: ``` using SharedTextLayoutManager = std::shared_ptr; ``` and changes callers to use ``` std::shared_ptr; ``` directly. Reviewed By: javache Differential Revision: D67059514 fbshipit-source-id: b94dc7f664083c5c62c4ba7defca480549ca9dc1 --- .../AndroidTextInputComponentDescriptor.h | 10 ++++------ .../androidtextinput/AndroidTextInputShadowNode.cpp | 2 +- .../androidtextinput/AndroidTextInputShadowNode.h | 5 +++-- .../iostextinput/TextInputComponentDescriptor.h | 9 ++++----- .../renderer/textlayoutmanager/TextLayoutManager.cpp | 4 ---- .../renderer/textlayoutmanager/TextLayoutManager.h | 9 --------- .../textlayoutmanager/platform/cxx/TextLayoutManager.h | 2 -- .../renderer/textlayoutmanager/TextLayoutManager.h | 2 +- .../renderer/textlayoutmanager/TextLayoutManager.mm | 10 +++++----- 9 files changed, 18 insertions(+), 35 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h index 5601d1c3c4330a..b5c91c462ddfe0 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h @@ -28,11 +28,9 @@ class AndroidTextInputComponentDescriptor final public: AndroidTextInputComponentDescriptor( const ComponentDescriptorParameters& parameters) - : ConcreteComponentDescriptor(parameters) { - // Every single `AndroidTextInputShadowNode` will have a reference to - // a shared `TextLayoutManager`. - textLayoutManager_ = std::make_shared(contextContainer_); - } + : ConcreteComponentDescriptor(parameters), + textLayoutManager_( + std::make_shared(contextContainer_)) {} virtual State::Shared createInitialState( const Props::Shared& props, @@ -165,7 +163,7 @@ class AndroidTextInputComponentDescriptor final constexpr static auto UIManagerJavaDescriptor = "com/facebook/react/fabric/FabricUIManager"; - SharedTextLayoutManager textLayoutManager_; + const std::shared_ptr textLayoutManager_; mutable std::unordered_map surfaceIdToThemePaddingMap_; }; diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp index e1a2c436f38230..db0d85d83befb6 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp @@ -84,7 +84,7 @@ AttributedString AndroidTextInputShadowNode::getPlaceholderAttributedString() } void AndroidTextInputShadowNode::setTextLayoutManager( - SharedTextLayoutManager textLayoutManager) { + std::shared_ptr textLayoutManager) { ensureUnsealed(); textLayoutManager_ = std::move(textLayoutManager); } diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h index 222ba23c10cd26..173c30928b2718 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h @@ -50,7 +50,8 @@ class AndroidTextInputShadowNode final * `TextInputShadowNode` uses the manager to measure text content * and construct `TextInputState` objects. */ - void setTextLayoutManager(SharedTextLayoutManager textLayoutManager); + void setTextLayoutManager( + std::shared_ptr textLayoutManager); #pragma mark - LayoutableShadowNode @@ -73,7 +74,7 @@ class AndroidTextInputShadowNode final */ void updateStateIfNeeded(); - SharedTextLayoutManager textLayoutManager_; + std::shared_ptr textLayoutManager_; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputComponentDescriptor.h index 796a7bd5a89900..c361114f6533b2 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/ios/react/renderer/components/iostextinput/TextInputComponentDescriptor.h @@ -19,10 +19,9 @@ class TextInputComponentDescriptor final : public ConcreteComponentDescriptor { public: TextInputComponentDescriptor(const ComponentDescriptorParameters& parameters) - : ConcreteComponentDescriptor(parameters) { - textLayoutManager_ = - std::make_shared(contextContainer_); - } + : ConcreteComponentDescriptor(parameters), + textLayoutManager_( + std::make_shared(contextContainer_)) {} protected: void adopt(ShadowNode& shadowNode) const override { @@ -33,7 +32,7 @@ class TextInputComponentDescriptor final } private: - std::shared_ptr textLayoutManager_; + const std::shared_ptr textLayoutManager_; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp index 719c329d53357b..70defbdf564933 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp @@ -92,10 +92,6 @@ TextLayoutManager::TextLayoutManager( textMeasureCache_(kSimpleThreadSafeCacheSizeCap), lineMeasureCache_(kSimpleThreadSafeCacheSizeCap) {} -void* TextLayoutManager::getNativeTextLayoutManager() const { - return self_; -} - TextMeasurement TextLayoutManager::measure( const AttributedStringBox& attributedStringBox, const ParagraphAttributes& paragraphAttributes, diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.h index 7a34319bd5e3d9..845fbabb05f667 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.h @@ -18,8 +18,6 @@ namespace facebook::react { class TextLayoutManager; -using SharedTextLayoutManager = std::shared_ptr; - /* * Cross platform facade for Android-specific TextLayoutManager. */ @@ -75,19 +73,12 @@ class TextLayoutManager { const ParagraphAttributes& paragraphAttributes, const Size& size) const; - /* - * Returns an opaque pointer to platform-specific TextLayoutManager. - * Is used on a native views layer to delegate text rendering to the manager. - */ - void* getNativeTextLayoutManager() const; - private: TextMeasurement doMeasure( const AttributedString& attributedString, const ParagraphAttributes& paragraphAttributes, const LayoutConstraints& layoutConstraints) const; - void* self_{}; ContextContainer::Shared contextContainer_; TextMeasureCache textMeasureCache_; LineMeasureCache lineMeasureCache_; 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 8a7bb824380d87..e2110037e48dd0 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 @@ -21,8 +21,6 @@ namespace facebook::react { class TextLayoutManager; -using SharedTextLayoutManager = std::shared_ptr; - /* * Cross platform facade for Android-specific TextLayoutManager. */ diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h index c12277093f2d0d..91d7e2ebb6f52d 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.h @@ -61,7 +61,7 @@ class TextLayoutManager { std::shared_ptr getNativeTextLayoutManager() const; private: - std::shared_ptr self_; + std::shared_ptr nativeTextLayoutManager_; TextMeasureCache textMeasureCache_{}; LineMeasureCache lineMeasureCache_{}; }; diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm index a34667060b08c6..db713f83b99be7 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/TextLayoutManager.mm @@ -15,13 +15,13 @@ TextLayoutManager::TextLayoutManager(const ContextContainer::Shared &contextContainer) { - self_ = wrapManagedObject([RCTTextLayoutManager new]); + nativeTextLayoutManager_ = wrapManagedObject([RCTTextLayoutManager new]); } std::shared_ptr TextLayoutManager::getNativeTextLayoutManager() const { - assert(self_ && "Stored NativeTextLayoutManager must not be null."); - return self_; + assert(nativeTextLayoutManager_ && "Stored NativeTextLayoutManager must not be null."); + return nativeTextLayoutManager_; } TextMeasurement TextLayoutManager::measure( @@ -30,7 +30,7 @@ const TextLayoutContext &layoutContext, const LayoutConstraints &layoutConstraints) const { - RCTTextLayoutManager *textLayoutManager = (RCTTextLayoutManager *)unwrapManagedObject(self_); + RCTTextLayoutManager *textLayoutManager = (RCTTextLayoutManager *)unwrapManagedObject(nativeTextLayoutManager_); auto measurement = TextMeasurement{}; @@ -92,7 +92,7 @@ react_native_assert(attributedStringBox.getMode() == AttributedStringBox::Mode::Value); const auto &attributedString = attributedStringBox.getValue(); - RCTTextLayoutManager *textLayoutManager = (RCTTextLayoutManager *)unwrapManagedObject(self_); + RCTTextLayoutManager *textLayoutManager = (RCTTextLayoutManager *)unwrapManagedObject(nativeTextLayoutManager_); auto measurement = lineMeasureCache_.get({attributedString, paragraphAttributes, size}, [&](const LineMeasureCacheKey &key) {