-
Notifications
You must be signed in to change notification settings - Fork 24k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fabric: Introducing ComponentDescriptorProvider
Summary: ComponentDescriptorProvider represents unified way to create a particular descriptor. Now all ComponentViews (which support RCTComponentViewProtocol) expose a `ComponentDescriptorProvider` which will allow creating and registering ComponentDescriptor instances for all visual components automatically as a part of ComponentView registration process. Don't panic, everything is still being as explicit as it always was, no magic involved; we just will have only one registration step instead of two parallel. That also opens a way to register components on the fly. Reviewed By: JoshuaGross Differential Revision: D14963488 fbshipit-source-id: 9e9d9166fabaf7b30b35b8647faa6e3a19cd2435
- Loading branch information
1 parent
0735873
commit 00eab3d
Showing
18 changed files
with
139 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
ReactCommon/fabric/uimanager/ComponentDescriptorProvider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <react/core/ComponentDescriptor.h> | ||
#include <react/core/EventDispatcher.h> | ||
#include <react/utils/ContextContainer.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
/* | ||
* Callable signature that represents the signature of `ComponentDescriptor` | ||
* constructor. The callable returns a unique pointer conveniently represents an | ||
* abstract type and ownership of the newly created object. | ||
*/ | ||
using ComponentDescriptorConstructor = ComponentDescriptor::Unique( | ||
EventDispatcher::Shared const &eventDispatcher, | ||
ContextContainer::Shared const &contextContainer); | ||
|
||
/* | ||
* Represents a unified way to construct an instance of a particular stored | ||
* `ComponentDescriptor` class. C++ does not allow to create pointers to | ||
* constructors, so we have to have such data structure to manipulate a | ||
* collection of classes. | ||
*/ | ||
class ComponentDescriptorProvider final { | ||
public: | ||
ComponentHandle handle; | ||
ComponentDescriptorConstructor *constructor; | ||
}; | ||
|
||
/* | ||
* Creates a `ComponentDescriptorConstructor` for given `ComponentDescriptor` | ||
* class. | ||
*/ | ||
template <typename ComponentDescriptorT> | ||
ComponentDescriptor::Unique concreteComponentDescriptorConstructor( | ||
EventDispatcher::Shared const &eventDispatcher, | ||
ContextContainer::Shared const &contextContainer) { | ||
static_assert( | ||
std::is_base_of<ComponentDescriptor, ComponentDescriptorT>::value, | ||
"ComponentDescriptorT must be a descendant of ComponentDescriptor"); | ||
|
||
return std::make_unique<ComponentDescriptorT const>( | ||
eventDispatcher, contextContainer); | ||
} | ||
|
||
/* | ||
* Creates a `ComponentDescriptorProvider` for given `ComponentDescriptor` | ||
* class. | ||
*/ | ||
template <typename ComponentDescriptorT> | ||
ComponentDescriptorProvider concreteComponentDescriptorProvider() { | ||
static_assert( | ||
std::is_base_of<ComponentDescriptor, ComponentDescriptorT>::value, | ||
"ComponentDescriptorT must be a descendant of ComponentDescriptor"); | ||
|
||
return {ComponentDescriptorT::ConcreteShadowNode::Handle(), | ||
&concreteComponentDescriptorConstructor<ComponentDescriptorT>}; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
Oops, something went wrong.