mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Allow to provide a custom TextLayoutManager for cxx platform (#48127)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48127 [Changelog] [Internal] - Allow to provide a custom TextLayoutManager for cxx platform This change allows target platforms to pass a platform specific or app specific TextLayoutManager implementation Reviewed By: zeyap Differential Revision: D66802434 fbshipit-source-id: a64e28d357bf601c7234b43f86538f49e62c8435
This commit is contained in:
committed by
Facebook GitHub Bot
parent
05b4146270
commit
d47ff26f37
+2
-18
@@ -8,23 +8,6 @@
|
||||
#include "ImageComponentDescriptor.h"
|
||||
#include <react/renderer/imagemanager/ImageManager.h>
|
||||
|
||||
namespace {
|
||||
|
||||
std::shared_ptr<facebook::react::ImageManager> getImageManager(
|
||||
std::shared_ptr<const facebook::react::ContextContainer>&
|
||||
contextContainer) {
|
||||
if (auto imageManager =
|
||||
contextContainer
|
||||
->find<std::shared_ptr<facebook::react::ImageManager>>(
|
||||
facebook::react::ImageManagerKey);
|
||||
imageManager.has_value()) {
|
||||
return imageManager.value();
|
||||
}
|
||||
return std::make_shared<facebook::react::ImageManager>(contextContainer);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char ImageManagerKey[] = "ImageManager";
|
||||
@@ -32,7 +15,8 @@ extern const char ImageManagerKey[] = "ImageManager";
|
||||
ImageComponentDescriptor::ImageComponentDescriptor(
|
||||
const ComponentDescriptorParameters& parameters)
|
||||
: ConcreteComponentDescriptor(parameters),
|
||||
imageManager_(getImageManager(contextContainer_)){};
|
||||
imageManager_(
|
||||
getManagerByName<ImageManager>(contextContainer_, ImageManagerKey)){};
|
||||
|
||||
void ImageComponentDescriptor::adopt(ShadowNode& shadowNode) const {
|
||||
ConcreteComponentDescriptor::adopt(shadowNode);
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "ParagraphComponentDescriptor.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char TextLayoutManagerKey[] = "TextLayoutManager";
|
||||
|
||||
} // namespace facebook::react
|
||||
+10
-7
@@ -14,18 +14,20 @@
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char TextLayoutManagerKey[];
|
||||
|
||||
/*
|
||||
* Descriptor for <Paragraph> component.
|
||||
*/
|
||||
class ParagraphComponentDescriptor final
|
||||
: public ConcreteComponentDescriptor<ParagraphShadowNode> {
|
||||
public:
|
||||
ParagraphComponentDescriptor(const ComponentDescriptorParameters& parameters)
|
||||
: ConcreteComponentDescriptor<ParagraphShadowNode>(parameters) {
|
||||
// Every single `ParagraphShadowNode` will have a reference to
|
||||
// a shared `TextLayoutManager`.
|
||||
textLayoutManager_ = std::make_shared<TextLayoutManager>(contextContainer_);
|
||||
}
|
||||
explicit ParagraphComponentDescriptor(
|
||||
const ComponentDescriptorParameters& parameters)
|
||||
: ConcreteComponentDescriptor<ParagraphShadowNode>(parameters),
|
||||
textLayoutManager_(getManagerByName<TextLayoutManager>(
|
||||
contextContainer_,
|
||||
TextLayoutManagerKey)) {}
|
||||
|
||||
protected:
|
||||
void adopt(ShadowNode& shadowNode) const override {
|
||||
@@ -39,7 +41,8 @@ class ParagraphComponentDescriptor final
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<const TextLayoutManager> textLayoutManager_;
|
||||
// Every `ParagraphShadowNode` has a reference to a shared `TextLayoutManager`
|
||||
const std::shared_ptr<const TextLayoutManager> textLayoutManager_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -184,4 +184,17 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TManager>
|
||||
std::shared_ptr<TManager> getManagerByName(
|
||||
std::shared_ptr<const ContextContainer>& contextContainer,
|
||||
const char name[]) {
|
||||
if (contextContainer) {
|
||||
if (auto manager = contextContainer->find<std::shared_ptr<TManager>>(name);
|
||||
manager.has_value()) {
|
||||
return manager.value();
|
||||
}
|
||||
}
|
||||
return std::make_shared<TManager>(contextContainer);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
Reference in New Issue
Block a user