diff --git a/README.md b/README.md index e237e224..21d66ade 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ npm install @rive-app/react-native react-native-nitro-modules ``` > `react-native-nitro-modules` is required as this library relies on [Nitro Modules](https://nitro.margelo.com/). -> React Native 0.87 and newer need `react-native-nitro-modules` 0.36.2 or newer; older releases of Nitro cannot install on RN 0.87 (see [#378](https://github.com/rive-app/rive-nitro-react-native/issues/378)). +> This library requires `react-native-nitro-modules` 0.37.1 or newer (below 0.38); the generated view code does not compile against older Nitro releases. ## Usage diff --git a/example/package.json b/example/package.json index e15a23fe..4cdc3666 100644 --- a/example/package.json +++ b/example/package.json @@ -22,7 +22,7 @@ "react": "19.1.0", "react-native": "0.80.3", "react-native-gesture-handler": "2.29.1", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "0.37.1", "react-native-reanimated": "4.1.5", "react-native-safe-area-context": "^5.4.0", "react-native-screens": "~4.18.0", diff --git a/expo-example/package.json b/expo-example/package.json index a3d0f767..57f2839e 100644 --- a/expo-example/package.json +++ b/expo-example/package.json @@ -35,7 +35,7 @@ "react-dom": "19.1.0", "react-native": "0.81.5", "react-native-gesture-handler": "2.29.1", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "0.37.1", "react-native-reanimated": "4.1.5", "react-native-safe-area-context": "~5.6.0", "react-native-screens": "~4.16.0", diff --git a/expo55-example/package.json b/expo55-example/package.json index 45014f6a..7843bd59 100644 --- a/expo55-example/package.json +++ b/expo55-example/package.json @@ -35,7 +35,7 @@ "react-dom": "19.2.0", "react-native": "0.83.4", "react-native-gesture-handler": "~2.29.0", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "0.37.1", "react-native-reanimated": "4.2.1", "react-native-safe-area-context": "~5.6.2", "react-native-screens": "~4.23.0", diff --git a/expo57-example/package.json b/expo57-example/package.json index a5b26103..4aa3e33e 100644 --- a/expo57-example/package.json +++ b/expo57-example/package.json @@ -34,7 +34,7 @@ "react-dom": "19.2.3", "react-native": "0.86.0", "react-native-gesture-handler": "~2.32.0", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "0.37.1", "react-native-reanimated": "4.5.0", "react-native-safe-area-context": "~5.7.0", "react-native-screens": "4.25.2", diff --git a/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.cpp b/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.cpp index e003051d..7595e9ea 100644 --- a/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.cpp +++ b/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.cpp @@ -15,81 +15,109 @@ namespace margelo::nitro::rive::views { using namespace facebook; using ConcreteStateData = react::ConcreteState; -void JHybridRiveViewStateUpdater::updateViewProps(jni::alias_ref /* class */, - jni::alias_ref javaView, - jni::alias_ref stateWrapperInterface) { - std::shared_ptr hybridView = javaView->getJHybridRiveViewSpec(); - +std::shared_ptr JHybridRiveViewStateUpdater::getPropsFromStateWrapper( + jni::alias_ref stateWrapper) { + if (stateWrapper.get() == nullptr) { + return nullptr; + } // Get concrete StateWrapperImpl from passed StateWrapper interface object - jobject rawStateWrapper = stateWrapperInterface.get(); - if (!stateWrapperInterface->isInstanceOf(react::StateWrapperImpl::javaClassStatic())) [[unlikely]] { - throw std::runtime_error("StateWrapper is not a StateWrapperImpl"); + jobject rawStateWrapper = stateWrapper.get(); + if (!stateWrapper->isInstanceOf(react::StateWrapperImpl::javaClassStatic())) [[unlikely]] { + throw std::runtime_error("StateWrapper is not a StateWrapperImpl"); + } + auto stateWrapperImpl = jni::alias_ref{ + static_cast(rawStateWrapper) + }; + std::shared_ptr state = stateWrapperImpl->cthis()->getState(); + if (state == nullptr) { + return nullptr; } - auto stateWrapper = jni::alias_ref{ - static_cast(rawStateWrapper)}; - std::shared_ptr state = stateWrapper->cthis()->getState(); auto concreteState = std::static_pointer_cast(state); const HybridRiveViewState& data = concreteState->getData(); - const std::shared_ptr& props = data.getProps(); + const std::shared_ptr& props = data.getProps(); if (props == nullptr) [[unlikely]] { - // Props aren't set yet! throw std::runtime_error("HybridRiveViewState's data doesn't contain any props!"); } + return props; +} + +void JHybridRiveViewStateUpdater::updateViewProps(jni::alias_ref /* class */, + jni::alias_ref javaView, + jni::alias_ref newState, + jni::alias_ref oldState) { + std::shared_ptr hybridView = javaView->getJHybridRiveViewSpec(); + std::shared_ptr newProps = getPropsFromStateWrapper(newState); + std::shared_ptr oldProps = getPropsFromStateWrapper(oldState); + if (newProps == nullptr) [[unlikely]] { + throw std::runtime_error("Current StateWrapper doesn't contain any props!"); + } - // Update all props if they are dirty - if (props->artboardName.isDirty) { - hybridView->setArtboardName(props->artboardName.value); - props->artboardName.isDirty = false; + // Update only props that differ from the previous State snapshot. + if (oldProps == nullptr + ? newProps->artboardName.isProvided() + : !newProps->artboardName.hasSameValue(oldProps->artboardName)) { + hybridView->setArtboardName(newProps->artboardName.get()); } - if (props->stateMachineName.isDirty) { - hybridView->setStateMachineName(props->stateMachineName.value); - props->stateMachineName.isDirty = false; + if (oldProps == nullptr + ? newProps->stateMachineName.isProvided() + : !newProps->stateMachineName.hasSameValue(oldProps->stateMachineName)) { + hybridView->setStateMachineName(newProps->stateMachineName.get()); } - if (props->autoPlay.isDirty) { - hybridView->setAutoPlay(props->autoPlay.value); - props->autoPlay.isDirty = false; + if (oldProps == nullptr + ? newProps->autoPlay.isProvided() + : !newProps->autoPlay.hasSameValue(oldProps->autoPlay)) { + hybridView->setAutoPlay(newProps->autoPlay.get()); } - if (props->file.isDirty) { - hybridView->setFile(props->file.value); - props->file.isDirty = false; + if (oldProps == nullptr + ? newProps->file.isProvided() + : !newProps->file.hasSameValue(oldProps->file)) { + hybridView->setFile(newProps->file.get()); } - if (props->alignment.isDirty) { - hybridView->setAlignment(props->alignment.value); - props->alignment.isDirty = false; + if (oldProps == nullptr + ? newProps->alignment.isProvided() + : !newProps->alignment.hasSameValue(oldProps->alignment)) { + hybridView->setAlignment(newProps->alignment.get()); } - if (props->fit.isDirty) { - hybridView->setFit(props->fit.value); - props->fit.isDirty = false; + if (oldProps == nullptr + ? newProps->fit.isProvided() + : !newProps->fit.hasSameValue(oldProps->fit)) { + hybridView->setFit(newProps->fit.get()); } - if (props->layoutScaleFactor.isDirty) { - hybridView->setLayoutScaleFactor(props->layoutScaleFactor.value); - props->layoutScaleFactor.isDirty = false; + if (oldProps == nullptr + ? newProps->layoutScaleFactor.isProvided() + : !newProps->layoutScaleFactor.hasSameValue(oldProps->layoutScaleFactor)) { + hybridView->setLayoutScaleFactor(newProps->layoutScaleFactor.get()); } - if (props->frameRate.isDirty) { - hybridView->setFrameRate(props->frameRate.value); - props->frameRate.isDirty = false; + if (oldProps == nullptr + ? newProps->frameRate.isProvided() + : !newProps->frameRate.hasSameValue(oldProps->frameRate)) { + hybridView->setFrameRate(newProps->frameRate.get()); } - if (props->semantics.isDirty) { - hybridView->setSemantics(props->semantics.value); - props->semantics.isDirty = false; + if (oldProps == nullptr + ? newProps->semantics.isProvided() + : !newProps->semantics.hasSameValue(oldProps->semantics)) { + hybridView->setSemantics(newProps->semantics.get()); } - if (props->dataBind.isDirty) { - hybridView->setDataBind(props->dataBind.value); - props->dataBind.isDirty = false; + if (oldProps == nullptr + ? newProps->dataBind.isProvided() + : !newProps->dataBind.hasSameValue(oldProps->dataBind)) { + hybridView->setDataBind(newProps->dataBind.get()); } - if (props->onError.isDirty) { - hybridView->setOnError(props->onError.value); - props->onError.isDirty = false; + if (oldProps == nullptr + ? newProps->onError.isProvided() + : !newProps->onError.hasSameValue(oldProps->onError)) { + hybridView->setOnError(newProps->onError.get()); } // Update hybridRef if it changed - if (props->hybridRef.isDirty) { + if (oldProps == nullptr + ? newProps->hybridRef.isProvided() + : !newProps->hybridRef.hasSameValue(oldProps->hybridRef)) { // hybridRef changed - call it with new this - const auto& maybeFunc = props->hybridRef.value; + const auto& maybeFunc = newProps->hybridRef.get(); if (maybeFunc.has_value()) { maybeFunc.value()(hybridView); } - props->hybridRef.isDirty = false; } } diff --git a/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.hpp b/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.hpp index 03b58dac..7c978528 100644 --- a/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.hpp +++ b/nitrogen/generated/android/c++/views/JHybridRiveViewStateUpdater.hpp @@ -31,7 +31,12 @@ class JHybridRiveViewStateUpdater final: public jni::JavaClass /* class */, jni::alias_ref view, - jni::alias_ref stateWrapperInterface); + jni::alias_ref newState, + jni::alias_ref oldState); + +private: + static std::shared_ptr getPropsFromStateWrapper( + jni::alias_ref stateWrapper); public: static void registerNatives() { diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewManager.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewManager.kt index 60f16b4a..585f192c 100644 --- a/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewManager.kt +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewManager.kt @@ -20,6 +20,14 @@ import com.margelo.nitro.rive.* * Represents the React Native `ViewManager` for the "RiveView" Nitro HybridView. */ public open class HybridRiveViewManager: SimpleViewManager() { + /** + * Represents the View and its last state snapshot (mutable) + */ + private class HybridViewHolder( + val hybridView: HybridRiveView, + var lastState: StateWrapper? = null, + ) + init { if (RecyclableView::class.java.isAssignableFrom(HybridRiveView::class.java)) { // Enable view recycling @@ -34,33 +42,41 @@ public open class HybridRiveViewManager: SimpleViewManager() { override fun createViewInstance(reactContext: ThemedReactContext): View { val hybridView = HybridRiveView(reactContext) val view = hybridView.view - view.setTag(associated_hybrid_view_tag, hybridView) + view.setTag(associated_hybrid_view_tag, HybridViewHolder(hybridView)) return view } override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? { - val hybridView = getHybridView(view) + val holder = getHybridViewHolder(view) ?: throw Error("Couldn't find view $view in local views table!") + val hybridView = holder.hybridView + val oldState = holder.lastState + val newState = stateWrapper // 1. Update each prop individually hybridView.beforeUpdate() - HybridRiveViewStateUpdater.updateViewProps(hybridView, stateWrapper) + HybridRiveViewStateUpdater.updateViewProps(hybridView, newState, oldState) hybridView.afterUpdate() + holder.lastState = newState // 2. Continue in base View props - return super.updateState(view, props, stateWrapper) + return super.updateState(view, props, newState) } override fun onDropViewInstance(view: View) { - val hybridView = getHybridView(view) - hybridView?.onDropView() + val holder = getHybridViewHolder(view) + holder?.lastState = null + holder?.hybridView?.onDropView() return super.onDropViewInstance(view) } protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? { - super.prepareToRecycleView(reactContext, view) - val hybridView = getHybridView(view) + val preparedView = super.prepareToRecycleView(reactContext, view) + ?: return null + val holder = getHybridViewHolder(preparedView) ?: return null + val hybridView = holder.hybridView + holder.lastState = null @Suppress("USELESS_IS_CHECK") if (hybridView is RecyclableView) { @@ -74,7 +90,7 @@ public open class HybridRiveViewManager: SimpleViewManager() { } } - private fun getHybridView(view: View): HybridRiveView? { - return view.getTag(associated_hybrid_view_tag) as? HybridRiveView + private fun getHybridViewHolder(view: View): HybridViewHolder? { + return view.getTag(associated_hybrid_view_tag) as? HybridViewHolder } } diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewStateUpdater.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewStateUpdater.kt index 0caac58a..b9a15e2f 100644 --- a/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewStateUpdater.kt +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/views/HybridRiveViewStateUpdater.kt @@ -14,10 +14,10 @@ internal class HybridRiveViewStateUpdater { companion object { /** * Updates the props for [view] through C++. - * The [state] prop is expected to contain [view]'s props as wrapped Fabric state. + * The [newState] prop is expected to contain [view]'s props as wrapped Fabric state. */ @Suppress("KotlinJniMissingFunction") @JvmStatic - external fun updateViewProps(view: HybridRiveViewSpec, state: StateWrapper) + external fun updateViewProps(view: HybridRiveViewSpec, newState: StateWrapper, oldState: StateWrapper?) } } diff --git a/nitrogen/generated/ios/c++/views/HybridRiveViewComponent.mm b/nitrogen/generated/ios/c++/views/HybridRiveViewComponent.mm index 5394f58a..a15875b3 100644 --- a/nitrogen/generated/ios/c++/views/HybridRiveViewComponent.mm +++ b/nitrogen/generated/ios/c++/views/HybridRiveViewComponent.mm @@ -37,12 +37,7 @@ + (BOOL)shouldBeRecycled; @implementation HybridRiveViewComponent { std::shared_ptr _hybridView; - // The cached props' isDirty flags were already consumed by the previous - // view instance when Fabric recreates this view from an unchanged - // ShadowNode, so updateProps would apply nothing and the fresh view would - // stay unconfigured (issue #365). Track whether this instance applied its - // props at least once. - BOOL _didApplyInitialProps; + BOOL _didDropView; } + (void) load { @@ -76,90 +71,115 @@ - (void) updateView { [self setContentView:view]; } +- (void) notifyOnDropView { + // A recycled component can later be invalidated. Notify only once per mount. + if (_didDropView) { + return; + } + RNRive::HybridRiveViewSpec_cxx& swiftPart = _hybridView->getSwiftPart(); + swiftPart.onDropView(); + _didDropView = YES; +} + - (void) updateProps:(const std::shared_ptr&)props oldProps:(const std::shared_ptr&)oldProps { + // A props update marks a newly mounted or still-active component. + _didDropView = NO; + // 1. Downcast props - const auto& newViewPropsConst = *std::static_pointer_cast(props); - auto& newViewProps = const_cast(newViewPropsConst); + const auto& newViewProps = *std::static_pointer_cast(props); + const auto* oldViewProps = static_cast(oldProps.get()); RNRive::HybridRiveViewSpec_cxx& swiftPart = _hybridView->getSwiftPart(); - // Force-apply all props the first time this view instance updates (see - // _didApplyInitialProps above). - const bool force = !_didApplyInitialProps; - _didApplyInitialProps = YES; - - // 2. Update each prop individually - swiftPart.beforeUpdate(); - - // artboardName: optional - if (force || newViewProps.artboardName.isDirty) { - swiftPart.setArtboardName(newViewProps.artboardName.value); - newViewProps.artboardName.isDirty = false; - } - // stateMachineName: optional - if (force || newViewProps.stateMachineName.isDirty) { - swiftPart.setStateMachineName(newViewProps.stateMachineName.value); - newViewProps.stateMachineName.isDirty = false; - } - // autoPlay: optional - if (force || newViewProps.autoPlay.isDirty) { - swiftPart.setAutoPlay(newViewProps.autoPlay.value); - newViewProps.autoPlay.isDirty = false; - } - // file: hybrid-object - if (force || newViewProps.file.isDirty) { - swiftPart.setFile(newViewProps.file.value); - newViewProps.file.isDirty = false; - } - // alignment: optional - if (force || newViewProps.alignment.isDirty) { - swiftPart.setAlignment(newViewProps.alignment.value); - newViewProps.alignment.isDirty = false; - } - // fit: optional - if (force || newViewProps.fit.isDirty) { - swiftPart.setFit(newViewProps.fit.value); - newViewProps.fit.isDirty = false; - } - // layoutScaleFactor: optional - if (force || newViewProps.layoutScaleFactor.isDirty) { - swiftPart.setLayoutScaleFactor(newViewProps.layoutScaleFactor.value); - newViewProps.layoutScaleFactor.isDirty = false; - } - // frameRate: optional - if (force || newViewProps.frameRate.isDirty) { - swiftPart.setFrameRate(newViewProps.frameRate.value); - newViewProps.frameRate.isDirty = false; - } - // semantics: optional - if (force || newViewProps.semantics.isDirty) { - swiftPart.setSemantics(newViewProps.semantics.value); - newViewProps.semantics.isDirty = false; - } - // dataBind: optional - if (force || newViewProps.dataBind.isDirty) { - swiftPart.setDataBind(newViewProps.dataBind.value); - newViewProps.dataBind.isDirty = false; - } - // onError: function - if (force || newViewProps.onError.isDirty) { - swiftPart.setOnError(newViewProps.onError.value); - newViewProps.onError.isDirty = false; - } - - swiftPart.afterUpdate(); + // 2. Update only props that differ from the previous Props snapshot. + const bool hasTransactionPropChanges = oldViewProps == nullptr + ? newViewProps.hasAnyProvidedProps() + : !newViewProps.hasSameProps(*oldViewProps); + if (hasTransactionPropChanges) { + swiftPart.beforeUpdate(); + + // artboardName: optional + if (oldViewProps == nullptr + ? newViewProps.artboardName.isProvided() + : !newViewProps.artboardName.hasSameValue(oldViewProps->artboardName)) { + swiftPart.setArtboardName(newViewProps.artboardName.get()); + } + // stateMachineName: optional + if (oldViewProps == nullptr + ? newViewProps.stateMachineName.isProvided() + : !newViewProps.stateMachineName.hasSameValue(oldViewProps->stateMachineName)) { + swiftPart.setStateMachineName(newViewProps.stateMachineName.get()); + } + // autoPlay: optional + if (oldViewProps == nullptr + ? newViewProps.autoPlay.isProvided() + : !newViewProps.autoPlay.hasSameValue(oldViewProps->autoPlay)) { + swiftPart.setAutoPlay(newViewProps.autoPlay.get()); + } + // file: hybrid-object + if (oldViewProps == nullptr + ? newViewProps.file.isProvided() + : !newViewProps.file.hasSameValue(oldViewProps->file)) { + swiftPart.setFile(newViewProps.file.get()); + } + // alignment: optional + if (oldViewProps == nullptr + ? newViewProps.alignment.isProvided() + : !newViewProps.alignment.hasSameValue(oldViewProps->alignment)) { + swiftPart.setAlignment(newViewProps.alignment.get()); + } + // fit: optional + if (oldViewProps == nullptr + ? newViewProps.fit.isProvided() + : !newViewProps.fit.hasSameValue(oldViewProps->fit)) { + swiftPart.setFit(newViewProps.fit.get()); + } + // layoutScaleFactor: optional + if (oldViewProps == nullptr + ? newViewProps.layoutScaleFactor.isProvided() + : !newViewProps.layoutScaleFactor.hasSameValue(oldViewProps->layoutScaleFactor)) { + swiftPart.setLayoutScaleFactor(newViewProps.layoutScaleFactor.get()); + } + // frameRate: optional + if (oldViewProps == nullptr + ? newViewProps.frameRate.isProvided() + : !newViewProps.frameRate.hasSameValue(oldViewProps->frameRate)) { + swiftPart.setFrameRate(newViewProps.frameRate.get()); + } + // semantics: optional + if (oldViewProps == nullptr + ? newViewProps.semantics.isProvided() + : !newViewProps.semantics.hasSameValue(oldViewProps->semantics)) { + swiftPart.setSemantics(newViewProps.semantics.get()); + } + // dataBind: optional + if (oldViewProps == nullptr + ? newViewProps.dataBind.isProvided() + : !newViewProps.dataBind.hasSameValue(oldViewProps->dataBind)) { + swiftPart.setDataBind(newViewProps.dataBind.get()); + } + // onError: function + if (oldViewProps == nullptr + ? newViewProps.onError.isProvided() + : !newViewProps.onError.hasSameValue(oldViewProps->onError)) { + swiftPart.setOnError(newViewProps.onError.get()); + } - // 3. Update hybridRef if it changed - if (force || newViewProps.hybridRef.isDirty) { - // hybridRef changed - call it with new this - const auto& maybeFunc = newViewProps.hybridRef.value; - if (maybeFunc.has_value()) { - maybeFunc.value()(_hybridView); + // Update hybridRef if it changed + if (oldViewProps == nullptr + ? newViewProps.hybridRef.isProvided() + : !newViewProps.hybridRef.hasSameValue(oldViewProps->hybridRef)) { + // hybridRef changed - call it with new this + const auto& maybeFunc = newViewProps.hybridRef.get(); + if (maybeFunc.has_value()) { + maybeFunc.value()(_hybridView); + } } - newViewProps.hybridRef.isDirty = false; + + swiftPart.afterUpdate(); } - // 4. Continue in base class + // 3. Continue in base class [super updateProps:props oldProps:oldProps]; } @@ -168,16 +188,15 @@ + (BOOL)shouldBeRecycled { } - (void)prepareForRecycle { + [self notifyOnDropView]; [super prepareForRecycle]; - _didApplyInitialProps = NO; RNRive::HybridRiveViewSpec_cxx& swiftPart = _hybridView->getSwiftPart(); swiftPart.maybePrepareForRecycle(); } #ifdef ENABLE_RCT_COMPONENT_VIEW_INVALIDATE - (void)invalidate { - RNRive::HybridRiveViewSpec_cxx& swiftPart = _hybridView->getSwiftPart(); - swiftPart.onDropView(); + [self notifyOnDropView]; [super invalidate]; } #endif diff --git a/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.cpp b/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.cpp index 9e395852..7dcc14aa 100644 --- a/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.cpp +++ b/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.cpp @@ -7,163 +7,51 @@ #include "HybridRiveViewComponent.hpp" -#if __has_include() -#include -#endif -#if defined(REACT_NATIVE_VERSION_MINOR) && (REACT_NATIVE_VERSION_MAJOR > 0 || REACT_NATIVE_VERSION_MINOR >= 85) -#define RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER 1 -#else -#define RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER 0 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include namespace margelo::nitro::rive::views { + using namespace facebook; + + namespace { + template + nitro::ReactProp fromRawValueAcceptingNull(const char* viewName, const char* propName, + const react::RawProps& rawProps, + const nitro::ReactProp& previousProp) { + const react::RawValue* rawValue = nitro::RawPropsCompat::at(rawProps, propName); + if (rawValue != nullptr) { + auto [runtime, value] = static_cast>(*rawValue); + if (value.isNull()) { + if (previousProp.isProvided() && !previousProp.get().has_value()) { + return previousProp; + } + JSICacheReference cache = JSICache::getOrCreateCache(*runtime); + return nitro::ReactProp(T(std::nullopt), cache.makeShared(jsi::Value::undefined())); + } + } + return nitro::ReactProp::fromRawValue(viewName, propName, rawProps, previousProp); + } + } // namespace + extern const char HybridRiveViewComponentName[] = "RiveView"; HybridRiveViewProps::HybridRiveViewProps(const react::PropsParserContext& context, const HybridRiveViewProps& sourceProps, const react::RawProps& rawProps): react::ViewProps(context, sourceProps, rawProps, filterObjectKeys), - artboardName([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("artboardName", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.artboardName; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.artboardName); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.artboardName); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.artboardName: ") + exc.what()); - } - }()), - stateMachineName([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("stateMachineName", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.stateMachineName; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.stateMachineName); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.stateMachineName); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.stateMachineName: ") + exc.what()); - } - }()), - autoPlay([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("autoPlay", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.autoPlay; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.autoPlay); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.autoPlay); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.autoPlay: ") + exc.what()); - } - }()), - file([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("file", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.file; - const auto& [runtime, value] = (std::pair)*rawValue; - return CachedProp>::fromRawValue(*runtime, value, sourceProps.file); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.file: ") + exc.what()); - } - }()), - alignment([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("alignment", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.alignment; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.alignment); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.alignment); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.alignment: ") + exc.what()); - } - }()), - fit([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("fit", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.fit; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.fit); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.fit); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.fit: ") + exc.what()); - } - }()), - layoutScaleFactor([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("layoutScaleFactor", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.layoutScaleFactor; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.layoutScaleFactor); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.layoutScaleFactor); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.layoutScaleFactor: ") + exc.what()); - } - }()), - frameRate([&]() -> CachedProp>> { - try { - const react::RawValue* rawValue = rawProps.at("frameRate", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.frameRate; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.frameRate); - return CachedProp>>::fromRawValue(*runtime, value, sourceProps.frameRate); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.frameRate: ") + exc.what()); - } - }()), - semantics([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("semantics", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.semantics; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.semantics); - return CachedProp>::fromRawValue(*runtime, value, sourceProps.semantics); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.semantics: ") + exc.what()); - } - }()), - dataBind([&]() -> CachedProp, DataBindMode, DataBindByName>>> { - try { - const react::RawValue* rawValue = rawProps.at("dataBind", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.dataBind; - const auto& [runtime, value] = (std::pair)*rawValue; - if (value.isNull()) return CachedProp, DataBindMode, DataBindByName>>>::fromRawValue(*runtime, jsi::Value::undefined(), sourceProps.dataBind); - return CachedProp, DataBindMode, DataBindByName>>>::fromRawValue(*runtime, value, sourceProps.dataBind); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.dataBind: ") + exc.what()); - } - }()), - onError([&]() -> CachedProp> { - try { - const react::RawValue* rawValue = rawProps.at("onError", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.onError; - const auto& [runtime, value] = (std::pair)*rawValue; - return CachedProp>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.onError); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.onError: ") + exc.what()); - } - }()), - hybridRef([&]() -> CachedProp& /* ref */)>>> { - try { - const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr); - if (rawValue == nullptr) return sourceProps.hybridRef; - const auto& [runtime, value] = (std::pair)*rawValue; - return CachedProp& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef); - } catch (const std::exception& exc) { - throw std::runtime_error(std::string("RiveView.hybridRef: ") + exc.what()); - } - }()) { } + artboardName(fromRawValueAcceptingNull>("RiveView", "artboardName", rawProps, sourceProps.artboardName)), + stateMachineName(fromRawValueAcceptingNull>("RiveView", "stateMachineName", rawProps, sourceProps.stateMachineName)), + autoPlay(fromRawValueAcceptingNull>("RiveView", "autoPlay", rawProps, sourceProps.autoPlay)), + file(nitro::ReactProp>::fromRawValue("RiveView", "file", rawProps, sourceProps.file)), + alignment(fromRawValueAcceptingNull>("RiveView", "alignment", rawProps, sourceProps.alignment)), + fit(fromRawValueAcceptingNull>("RiveView", "fit", rawProps, sourceProps.fit)), + layoutScaleFactor(fromRawValueAcceptingNull>("RiveView", "layoutScaleFactor", rawProps, sourceProps.layoutScaleFactor)), + frameRate(fromRawValueAcceptingNull>>("RiveView", "frameRate", rawProps, sourceProps.frameRate)), + semantics(fromRawValueAcceptingNull>("RiveView", "semantics", rawProps, sourceProps.semantics)), + dataBind(fromRawValueAcceptingNull, DataBindMode, DataBindByName>>>("RiveView", "dataBind", rawProps, sourceProps.dataBind)), + onError(nitro::ReactProp>::fromRawValue("RiveView", "onError", rawProps, sourceProps.onError)), + hybridRef(fromRawValueAcceptingNull& /* ref */)>>>("RiveView", "hybridRef", rawProps, sourceProps.hybridRef)) { } bool HybridRiveViewProps::filterObjectKeys(const std::string& propName) { switch (hashString(propName)) { @@ -183,33 +71,4 @@ namespace margelo::nitro::rive::views { } } - HybridRiveViewComponentDescriptor::HybridRiveViewComponentDescriptor(const react::ComponentDescriptorParameters& parameters) - : ConcreteComponentDescriptor(parameters, -#if RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER - react::RawPropsParser()) {} -#else - react::RawPropsParser(/* useRawPropsJsiValue */ true)) {} -#endif - - std::shared_ptr HybridRiveViewComponentDescriptor::cloneProps(const react::PropsParserContext& context, - const std::shared_ptr& props, - react::RawProps rawProps) const { - // 1. Prepare raw props parser - rawProps.parse(rawPropsParser_); - // 2. Copy props with Nitro's cached copy constructor - return HybridRiveViewShadowNode::Props(context, /* & */ rawProps, props); - } - -#ifdef ANDROID - void HybridRiveViewComponentDescriptor::adopt(react::ShadowNode& shadowNode) const { - // This is called immediately after `ShadowNode` is created, cloned or in progress. - // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++. - auto& concreteShadowNode = static_cast(shadowNode); - const std::shared_ptr& constProps = concreteShadowNode.getConcreteSharedProps(); - const std::shared_ptr& props = std::const_pointer_cast(constProps); - HybridRiveViewState state{props}; - concreteShadowNode.setStateData(std::move(state)); - } -#endif - } // namespace margelo::nitro::rive::views diff --git a/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.hpp b/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.hpp index 564ffcc9..78b11972 100644 --- a/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.hpp +++ b/nitrogen/generated/shared/c++/views/HybridRiveViewComponent.hpp @@ -7,14 +7,15 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include +#include +#include #include #include +#include +#include + +#include #include #include @@ -52,18 +53,50 @@ namespace margelo::nitro::rive::views { const react::RawProps& rawProps); public: - CachedProp> artboardName; - CachedProp> stateMachineName; - CachedProp> autoPlay; - CachedProp> file; - CachedProp> alignment; - CachedProp> fit; - CachedProp> layoutScaleFactor; - CachedProp>> frameRate; - CachedProp> semantics; - CachedProp, DataBindMode, DataBindByName>>> dataBind; - CachedProp> onError; - CachedProp& /* ref */)>>> hybridRef; + nitro::ReactProp> artboardName; + nitro::ReactProp> stateMachineName; + nitro::ReactProp> autoPlay; + nitro::ReactProp> file; + nitro::ReactProp> alignment; + nitro::ReactProp> fit; + nitro::ReactProp> layoutScaleFactor; + nitro::ReactProp>> frameRate; + nitro::ReactProp> semantics; + nitro::ReactProp, DataBindMode, DataBindByName>>> dataBind; + nitro::ReactProp> onError; + nitro::ReactProp& /* ref */)>>> hybridRef; + + [[nodiscard]] + bool hasSameProps(const HybridRiveViewProps& other) const noexcept { + return artboardName.hasSameValue(other.artboardName) && + stateMachineName.hasSameValue(other.stateMachineName) && + autoPlay.hasSameValue(other.autoPlay) && + file.hasSameValue(other.file) && + alignment.hasSameValue(other.alignment) && + fit.hasSameValue(other.fit) && + layoutScaleFactor.hasSameValue(other.layoutScaleFactor) && + frameRate.hasSameValue(other.frameRate) && + semantics.hasSameValue(other.semantics) && + dataBind.hasSameValue(other.dataBind) && + onError.hasSameValue(other.onError) && + hybridRef.hasSameValue(other.hybridRef); + } + + [[nodiscard]] + bool hasAnyProvidedProps() const noexcept { + return artboardName.isProvided() || + stateMachineName.isProvided() || + autoPlay.isProvided() || + file.isProvided() || + alignment.isProvided() || + fit.isProvided() || + layoutScaleFactor.isProvided() || + frameRate.isProvided() || + semantics.isProvided() || + dataBind.isProvided() || + onError.isProvided() || + hybridRef.isProvided(); + } private: static bool filterObjectKeys(const std::string& propName); @@ -72,32 +105,7 @@ namespace margelo::nitro::rive::views { /** * State for the "RiveView" View. */ - class HybridRiveViewState final { - public: - HybridRiveViewState() = default; - explicit HybridRiveViewState(const std::shared_ptr& props): - _props(props) {} - - public: - [[nodiscard]] - const std::shared_ptr& getProps() const { - return _props; - } - - public: -#ifdef ANDROID - HybridRiveViewState(const HybridRiveViewState& /* previousState */, folly::dynamic /* data */) {} - folly::dynamic getDynamic() const { - throw std::runtime_error("HybridRiveViewState does not support folly!"); - } - react::MapBuffer getMapBuffer() const { - throw std::runtime_error("HybridRiveViewState does not support MapBuffer!"); - }; -#endif - - private: - std::shared_ptr _props; - }; + using HybridRiveViewState = nitro::ViewPropsHolderState; /** * The Shadow Node for the "RiveView" View. @@ -110,21 +118,7 @@ namespace margelo::nitro::rive::views { /** * The Component Descriptor for the "RiveView" View. */ - class HybridRiveViewComponentDescriptor final: public react::ConcreteComponentDescriptor { - public: - explicit HybridRiveViewComponentDescriptor(const react::ComponentDescriptorParameters& parameters); - - public: - /** - * A faster path for cloning props - reuses the caching logic from `HybridRiveViewProps`. - */ - std::shared_ptr cloneProps(const react::PropsParserContext& context, - const std::shared_ptr& props, - react::RawProps rawProps) const override; -#ifdef ANDROID - void adopt(react::ShadowNode& shadowNode) const override; -#endif - }; + using HybridRiveViewComponentDescriptor = nitro::ViewComponentDescriptor; /* The actual view for "RiveView" needs to be implemented in platform-specific code. */ diff --git a/package.json b/package.json index 97a87756..9a83ad4c 100644 --- a/package.json +++ b/package.json @@ -101,12 +101,12 @@ "eslint-plugin-prettier": "^5.2.3", "expect": "29.7.0", "jest": "^29.7.0", - "nitrogen": "0.36.5", + "nitrogen": "0.37.1", "prettier": "^3.0.3", "react": "19.0.0", "react-native": "0.79.2", "react-native-builder-bob": "^0.40.10", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "0.37.1", "react-test-renderer": "19.0.0", "release-it": "^17.10.0", "tsd": "^0.33.0", @@ -117,7 +117,7 @@ "@rive-app/canvas": "^2.39.0", "react": "*", "react-native": "*", - "react-native-nitro-modules": ">=0.35.10 <0.37" + "react-native-nitro-modules": ">=0.37.1 <0.38" }, "workspaces": [ "example", diff --git a/scripts/nitrogen-postprocess.ts b/scripts/nitrogen-postprocess.ts index 1f3ec9a8..d11f803c 100644 --- a/scripts/nitrogen-postprocess.ts +++ b/scripts/nitrogen-postprocess.ts @@ -10,10 +10,6 @@ const COMPONENT_FILE = join( ROOT, 'nitrogen/generated/shared/c++/views/HybridRiveViewComponent.cpp' ); -const IOS_COMPONENT_FILE = join( - ROOT, - 'nitrogen/generated/ios/c++/views/HybridRiveViewComponent.mm' -); function makeHybridRiveViewManagerOpen() { if (!existsSync(MANAGER_FILE)) { @@ -48,211 +44,53 @@ function acceptNullForOptionalProps() { } const content = readFileSync(COMPONENT_FILE, 'utf-8'); - if (content.includes('value.isNull()')) { + if (content.includes('fromRawValueAcceptingNull')) { console.log('HybridRiveViewComponent.cpp already accepts null props'); return; } - const pattern = - /^( *)return (CachedProp>)::fromRawValue\(\*runtime, value, (sourceProps\.\w+)\);$/gm; - const updated = content.replace( - pattern, - (match, indent, cachedProp, sourceProp) => - `${indent}if (value.isNull()) return ${cachedProp}::fromRawValue(*runtime, jsi::Value::undefined(), ${sourceProp});\n${match}` - ); - if (content === updated) { + const parseSite = + /nitro::ReactProp<(std::optional<[^\n]+>)>::fromRawValue\(/g; + const anchor = ' using namespace facebook;\n'; + if (!parseSite.test(content) || !content.includes(anchor)) { console.warn( - 'No optional CachedProp parse sites found in HybridRiveViewComponent.cpp — nitrogen output may have changed shape' + 'No optional ReactProp parse sites found in HybridRiveViewComponent.cpp — nitrogen output may have changed shape' ); return; } - - writeFileSync(COMPONENT_FILE, updated); - console.log( - 'Patched HybridRiveViewComponent.cpp to accept null for optional props' - ); -} - -// Fabric can recreate a component view from an unchanged ShadowNode (e.g. -// react-freeze / Suspense re-inserting a previously hidden screen, or a plain -// display:none toggle). Nitro 0.35's isDirty prop flags live on the shared -// Props object and were already consumed by the previous view instance, so the -// recreated view's updateProps applies nothing: no file, no artboard, and a -// hybridRef that never fires (issue #365). Force-apply every prop on a view -// instance's first updateProps. Fixed upstream in nitro 0.37 (the generated -// code diffs old vs new props instead) — drop this when bumping past 0.36. -function forceApplyPropsOnFreshComponentView() { - if (!existsSync(IOS_COMPONENT_FILE)) { - console.warn('HybridRiveViewComponent.mm not found, skipping'); - return; - } - - const content = readFileSync(IOS_COMPONENT_FILE, 'utf-8'); - if (content.includes('_didApplyInitialProps')) { - console.log( - 'HybridRiveViewComponent.mm already force-applies initial props' - ); - return; - } - - const ivarAnchor = `@implementation HybridRiveViewComponent { - std::shared_ptr _hybridView; -}`; - const updatePropsAnchor = ` auto& newViewProps = const_cast(newViewPropsConst); - RNRive::HybridRiveViewSpec_cxx& swiftPart = _hybridView->getSwiftPart(); + parseSite.lastIndex = 0; + + const helper = ` + namespace { + template + nitro::ReactProp fromRawValueAcceptingNull(const char* viewName, const char* propName, + const react::RawProps& rawProps, + const nitro::ReactProp& previousProp) { + const react::RawValue* rawValue = nitro::RawPropsCompat::at(rawProps, propName); + if (rawValue != nullptr) { + auto [runtime, value] = static_cast>(*rawValue); + if (value.isNull()) { + if (previousProp.isProvided() && !previousProp.get().has_value()) { + return previousProp; + } + JSICacheReference cache = JSICache::getOrCreateCache(*runtime); + return nitro::ReactProp(T(std::nullopt), cache.makeShared(jsi::Value::undefined())); + } + } + return nitro::ReactProp::fromRawValue(viewName, propName, rawProps, previousProp); + } + } // namespace `; - const recycleAnchor = `- (void)prepareForRecycle { - [super prepareForRecycle];`; - const dirtyCheck = /if \((newViewProps\.\w+\.isDirty)\) \{/g; - - if ( - !content.includes(ivarAnchor) || - !content.includes(updatePropsAnchor) || - !content.includes(recycleAnchor) || - !dirtyCheck.test(content) - ) { - console.warn( - 'HybridRiveViewComponent.mm anchors not found — nitrogen output may have changed shape' - ); - return; - } - dirtyCheck.lastIndex = 0; const updated = content - .replace( - ivarAnchor, - `@implementation HybridRiveViewComponent { - std::shared_ptr _hybridView; - // The cached props' isDirty flags were already consumed by the previous - // view instance when Fabric recreates this view from an unchanged - // ShadowNode, so updateProps would apply nothing and the fresh view would - // stay unconfigured (issue #365). Track whether this instance applied its - // props at least once. - BOOL _didApplyInitialProps; -}` - ) - .replace( - updatePropsAnchor, - updatePropsAnchor + - ` - // Force-apply all props the first time this view instance updates (see - // _didApplyInitialProps above). - const bool force = !_didApplyInitialProps; - _didApplyInitialProps = YES; -` - ) - .replace(dirtyCheck, 'if (force || $1) {') - .replace( - recycleAnchor, - recycleAnchor + - ` - _didApplyInitialProps = NO;` - ); - - writeFileSync(IOS_COMPONENT_FILE, updated); - console.log( - 'Patched HybridRiveViewComponent.mm to force-apply props on a fresh view' - ); -} - -// nitrogen 0.36 constructs the component descriptor with a plain -// `RawPropsParser()`, which only keeps props as jsi::Values on React Native -// >= 0.85 (older versions default the useRawPropsJsiValue flag to false and -// convert every prop to folly::dynamic). The generated Props constructor then -// casts each RawValue to a jsi::Value pair, which aborts on a dynamic-backed -// value, so mounting any RiveView crashes on RN < 0.85. Force the JSI parser -// where the flag still exists; nitro 0.37 ships the same guard in -// RawPropsCompat::makePropsParser(). -function forceJsiPropsParserOnOlderReactNative() { - if (!existsSync(COMPONENT_FILE)) { - console.warn('HybridRiveViewComponent.cpp not found, skipping'); - return; - } - - const content = readFileSync(COMPONENT_FILE, 'utf-8'); - if (content.includes('RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER')) { - console.log( - 'HybridRiveViewComponent.cpp already forces the JSI props parser' - ); - return; - } - - const ctorPattern = /^( *)react::RawPropsParser\(\)\) \{\}$/m; - const includePattern = /^#include "HybridRiveViewComponent\.hpp"$/m; - if (!ctorPattern.test(content) || !includePattern.test(content)) { - console.warn( - 'RawPropsParser() call site not found in HybridRiveViewComponent.cpp — nitrogen output may have changed shape' - ); - return; - } - - const updated = content - .replace( - includePattern, - `$& - -#if __has_include() -#include -#endif -#if defined(REACT_NATIVE_VERSION_MINOR) && (REACT_NATIVE_VERSION_MAJOR > 0 || REACT_NATIVE_VERSION_MINOR >= 85) -#define RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER 1 -#else -#define RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER 0 -#endif` - ) - .replace( - ctorPattern, - (match, indent) => - `#if RN_HAS_ALWAYS_ON_JSI_PROPS_PARSER -${match} -#else -${indent}react::RawPropsParser(/* useRawPropsJsiValue */ true)) {} -#endif` - ); + .replace(anchor, anchor + helper) + .replace(parseSite, 'fromRawValueAcceptingNull<$1>('); writeFileSync(COMPONENT_FILE, updated); console.log( - 'Patched HybridRiveViewComponent.cpp to force the JSI props parser on RN < 0.85' - ); -} - -// RCTViewComponentView asserts in updateProps that a subclass replaced the -// base ViewProps default in its constructor; React Native 0.87 turns that -// assertion into an uncaught NSInternalInconsistencyException, so every -// RiveView mount aborts on a debug build. nitrogen 0.36 leaves `_props` at the -// base default; nitrogen 0.37 emits this same assignment. -function defaultPropsInComponentViewInit() { - if (!existsSync(IOS_COMPONENT_FILE)) { - console.warn('HybridRiveViewComponent.mm not found, skipping'); - return; - } - - const content = readFileSync(IOS_COMPONENT_FILE, 'utf-8'); - if (content.includes('defaultSharedProps()')) { - console.log('HybridRiveViewComponent.mm already initializes _props'); - return; - } - - const pattern = /^( *)if \(self = \[super init\]\) \{$/m; - if (!pattern.test(content)) { - console.warn( - 'init not found in HybridRiveViewComponent.mm — nitrogen output may have changed shape' - ); - return; - } - - const updated = content.replace( - pattern, - (match, indent) => - `${match}\n${indent} _props = HybridRiveViewShadowNode::defaultSharedProps();` + 'Patched HybridRiveViewComponent.cpp to accept null for optional props' ); - - writeFileSync(IOS_COMPONENT_FILE, updated); - console.log('Patched HybridRiveViewComponent.mm to initialize _props'); } makeHybridRiveViewManagerOpen(); acceptNullForOptionalProps(); -forceApplyPropsOnFreshComponentView(); -forceJsiPropsParserOnOlderReactNative(); -defaultPropsInComponentViewInit(); diff --git a/yarn.lock b/yarn.lock index 8c0484ad..0e8959c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7039,12 +7039,12 @@ __metadata: eslint-plugin-prettier: ^5.2.3 expect: 29.7.0 jest: ^29.7.0 - nitrogen: 0.36.5 + nitrogen: 0.37.1 prettier: ^3.0.3 react: 19.0.0 react-native: 0.79.2 react-native-builder-bob: ^0.40.10 - react-native-nitro-modules: 0.36.5 + react-native-nitro-modules: 0.37.1 react-test-renderer: 19.0.0 release-it: ^17.10.0 tsd: ^0.33.0 @@ -7054,7 +7054,7 @@ __metadata: "@rive-app/canvas": ^2.39.0 react: "*" react-native: "*" - react-native-nitro-modules: ">=0.35.10 <0.37" + react-native-nitro-modules: ">=0.37.1 <0.38" peerDependenciesMeta: "@rive-app/canvas": optional: true @@ -12043,7 +12043,7 @@ __metadata: react-dom: 19.1.0 react-native: 0.81.5 react-native-gesture-handler: 2.29.1 - react-native-nitro-modules: 0.36.5 + react-native-nitro-modules: 0.37.1 react-native-reanimated: 4.1.5 react-native-safe-area-context: ~5.6.0 react-native-screens: ~4.16.0 @@ -12858,7 +12858,7 @@ __metadata: react-dom: 19.2.0 react-native: 0.83.4 react-native-gesture-handler: ~2.29.0 - react-native-nitro-modules: 0.36.5 + react-native-nitro-modules: 0.37.1 react-native-reanimated: 4.2.1 react-native-safe-area-context: ~5.6.2 react-native-screens: ~4.23.0 @@ -12902,7 +12902,7 @@ __metadata: react-native: 0.86.0 react-native-gesture-handler: ~2.32.0 react-native-harness: 1.4.0-rc.1 - react-native-nitro-modules: 0.36.5 + react-native-nitro-modules: 0.37.1 react-native-reanimated: 4.5.0 react-native-safe-area-context: ~5.7.0 react-native-screens: 4.25.2 @@ -17875,18 +17875,18 @@ __metadata: languageName: node linkType: hard -"nitrogen@npm:0.36.5": - version: 0.36.5 - resolution: "nitrogen@npm:0.36.5" +"nitrogen@npm:0.37.1": + version: 0.37.1 + resolution: "nitrogen@npm:0.37.1" dependencies: chalk: ^5.3.0 - react-native-nitro-modules: ^0.36.5 + react-native-nitro-modules: ^0.37.1 ts-morph: ^28.0.0 yargs: ^18.0.0 zod: ^4.4.3 bin: nitrogen: lib/index.js - checksum: 11d56be81f6eb2fca665a6693f626ae9a3210ef8d6bdbe6a68f814aa9649cf409b1f1ca64bf7bfa19119e51ac81805eb5ce36f98a029a23bc4eb23618efd4290 + checksum: 9fbf573709418f0fd170ed078bf7fb836b435ff9a6f926434b073e0286d036f6f9e306c6bc4216e178a0a4d7164eb48a1adca09967ed650052fce967946e4546 languageName: node linkType: hard @@ -19374,13 +19374,13 @@ __metadata: languageName: node linkType: hard -"react-native-nitro-modules@npm:0.36.5, react-native-nitro-modules@npm:^0.36.5": - version: 0.36.5 - resolution: "react-native-nitro-modules@npm:0.36.5" +"react-native-nitro-modules@npm:0.37.1, react-native-nitro-modules@npm:^0.37.1": + version: 0.37.1 + resolution: "react-native-nitro-modules@npm:0.37.1" peerDependencies: react: "*" react-native: "*" - checksum: 4739190a0ffd2a11ed8d506b24fb168fd7d5070617a2a0734e5ac8aa26df5d5a49be6c55b7bf94b8eac8439d896c1c6257f3b04cbfbca06d7d8f0c186c97f2e3 + checksum: ef8a3fbf9b66bc6e5ec9db3aa2f4566600777a5d95e3f897e09e50b2fd33860a1bda4bfa54887709a6fc2ce2cc80a26d9cbb6e77f8c33aea9537c788d089638b languageName: node linkType: hard @@ -19456,7 +19456,7 @@ __metadata: react-native-builder-bob: ^0.40.10 react-native-gesture-handler: 2.29.1 react-native-harness: 1.4.0-rc.1 - react-native-nitro-modules: 0.36.5 + react-native-nitro-modules: 0.37.1 react-native-reanimated: 4.1.5 react-native-safe-area-context: ^5.4.0 react-native-screens: ~4.18.0