Skip to content

Commit 878b745

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Refactor Component -> ComponentDeprecatedAPI
Summary: The goal of this diff is to refactor the name of Component to ComponentDeprecatedAPI Also, I'm introducing a new very simple Component API, this new Component will evolve in the next few diffs and days changelog: [internal] internal Reviewed By: sammy-SC Differential Revision: D41128461 fbshipit-source-id: b6aea08caa609153663cdd4165694cc57b4b76b6
1 parent c8c9015 commit 878b745

File tree

5 files changed

+79
-52
lines changed

5 files changed

+79
-52
lines changed

ReactAndroid/src/main/jni/react/cxxcomponents/Component.h

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,14 @@ namespace facebook::react {
1616

1717
class Component {
1818
public:
19-
Component(Tag tag, Props::Shared initialProps)
20-
: tag_(tag), props_(std::move(initialProps)) {}
19+
Component(Tag tag) : tag_(tag) {}
2120

22-
virtual ~Component() = default;
23-
24-
/*
25-
* Called for updating component's props.
26-
* Receiver must update native view props accordingly changed props.
27-
*/
28-
virtual void updateProps(
29-
Props::Shared const &oldProps,
30-
Props::Shared const &newProps) = 0;
31-
32-
/*
33-
* Called for mounting (attaching) a child component view inside `self`
34-
* component view.
35-
* Receiver must add `childComponent` as a sub component.
36-
*/
37-
virtual void mountChildComponent(
38-
std::shared_ptr<facebook::react::Component> childComponent,
39-
int index){};
21+
virtual void updateFloatProp(const std::string &propName, float value) = 0;
4022

41-
/*
42-
* Called for unmounting (detaching) a child component view from `self`
43-
* component view.
44-
* Receiver must remove `childComponent` from a sub component
45-
*/
46-
virtual void unmountChildComponent(
47-
std::shared_ptr<facebook::react::Component> childComponent,
48-
int index){};
49-
50-
/*
51-
* Called for updating component's state.
52-
* Receiver must update native view according to changed state.
53-
*/
54-
virtual void updateState(){};
55-
56-
/*
57-
* Called when the component is being deleted.
58-
*/
59-
virtual void deleteComponent() = 0;
23+
virtual ~Component() = default;
6024

6125
protected:
6226
Tag tag_ = -1;
63-
Props::Shared props_;
6427
};
6528

6629
} // namespace facebook::react
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <react/renderer/core/Props.h>
11+
#include <react/renderer/core/ReactPrimitives.h>
12+
#include <memory>
13+
#include <string>
14+
15+
namespace facebook::react {
16+
17+
class ComponentDeprecatedAPI {
18+
public:
19+
ComponentDeprecatedAPI(Tag tag, Props::Shared initialProps)
20+
: tag_(tag), props_(std::move(initialProps)) {}
21+
22+
virtual ~ComponentDeprecatedAPI() = default;
23+
24+
/*
25+
* Called for updating component's props.
26+
* Receiver must update native view props accordingly changed props.
27+
*/
28+
virtual void updateProps(
29+
Props::Shared const &oldProps,
30+
Props::Shared const &newProps) = 0;
31+
32+
/*
33+
* Called for mounting (attaching) a child component view inside `self`
34+
* component view.
35+
* Receiver must add `childComponent` as a sub component.
36+
*/
37+
virtual void mountChildComponent(
38+
std::shared_ptr<facebook::react::ComponentDeprecatedAPI> childComponent,
39+
int index){};
40+
41+
/*
42+
* Called for unmounting (detaching) a child component view from `self`
43+
* component view.
44+
* Receiver must remove `childComponent` from a sub component
45+
*/
46+
virtual void unmountChildComponent(
47+
std::shared_ptr<facebook::react::ComponentDeprecatedAPI> childComponent,
48+
int index){};
49+
50+
/*
51+
* Called for updating component's state.
52+
* Receiver must update native view according to changed state.
53+
*/
54+
virtual void updateState(){};
55+
56+
protected:
57+
Tag tag_ = -1;
58+
Props::Shared props_;
59+
};
60+
61+
} // namespace facebook::react

ReactAndroid/src/main/jni/react/cxxcomponents/ComponentManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <react/cxxcomponents/Component.h>
11+
#include <react/cxxcomponents/ComponentDeprecatedAPI.h>
1112
#include <react/renderer/core/Props.h>
1213

1314
namespace facebook::react {
@@ -16,10 +17,12 @@ class ComponentManager {
1617
public:
1718
ComponentManager() {}
1819

19-
virtual std::shared_ptr<Component> createComponent(
20+
virtual std::shared_ptr<ComponentDeprecatedAPI> createComponent(
2021
Tag tag,
2122
Props::Shared initialProps) = 0;
2223

24+
virtual std::shared_ptr<Component> createComponent(Tag tag) = 0;
25+
2326
virtual ~ComponentManager() = default;
2427
};
2528

ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include "CppComponentRegistry.h"
9-
#include <android/log.h>
109
#include <fbjni/fbjni.h>
1110
#include <jsi/jsi.h>
1211
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
@@ -22,9 +21,8 @@ CppComponentRegistry::initHybrid(jni::alias_ref<jclass>) {
2221
}
2322

2423
void CppComponentRegistry::registerNatives() {
25-
registerHybrid({
26-
makeNativeMethod("initHybrid", CppComponentRegistry::initHybrid),
27-
});
24+
registerHybrid(
25+
{makeNativeMethod("initHybrid", CppComponentRegistry::initHybrid)});
2826
}
2927

3028
void CppComponentRegistry::addComponentManager(
@@ -44,7 +42,7 @@ CppComponentRegistry::getComponentManager(const std::string &name) const {
4442
return componentManagerResolver_.getComponentManager(name);
4543
}
4644

47-
std::shared_ptr<facebook::react::Component>
45+
std::shared_ptr<facebook::react::ComponentDeprecatedAPI>
4846
CppComponentRegistry::getComponentInstance(Tag tag) const {
4947
return components_[tag];
5048
}
@@ -53,7 +51,7 @@ bool CppComponentRegistry::isRootComponent(std::string name) const {
5351
return componentManagerResolver_.isRootComponent(name);
5452
}
5553

56-
std::shared_ptr<facebook::react::Component>
54+
std::shared_ptr<facebook::react::ComponentDeprecatedAPI>
5755
CppComponentRegistry::createComponentInstance(
5856
const std::string &componentName,
5957
Tag tag,

ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <mutex>
1515
#include <unordered_set>
1616

17-
#include <react/cxxcomponents/Component.h>
17+
#include <react/cxxcomponents/ComponentDeprecatedAPI.h>
1818
#include <react/cxxcomponents/ComponentManager.h>
1919
#include <react/fabric/ComponentRegistryResolver.h>
2020

@@ -43,10 +43,11 @@ class CppComponentRegistry : public jni::HybridClass<CppComponentRegistry> {
4343
std::shared_ptr<facebook::react::ComponentManager> getComponentManager(
4444
const std::string &name) const;
4545

46-
std::shared_ptr<facebook::react::Component> getComponentInstance(
46+
std::shared_ptr<facebook::react::ComponentDeprecatedAPI> getComponentInstance(
4747
Tag tag) const;
4848

49-
std::shared_ptr<facebook::react::Component> createComponentInstance(
49+
std::shared_ptr<facebook::react::ComponentDeprecatedAPI>
50+
createComponentInstance(
5051
const std::string &componentName,
5152
Tag tag,
5253
Props::Shared initialProps) const;
@@ -56,8 +57,9 @@ class CppComponentRegistry : public jni::HybridClass<CppComponentRegistry> {
5657
private:
5758
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
5859
ComponentRegistryResolver componentManagerResolver_{};
59-
mutable butter::map<Tag, std::shared_ptr<facebook::react::Component>>
60-
components_{};
60+
mutable butter::
61+
map<Tag, std::shared_ptr<facebook::react::ComponentDeprecatedAPI>>
62+
components_{};
6163
};
6264

6365
} // namespace react

0 commit comments

Comments
 (0)