Skip to content

Commit

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

This Diff is the first 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.

To make this work, we also have to always generate a ViewEventEmitter: that's because the ConcreteShadowNode template lists the Generics with this order: Name, Props, EventEmitter, Others...
If we skip the EventEmitters and we put the State, React Native would think that the State is actually an EventEmitter and the build step will fail.

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

Differential Revision: D39509869

fbshipit-source-id: 93eb8b6d280e4ae95dd32f578e181d22fed781b5
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Sep 21, 2022
1 parent 596111f commit f29ead8
Show file tree
Hide file tree
Showing 17 changed files with 709 additions and 70 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 @@ -19,7 +19,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT ArrayPropsNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -46,7 +53,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT BooleanPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -73,7 +87,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT ColorPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -100,7 +121,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT EdgeInsetsPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -127,7 +155,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT EnumPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -281,7 +316,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT FloatPropsNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -308,7 +350,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT ImagePropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -335,7 +384,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT IntegerPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -398,7 +454,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT MultiNativePropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -425,7 +488,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT NoPropsNoEventsNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -452,7 +522,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT ObjectPropsNativeComponentEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -479,7 +556,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT PointPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand All @@ -506,7 +590,14 @@ Object {
namespace facebook {
namespace react {
class JSI_EXPORT StringPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
} // namespace facebook
Expand Down
Loading

0 comments on commit f29ead8

Please sign in to comment.