diff --git a/packages/react-native-codegen/src/generators/components/GenerateStateH.js b/packages/react-native-codegen/src/generators/components/GenerateStateH.js index 8805977275f..fa7f8f93201 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateStateH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateStateH.js @@ -33,7 +33,7 @@ const FileTemplate = ({ */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -50,7 +50,7 @@ class ${stateName}State { public: ${stateName}State() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ${stateName}State(${stateName}State const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap index 23db8fc9937..3d35e917299 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap @@ -12,7 +12,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -22,7 +22,7 @@ class ArrayPropsNativeComponentState { public: ArrayPropsNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -46,7 +46,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -56,7 +56,7 @@ class ArrayPropsNativeComponentState { public: ArrayPropsNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -80,7 +80,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -90,7 +90,7 @@ class BooleanPropNativeComponentState { public: BooleanPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE BooleanPropNativeComponentState(BooleanPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -114,7 +114,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -124,7 +124,7 @@ class ColorPropNativeComponentState { public: ColorPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ColorPropNativeComponentState(ColorPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -148,7 +148,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -158,7 +158,7 @@ class CommandNativeComponentState { public: CommandNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -182,7 +182,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -192,7 +192,7 @@ class CommandNativeComponentState { public: CommandNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -216,7 +216,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -226,7 +226,7 @@ class DimensionPropNativeComponentState { public: DimensionPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE DimensionPropNativeComponentState(DimensionPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -250,7 +250,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -260,7 +260,7 @@ class DoublePropNativeComponentState { public: DoublePropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE DoublePropNativeComponentState(DoublePropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -284,7 +284,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -294,7 +294,7 @@ class EventsNestedObjectNativeComponentState { public: EventsNestedObjectNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE EventsNestedObjectNativeComponentState(EventsNestedObjectNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -318,7 +318,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -328,7 +328,7 @@ class EventsNativeComponentState { public: EventsNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE EventsNativeComponentState(EventsNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -352,7 +352,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -376,7 +376,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -386,7 +386,7 @@ class ExcludedAndroidComponentState { public: ExcludedAndroidComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ExcludedAndroidComponentState(ExcludedAndroidComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -410,7 +410,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -420,7 +420,7 @@ class ExcludedAndroidIosComponentState { public: ExcludedAndroidIosComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ExcludedAndroidIosComponentState(ExcludedAndroidIosComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -444,7 +444,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -454,7 +454,7 @@ class ExcludedIosComponentState { public: ExcludedIosComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ExcludedIosComponentState(ExcludedIosComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -466,7 +466,7 @@ class MultiFileIncludedNativeComponentState { public: MultiFileIncludedNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE MultiFileIncludedNativeComponentState(MultiFileIncludedNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -490,7 +490,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -500,7 +500,7 @@ class FloatPropNativeComponentState { public: FloatPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE FloatPropNativeComponentState(FloatPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -524,7 +524,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -534,7 +534,7 @@ class ImagePropNativeComponentState { public: ImagePropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ImagePropNativeComponentState(ImagePropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -558,7 +558,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -568,7 +568,7 @@ class InsetsPropNativeComponentState { public: InsetsPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE InsetsPropNativeComponentState(InsetsPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -592,7 +592,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -602,7 +602,7 @@ class Int32EnumPropsNativeComponentState { public: Int32EnumPropsNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE Int32EnumPropsNativeComponentState(Int32EnumPropsNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -626,7 +626,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -636,7 +636,7 @@ class IntegerPropNativeComponentState { public: IntegerPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE IntegerPropNativeComponentState(IntegerPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -660,7 +660,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -684,7 +684,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -694,7 +694,7 @@ class MixedPropNativeComponentState { public: MixedPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE MixedPropNativeComponentState(MixedPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -718,7 +718,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -728,7 +728,7 @@ class ImageColorPropNativeComponentState { public: ImageColorPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ImageColorPropNativeComponentState(ImageColorPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -752,7 +752,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -762,7 +762,7 @@ class NoPropsNoEventsComponentState { public: NoPropsNoEventsComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE NoPropsNoEventsComponentState(NoPropsNoEventsComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -786,7 +786,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -796,7 +796,7 @@ class ObjectPropsState { public: ObjectPropsState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ObjectPropsState(ObjectPropsState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -820,7 +820,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -830,7 +830,7 @@ class PointPropNativeComponentState { public: PointPropNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE PointPropNativeComponentState(PointPropNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -854,7 +854,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -864,7 +864,7 @@ class StringEnumPropsNativeComponentState { public: StringEnumPropsNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE StringEnumPropsNativeComponentState(StringEnumPropsNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -888,7 +888,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -898,7 +898,7 @@ class StringPropComponentState { public: StringPropComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE StringPropComponentState(StringPropComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -922,7 +922,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -932,7 +932,7 @@ class MultiFile1NativeComponentState { public: MultiFile1NativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE MultiFile1NativeComponentState(MultiFile1NativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -944,7 +944,7 @@ class MultiFile2NativeComponentState { public: MultiFile2NativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE MultiFile2NativeComponentState(MultiFile2NativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -968,7 +968,7 @@ Map { */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -978,7 +978,7 @@ class MultiComponent1NativeComponentState { public: MultiComponent1NativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE MultiComponent1NativeComponentState(MultiComponent1NativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -990,7 +990,7 @@ class MultiComponent2NativeComponentState { public: MultiComponent2NativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE MultiComponent2NativeComponentState(MultiComponent2NativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; diff --git a/packages/react-native-popup-menu-android/android/src/main/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.h b/packages/react-native-popup-menu-android/android/src/main/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.h index 4c50c5cca27..de97a8fb38e 100644 --- a/packages/react-native-popup-menu-android/android/src/main/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.h +++ b/packages/react-native-popup-menu-android/android/src/main/jni/react/renderer/components/ReactPopupMenuAndroidSpecs/States.h @@ -8,7 +8,7 @@ */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #include #include @@ -20,7 +20,7 @@ class AndroidPopupMenuState { public: AndroidPopupMenuState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE AndroidPopupMenuState(AndroidPopupMenuState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -31,4 +31,4 @@ public: #endif }; -} // namespace facebook::react \ No newline at end of file +} // namespace facebook::react diff --git a/packages/react-native-test-library/android/src/main/jni/react/renderer/components/OSSLibraryExampleSpec/States.h b/packages/react-native-test-library/android/src/main/jni/react/renderer/components/OSSLibraryExampleSpec/States.h index c083692a8e7..1cffd0cfe6d 100644 --- a/packages/react-native-test-library/android/src/main/jni/react/renderer/components/OSSLibraryExampleSpec/States.h +++ b/packages/react-native-test-library/android/src/main/jni/react/renderer/components/OSSLibraryExampleSpec/States.h @@ -8,7 +8,7 @@ */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -18,7 +18,7 @@ class SampleNativeComponentState { public: SampleNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE SampleNativeComponentState(SampleNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -26,4 +26,4 @@ public: #endif }; -} // namespace facebook::react \ No newline at end of file +} // namespace facebook::react diff --git a/packages/react-native-test-library/ios/OSSLibraryExampleSpec/States.h b/packages/react-native-test-library/ios/OSSLibraryExampleSpec/States.h index c083692a8e7..1cffd0cfe6d 100644 --- a/packages/react-native-test-library/ios/OSSLibraryExampleSpec/States.h +++ b/packages/react-native-test-library/ios/OSSLibraryExampleSpec/States.h @@ -8,7 +8,7 @@ */ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -18,7 +18,7 @@ class SampleNativeComponentState { public: SampleNativeComponentState() = default; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE SampleNativeComponentState(SampleNativeComponentState const &previousState, folly::dynamic data){}; folly::dynamic getDynamic() const { return {}; @@ -26,4 +26,4 @@ public: #endif }; -} // namespace facebook::react \ No newline at end of file +} // namespace facebook::react diff --git a/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt index 4b562cb790d..a00ce454de8 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt @@ -332,6 +332,81 @@ target_include_directories(reactnative $ ) +target_compile_definitions(reactnative + PUBLIC + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ +) + # GTest dependencies add_executable(reactnative_unittest ${REACT_COMMON_DIR}/cxxreact/tests/jsarg_helpers.cpp diff --git a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h index cecf63e6e1b..3bd36a9a98c 100644 --- a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h @@ -24,7 +24,7 @@ #include #include -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #include #endif @@ -1003,7 +1003,7 @@ inline std::string toString(const AttributedString::Range& range) { ", length: " + std::to_string(range.length) + "}"; } -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE // constants for AttributedString serialization constexpr static MapBuffer::Key AS_KEY_HASH = 0; diff --git a/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.cpp b/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.cpp index 9feec1d3856..e27e9377455 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.cpp @@ -9,7 +9,7 @@ namespace facebook::react { -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE folly::dynamic ModalHostViewState::getDynamic() const { return folly::dynamic::object("screenWidth", screenSize.width)( "screenHeight", screenSize.height); diff --git a/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.h b/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.h index 2b713926dd5..183188de443 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.h +++ b/packages/react-native/ReactCommon/react/renderer/components/modal/ModalHostViewState.h @@ -10,7 +10,7 @@ #include #include -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -35,7 +35,7 @@ class ModalHostViewState final { }; ModalHostViewState(Size screenSize_) : screenSize(screenSize_){}; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ModalHostViewState( const ModalHostViewState& previousState, folly::dynamic data) @@ -46,7 +46,7 @@ class ModalHostViewState final { const Size screenSize{}; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE folly::dynamic getDynamic() const; #endif diff --git a/packages/react-native/ReactCommon/react/renderer/components/progressbar/android/react/renderer/components/progressbar/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/progressbar/android/react/renderer/components/progressbar/conversions.h index 843755a8fa5..a8fc416c64a 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/progressbar/android/react/renderer/components/progressbar/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/progressbar/android/react/renderer/components/progressbar/conversions.h @@ -13,7 +13,7 @@ namespace facebook::react { -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE inline folly::dynamic toDynamic(const AndroidProgressBarProps& props) { folly::dynamic serializedProps = folly::dynamic::object(); serializedProps["styleAttr"] = props.styleAttr; diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewState.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewState.h index e9357004d45..bfe5d7f308f 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewState.h +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewState.h @@ -12,7 +12,7 @@ #include #include -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #endif @@ -38,7 +38,7 @@ class ScrollViewState final { */ Size getContentSize() const; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE ScrollViewState(const ScrollViewState& previousState, folly::dynamic data) : contentOffset( {(Float)data["contentOffsetLeft"].getDouble(), diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/text/conversions.h index 3b577200651..1f59b74a43a 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/text/conversions.h @@ -10,14 +10,14 @@ #include #include #include -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #include #endif namespace facebook::react { -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE inline MapBuffer toMapBuffer(const ParagraphState& paragraphState) { auto builder = MapBufferBuilder(); auto attStringMapBuffer = toMapBuffer(paragraphState.attributedString); diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h index ec720b5c67d..0101eda1790 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h @@ -12,6 +12,7 @@ #include #include +#include #include #include diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.h index 3f980ea78f8..d278f6818b7 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.h @@ -11,11 +11,6 @@ #include #include -#ifdef ANDROID -#include -#include -#endif - namespace facebook::react { /* @@ -29,15 +24,11 @@ class TextInputState final { AttributedStringBox attributedStringBox, AttributedString reactTreeAttributedString, ParagraphAttributes paragraphAttributes, - int64_t mostRecentEventCount); - -#ifdef ANDROID - TextInputState( - const TextInputState& previousState, - const folly::dynamic& data); - folly::dynamic getDynamic() const; - MapBuffer getMapBuffer() const; -#endif + int64_t mostRecentEventCount) + : attributedStringBox(std::move(attributedStringBox)), + reactTreeAttributedString(std::move(reactTreeAttributedString)), + paragraphAttributes(std::move(paragraphAttributes)), + mostRecentEventCount(mostRecentEventCount) {} /* * All content of component. @@ -60,14 +51,6 @@ class TextInputState final { ParagraphAttributes paragraphAttributes; int64_t mostRecentEventCount{0}; - -#ifdef ANDROID - /** - * Stores an opaque cache ID used on the Java side to refer to a specific - * AttributedString for measurement purposes only. - */ - int64_t cachedAttributedStringId{0}; -#endif }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h index 05018e83a46..d9940dfdc14 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h @@ -8,6 +8,7 @@ #pragma once #include "AndroidTextInputShadowNode.h" +#include "AndroidTextInputState.h" #include @@ -68,7 +69,8 @@ class AndroidTextInputComponentDescriptor final } return std::make_shared( - std::make_shared(TextInputState({}, {}, {}, 0)), + std::make_shared( + AndroidTextInputState({}, {}, {}, 0)), family); } diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp index f32d12f9a12..524e5184f74 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp @@ -154,7 +154,7 @@ void AndroidTextInputShadowNode::updateStateIfNeeded( : props.mostRecentEventCount; auto newAttributedString = getMostRecentAttributedString(layoutContext); - setStateData(TextInputState{ + setStateData(AndroidTextInputState{ AttributedStringBox(newAttributedString), reactTreeAttributedString, props.paragraphAttributes, diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h index e21e30c7bca..97e0b18664f 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h @@ -9,9 +9,9 @@ #include "AndroidTextInputEventEmitter.h" #include "AndroidTextInputProps.h" +#include "AndroidTextInputState.h" #include -#include #include #include @@ -26,7 +26,7 @@ class AndroidTextInputShadowNode final : public ConcreteViewShadowNode< AndroidTextInputComponentName, AndroidTextInputProps, AndroidTextInputEventEmitter, - TextInputState> { + AndroidTextInputState> { public: using ConcreteViewShadowNode::ConcreteViewShadowNode; diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputState.cpp similarity index 50% rename from packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.cpp rename to packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputState.cpp index 1bf68a8621c..1669ad34a70 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputState.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputState.cpp @@ -5,46 +5,18 @@ * LICENSE file in the root directory of this source tree. */ -#include "TextInputState.h" +#include "AndroidTextInputState.h" -#ifdef ANDROID #include #include -#endif namespace facebook::react { -TextInputState::TextInputState( - AttributedStringBox attributedStringBox, - AttributedString reactTreeAttributedString, - ParagraphAttributes paragraphAttributes, - int64_t mostRecentEventCount) - : attributedStringBox(std::move(attributedStringBox)), - reactTreeAttributedString(std::move(reactTreeAttributedString)), - paragraphAttributes(std::move(paragraphAttributes)), - mostRecentEventCount(mostRecentEventCount) {} - -#ifdef ANDROID -TextInputState::TextInputState( - const TextInputState& previousState, - const folly::dynamic& data) - : attributedStringBox(previousState.attributedStringBox), - reactTreeAttributedString(previousState.reactTreeAttributedString), - paragraphAttributes(previousState.paragraphAttributes), - mostRecentEventCount(data.getDefault( - "mostRecentEventCount", - previousState.mostRecentEventCount) - .getInt()), - cachedAttributedStringId(data.getDefault( - "opaqueCacheId", - previousState.cachedAttributedStringId) - .getInt()){}; - -folly::dynamic TextInputState::getDynamic() const { +folly::dynamic AndroidTextInputState::getDynamic() const { LOG(FATAL) << "TextInputState state should only be read using MapBuffer"; } -MapBuffer TextInputState::getMapBuffer() const { +MapBuffer AndroidTextInputState::getMapBuffer() const { auto builder = MapBufferBuilder(); // If we have a `cachedAttributedStringId` we know that we're (1) not trying // to set a new string, so we don't need to pass it along; (2) setState was @@ -66,6 +38,5 @@ MapBuffer TextInputState::getMapBuffer() const { } return builder.build(); } -#endif } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputState.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputState.h new file mode 100644 index 00000000000..b5d5eec1522 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputState.h @@ -0,0 +1,83 @@ +/* + * 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. + */ + +#pragma once + +#include +#include +#include + +#include +#include + +namespace facebook::react { + +/* + * State for component. + */ +class AndroidTextInputState final { + public: + AndroidTextInputState() = default; + + AndroidTextInputState( + AttributedStringBox attributedStringBox, + AttributedString reactTreeAttributedString, + ParagraphAttributes paragraphAttributes, + int64_t mostRecentEventCount) + : attributedStringBox(std::move(attributedStringBox)), + reactTreeAttributedString(std::move(reactTreeAttributedString)), + paragraphAttributes(std::move(paragraphAttributes)), + mostRecentEventCount(mostRecentEventCount) {} + + AndroidTextInputState( + const AndroidTextInputState& previousState, + const folly::dynamic& data) + : attributedStringBox(previousState.attributedStringBox), + reactTreeAttributedString(previousState.reactTreeAttributedString), + paragraphAttributes(previousState.paragraphAttributes), + mostRecentEventCount(data.getDefault( + "mostRecentEventCount", + previousState.mostRecentEventCount) + .getInt()), + cachedAttributedStringId(data.getDefault( + "opaqueCacheId", + previousState.cachedAttributedStringId) + .getInt()) {} + + folly::dynamic getDynamic() const; + MapBuffer getMapBuffer() const; + + /* + * All content of component. + */ + AttributedStringBox attributedStringBox; + + /* + * All content of component represented as an `AttributedString`. + * This stores the previous computed *from the React tree*. This usually + * doesn't change as the TextInput contents are being updated. If it does + * change, we need to wipe out current contents of the TextInput and replace + * with the new value from the tree. + */ + AttributedString reactTreeAttributedString{}; + + /* + * Represents all visual attributes of a paragraph of text represented as + * a ParagraphAttributes. + */ + ParagraphAttributes paragraphAttributes; + + int64_t mostRecentEventCount{0}; + + /** + * Stores an opaque cache ID used on the Java side to refer to a specific + * AttributedString for measurement purposes only. + */ + int64_t cachedAttributedStringId{0}; +}; + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/CMakeLists.txt b/packages/react-native/ReactCommon/react/renderer/core/CMakeLists.txt index ce90c7a8a97..b40b3beb598 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/CMakeLists.txt +++ b/packages/react-native/ReactCommon/react/renderer/core/CMakeLists.txt @@ -26,4 +26,5 @@ target_link_libraries(react_renderer_core react_utils runtimeexecutor) target_compile_reactnative_options(react_renderer_core PRIVATE "Fabric") +target_compile_definitions(react_renderer_core PUBLIC RN_SERIALIZABLE_STATE) target_compile_options(react_renderer_core PRIVATE -Wpedantic) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h index 6e85b0487af..f0eb03a8666 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h @@ -13,7 +13,7 @@ #include #include -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #include #include @@ -21,7 +21,7 @@ namespace facebook::react { -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE template concept StateDataWithMapBuffer = requires(StateDataT stateData) { { stateData.getMapBuffer() } -> std::same_as; @@ -107,7 +107,7 @@ class ConcreteState : public State { family->dispatchRawState(std::move(stateUpdate)); } -#ifdef ANDROID +#if defined(RN_SERIALIZABLE_STATE) folly::dynamic getDynamic() const override { return getData().getDynamic(); } diff --git a/packages/react-native/ReactCommon/react/renderer/core/State.h b/packages/react-native/ReactCommon/react/renderer/core/State.h index 0fe174414f9..21980378075 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/State.h +++ b/packages/react-native/ReactCommon/react/renderer/core/State.h @@ -7,7 +7,7 @@ #pragma once -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #include #include @@ -62,7 +62,7 @@ class State { */ size_t getRevision() const; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE virtual folly::dynamic getDynamic() const = 0; virtual MapBuffer getMapBuffer() const = 0; virtual jni::local_ref getJNIReference() const = 0; diff --git a/packages/react-native/ReactCommon/react/renderer/core/StateData.h b/packages/react-native/ReactCommon/react/renderer/core/StateData.h index aa051f5d9b4..cfefa0e9ac6 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/StateData.h +++ b/packages/react-native/ReactCommon/react/renderer/core/StateData.h @@ -9,7 +9,7 @@ #include -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE #include #include #include @@ -24,7 +24,7 @@ namespace facebook::react { struct StateData final { using Shared = std::shared_ptr; -#ifdef ANDROID +#ifdef RN_SERIALIZABLE_STATE StateData() = default; StateData(const StateData& previousState, folly::dynamic data) {} folly::dynamic getDynamic() const;