Skip to content

Commit

Permalink
Always generate an EmptyNativeState (#34754)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #34754

This Diff is the second step of enabling the CodeGen to parse and generate a NativeState for the components.

The feature has been largely requested by the OSS community but it could be also helpful for people in Meta.

## Changelog
[General][Added] - Always generate an empty NativeState for Fabric Components

Reviewed By: cortinico

Differential Revision: D39696435

fbshipit-source-id: e24768af78f59696c0b4db009e8065bb5c89316b
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Sep 22, 2022
1 parent 69f8cf1 commit b7add0a
Show file tree
Hide file tree
Showing 18 changed files with 2,314 additions and 56 deletions.
7 changes: 4 additions & 3 deletions ReactAndroid/cmake-utils/ReactNative-application.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ set(CMAKE_VERBOSE_MAKEFILE on)

include(${REACT_ANDROID_DIR}/cmake-utils/Android-prebuilt.cmake)

file(GLOB input_SRC CONFIGURE_DEPENDS
file(GLOB input_SRC CONFIGURE_DEPENDS
*.cpp
${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/*.cpp)

add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC
target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni)

Expand All @@ -45,6 +45,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
react_render_core
react_render_debug
react_render_graphics
react_render_mapbuffer
rrc_view
runtimeexecutor
turbomodulejsijni
Expand Down
19 changes: 19 additions & 0 deletions packages/react-native-codegen/DEFS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def rn_codegen_components(
generate_event_emitter_h_name = "generate_event_emitter_h-{}".format(name)
generate_props_cpp_name = "generate_props_cpp-{}".format(name)
generate_props_h_name = "generated_props_h-{}".format(name)
generate_state_cpp_name = "generate_state_cpp-{}".format(name)
generate_state_h_name = "generated_state_h-{}".format(name)
generate_tests_cpp_name = "generate_tests_cpp-{}".format(name)
generate_shadow_node_cpp_name = "generated_shadow_node_cpp-{}".format(name)
generate_shadow_node_h_name = "generated_shadow_node_h-{}".format(name)
Expand Down Expand Up @@ -314,6 +316,13 @@ def rn_codegen_components(
labels = ["codegen_rule"],
)

fb_native.genrule(
name = generate_state_cpp_name,
cmd = "cp $(location :{})/States.cpp $OUT".format(generate_fixtures_rule_name),
out = "States.cpp",
labels = ["codegen_rule"],
)

fb_native.genrule(
name = generate_tests_cpp_name,
cmd = "cp $(location :{})/Tests.cpp $OUT".format(generate_fixtures_rule_name),
Expand All @@ -328,6 +337,13 @@ def rn_codegen_components(
labels = ["codegen_rule"],
)

fb_native.genrule(
name = generate_state_h_name,
cmd = "cp $(location :{})/States.h $OUT".format(generate_fixtures_rule_name),
out = "States.h",
labels = ["codegen_rule"],
)

fb_native.genrule(
name = copy_generated_java_files,
# TODO: support different package name internally.
Expand Down Expand Up @@ -388,12 +404,14 @@ def rn_codegen_components(
srcs = [
":{}".format(generate_event_emitter_cpp_name),
":{}".format(generate_props_cpp_name),
":{}".format(generate_state_cpp_name),
":{}".format(generate_shadow_node_cpp_name),
],
headers = [
":{}".format(generate_component_descriptor_h_name),
":{}".format(generate_event_emitter_h_name),
":{}".format(generate_props_h_name),
":{}".format(generate_state_h_name),
":{}".format(generate_shadow_node_h_name),
],
header_namespace = "react/renderer/components/{}".format(name),
Expand All @@ -403,6 +421,7 @@ def rn_codegen_components(
"Props.h": ":{}".format(generate_props_h_name),
"RCTComponentViewHelpers.h": ":{}".format(generate_component_hobjcpp_name),
"ShadowNodes.h": ":{}".format(generate_shadow_node_h_name),
"States.h": ":{}".format(generate_state_h_name),
},
fbobjc_compiler_flags = get_apple_compiler_flags(),
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -30,7 +31,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentViewComponentName[];
using ArrayPropsNativeComponentViewShadowNode = ConcreteViewShadowNode<
ArrayPropsNativeComponentViewComponentName,
ArrayPropsNativeComponentViewProps,
ArrayPropsNativeComponentViewEventEmitter>;
ArrayPropsNativeComponentViewEventEmitter,
ArrayPropsNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -54,6 +56,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -68,7 +71,8 @@ JSI_EXPORT extern const char BooleanPropNativeComponentViewComponentName[];
using BooleanPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
BooleanPropNativeComponentViewComponentName,
BooleanPropNativeComponentViewProps,
BooleanPropNativeComponentViewEventEmitter>;
BooleanPropNativeComponentViewEventEmitter,
BooleanPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -92,6 +96,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -106,7 +111,8 @@ JSI_EXPORT extern const char ColorPropNativeComponentViewComponentName[];
using ColorPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
ColorPropNativeComponentViewComponentName,
ColorPropNativeComponentViewProps,
ColorPropNativeComponentViewEventEmitter>;
ColorPropNativeComponentViewEventEmitter,
ColorPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -130,6 +136,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -144,7 +151,8 @@ JSI_EXPORT extern const char EdgeInsetsPropNativeComponentViewComponentName[];
using EdgeInsetsPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
EdgeInsetsPropNativeComponentViewComponentName,
EdgeInsetsPropNativeComponentViewProps,
EdgeInsetsPropNativeComponentViewEventEmitter>;
EdgeInsetsPropNativeComponentViewEventEmitter,
EdgeInsetsPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -168,6 +176,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -182,7 +191,8 @@ JSI_EXPORT extern const char EnumPropNativeComponentViewComponentName[];
using EnumPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
EnumPropNativeComponentViewComponentName,
EnumPropNativeComponentViewProps,
EnumPropNativeComponentViewEventEmitter>;
EnumPropNativeComponentViewEventEmitter,
EnumPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -206,6 +216,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -220,7 +231,8 @@ JSI_EXPORT extern const char EventNestedObjectPropsNativeComponentViewComponentN
using EventNestedObjectPropsNativeComponentViewShadowNode = ConcreteViewShadowNode<
EventNestedObjectPropsNativeComponentViewComponentName,
EventNestedObjectPropsNativeComponentViewProps,
EventNestedObjectPropsNativeComponentViewEventEmitter>;
EventNestedObjectPropsNativeComponentViewEventEmitter,
EventNestedObjectPropsNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -244,6 +256,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -258,7 +271,8 @@ JSI_EXPORT extern const char EventPropsNativeComponentViewComponentName[];
using EventPropsNativeComponentViewShadowNode = ConcreteViewShadowNode<
EventPropsNativeComponentViewComponentName,
EventPropsNativeComponentViewProps,
EventPropsNativeComponentViewEventEmitter>;
EventPropsNativeComponentViewEventEmitter,
EventPropsNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -282,6 +296,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -296,7 +311,8 @@ JSI_EXPORT extern const char FloatPropsNativeComponentViewComponentName[];
using FloatPropsNativeComponentViewShadowNode = ConcreteViewShadowNode<
FloatPropsNativeComponentViewComponentName,
FloatPropsNativeComponentViewProps,
FloatPropsNativeComponentViewEventEmitter>;
FloatPropsNativeComponentViewEventEmitter,
FloatPropsNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -320,6 +336,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -334,7 +351,8 @@ JSI_EXPORT extern const char ImagePropNativeComponentViewComponentName[];
using ImagePropNativeComponentViewShadowNode = ConcreteViewShadowNode<
ImagePropNativeComponentViewComponentName,
ImagePropNativeComponentViewProps,
ImagePropNativeComponentViewEventEmitter>;
ImagePropNativeComponentViewEventEmitter,
ImagePropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -358,6 +376,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -372,7 +391,8 @@ JSI_EXPORT extern const char IntegerPropNativeComponentViewComponentName[];
using IntegerPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
IntegerPropNativeComponentViewComponentName,
IntegerPropNativeComponentViewProps,
IntegerPropNativeComponentViewEventEmitter>;
IntegerPropNativeComponentViewEventEmitter,
IntegerPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -396,6 +416,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand Down Expand Up @@ -426,6 +447,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -440,7 +462,8 @@ JSI_EXPORT extern const char MultiNativePropNativeComponentViewComponentName[];
using MultiNativePropNativeComponentViewShadowNode = ConcreteViewShadowNode<
MultiNativePropNativeComponentViewComponentName,
MultiNativePropNativeComponentViewProps,
MultiNativePropNativeComponentViewEventEmitter>;
MultiNativePropNativeComponentViewEventEmitter,
MultiNativePropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -464,6 +487,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -478,7 +502,8 @@ JSI_EXPORT extern const char NoPropsNoEventsNativeComponentViewComponentName[];
using NoPropsNoEventsNativeComponentViewShadowNode = ConcreteViewShadowNode<
NoPropsNoEventsNativeComponentViewComponentName,
NoPropsNoEventsNativeComponentViewProps,
NoPropsNoEventsNativeComponentViewEventEmitter>;
NoPropsNoEventsNativeComponentViewEventEmitter,
NoPropsNoEventsNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -502,6 +527,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -516,7 +542,8 @@ JSI_EXPORT extern const char ObjectPropsNativeComponentComponentName[];
using ObjectPropsNativeComponentShadowNode = ConcreteViewShadowNode<
ObjectPropsNativeComponentComponentName,
ObjectPropsNativeComponentProps,
ObjectPropsNativeComponentEventEmitter>;
ObjectPropsNativeComponentEventEmitter,
ObjectPropsNativeComponentState>;
} // namespace react
} // namespace facebook
Expand All @@ -540,6 +567,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -554,7 +582,8 @@ JSI_EXPORT extern const char PointPropNativeComponentViewComponentName[];
using PointPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
PointPropNativeComponentViewComponentName,
PointPropNativeComponentViewProps,
PointPropNativeComponentViewEventEmitter>;
PointPropNativeComponentViewEventEmitter,
PointPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand All @@ -578,6 +607,7 @@ Object {
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/components/RNCodegenModuleFixtures/States.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand All @@ -592,7 +622,8 @@ JSI_EXPORT extern const char StringPropNativeComponentViewComponentName[];
using StringPropNativeComponentViewShadowNode = ConcreteViewShadowNode<
StringPropNativeComponentViewComponentName,
StringPropNativeComponentViewProps,
StringPropNativeComponentViewEventEmitter>;
StringPropNativeComponentViewEventEmitter,
StringPropNativeComponentViewState>;
} // namespace react
} // namespace facebook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ RNCodegen.generate(
'descriptors',
'events',
'props',
'states',
'tests',
'shadow-nodes',
'modulesAndroid',
Expand Down
Loading

0 comments on commit b7add0a

Please sign in to comment.