Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsProvider

private val stableFlagsWithNitroViewRecycling: ReactNativeFeatureFlagsProvider =
object : ReactNativeFeatureFlagsProvider by ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android() {
// TODO: this can be removed once we upgraded to RN 0.87. Added for being able to reproduce #1656
override fun enableExclusivePropsUpdateAndroid(): Boolean = true

override fun enablePreparedTextLayout(): Boolean = false

override fun enableViewRecycling(): Boolean = true
Expand Down
7 changes: 6 additions & 1 deletion packages/nitrogen/src/views/CppHybridViewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ ${createFileMetadataString(`${component}.cpp`)}
#include "${component}.hpp"

#include <NitroModules/NitroHash.hpp>
#include <NitroModules/RawPropsCompat.hpp>
#include <NitroModules/ReactProp.hpp>

namespace ${namespace} {
Expand All @@ -196,7 +197,11 @@ namespace ${namespace} {
${propsClassName}::${propsClassName}(const react::PropsParserContext& context,
${ctorIndent} const ${propsClassName}& sourceProps,
${ctorIndent} const react::RawProps& rawProps):
${indent(propInitializers.join(',\n'), ' ')} { }
${indent(propInitializers.join(',\n'), ' ')} {
#ifdef ANDROID
nitro::RawPropsCompat::initializeDynamicProps(*this, sourceProps, rawProps, filterObjectKeys);
#endif
}

bool ${propsClassName}::filterObjectKeys(const std::string& propName) {
switch (hashString(propName)) {
Expand Down
21 changes: 21 additions & 0 deletions packages/react-native-nitro-modules/cpp/views/RawPropsCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#endif

#include <cxxreact/ReactNativeVersion.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/RawPropsParser.h>

#if defined(ANDROID) && REACT_NATIVE_VERSION_MAJOR == 0 && REACT_NATIVE_VERSION_MINOR >= 84 && REACT_NATIVE_VERSION_MINOR < 87
#include <react/featureflags/ReactNativeFeatureFlags.h>
#endif

namespace margelo::nitro::RawPropsCompat {

const facebook::react::RawValue* at(const facebook::react::RawProps& props, const char* name) {
Expand All @@ -32,4 +37,20 @@ facebook::react::RawPropsParser makePropsParser() {
#endif
}

void initializeDynamicProps([[maybe_unused]] facebook::react::Props& props, [[maybe_unused]] const facebook::react::Props& sourceProps,
[[maybe_unused]] const facebook::react::RawProps& rawProps,
[[maybe_unused]] bool (*filterObjectKeys)(const std::string&)) {
#ifdef ANDROID
#if REACT_NATIVE_VERSION_MAJOR > 0 || REACT_NATIVE_VERSION_MINOR >= 87
// Since React Native 0.87, the base constructor no longer initializes dynamic props.
props.initializeDynamicProps(sourceProps, rawProps, filterObjectKeys);
#elif REACT_NATIVE_VERSION_MINOR >= 84
// React Native 0.84-0.86 skips initialization only when exclusive props updates are enabled.
if (facebook::react::ReactNativeFeatureFlags::enableExclusivePropsUpdateAndroid()) {
props.initializeDynamicProps(sourceProps, rawProps, filterObjectKeys);
}
#endif
#endif
}

} // namespace margelo::nitro::RawPropsCompat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#pragma once

#include <string>

namespace facebook::react {
class Props;
class RawProps;
class RawPropsParser;
class RawValue;
Expand All @@ -15,4 +18,8 @@ namespace margelo::nitro::RawPropsCompat {
const facebook::react::RawValue* at(const facebook::react::RawProps& props, const char* name);
facebook::react::RawPropsParser makePropsParser();

// Initialize Android's dynamic props only when the React Native constructor has not already done so.
void initializeDynamicProps(facebook::react::Props& props, const facebook::react::Props& sourceProps,
const facebook::react::RawProps& rawProps, bool (*filterObjectKeys)(const std::string&));

} // namespace margelo::nitro::RawPropsCompat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "HybridRecyclableTestViewComponent.hpp"

#include <NitroModules/NitroHash.hpp>
#include <NitroModules/RawPropsCompat.hpp>
#include <NitroModules/ReactProp.hpp>

namespace margelo::nitro::test::views {
Expand All @@ -22,7 +23,11 @@ namespace margelo::nitro::test::views {
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
isBlue(nitro::ReactProp<bool>::fromRawValue("RecyclableTestView", "isBlue", rawProps, sourceProps.isBlue)),
nativeDefaultValue(nitro::ReactProp<std::optional<double>>::fromRawValue("RecyclableTestView", "nativeDefaultValue", rawProps, sourceProps.nativeDefaultValue)),
hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridRecyclableTestViewSpec>& /* ref */)>>>::fromRawValue("RecyclableTestView", "hybridRef", rawProps, sourceProps.hybridRef)) { }
hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridRecyclableTestViewSpec>& /* ref */)>>>::fromRawValue("RecyclableTestView", "hybridRef", rawProps, sourceProps.hybridRef)) {
#ifdef ANDROID
nitro::RawPropsCompat::initializeDynamicProps(*this, sourceProps, rawProps, filterObjectKeys);
#endif
}

bool HybridRecyclableTestViewProps::filterObjectKeys(const std::string& propName) {
switch (hashString(propName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "HybridTestViewComponent.hpp"

#include <NitroModules/NitroHash.hpp>
#include <NitroModules/RawPropsCompat.hpp>
#include <NitroModules/ReactProp.hpp>

namespace margelo::nitro::test::views {
Expand All @@ -25,7 +26,11 @@ namespace margelo::nitro::test::views {
colorScheme(nitro::ReactProp<ColorScheme>::fromRawValue("TestView", "colorScheme", rawProps, sourceProps.colorScheme)),
someCallback(nitro::ReactProp<std::function<void()>>::fromRawValue("TestView", "someCallback", rawProps, sourceProps.someCallback)),
nativeDefaultValue(nitro::ReactProp<std::optional<double>>::fromRawValue("TestView", "nativeDefaultValue", rawProps, sourceProps.nativeDefaultValue)),
hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridTestViewSpec>& /* ref */)>>>::fromRawValue("TestView", "hybridRef", rawProps, sourceProps.hybridRef)) { }
hybridRef(nitro::ReactProp<std::optional<std::function<void(const std::shared_ptr<HybridTestViewSpec>& /* ref */)>>>::fromRawValue("TestView", "hybridRef", rawProps, sourceProps.hybridRef)) {
#ifdef ANDROID
nitro::RawPropsCompat::initializeDynamicProps(*this, sourceProps, rawProps, filterObjectKeys);
#endif
}

bool HybridTestViewProps::filterObjectKeys(const std::string& propName) {
switch (hashString(propName)) {
Expand Down
Loading