Skip to content

Commit

Permalink
Support for [email protected] (#4913)
Browse files Browse the repository at this point in the history
## Summary

The PR adds support for [email protected].

### Related changes in react-native

#### Paper

```
* What went wrong:
A problem occurred configuring project ':react-native-reanimated'.
> defaultConfig contains custom BuildConfig fields, but the feature is disabled.
  To enable the feature, add the following to your module-level build.gradle:
  `android.buildFeatures.buildConfig true`
```
According to documentation, we can do it safely -
https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/BuildFeatures#buildConfig:kotlin.Boolean

- facebook/react-native#40748


#### Fabric

-
https://github.com/facebook/react-native/pull/37588/files#diff-1aaade82ec15d197d2785561ee85f90029c7ebb46e75bc4a24967da1fc1cc041
-
https://github.com/facebook/react-native/pull/36609/files#diff-e8a960fbc5a09cea2611fa92b7791c749c3fce1d02b614694d203d9712e97aa4
-
https://github.com/facebook/react-native/pull/38276/files#diff-f53e9cf2e2c954166cb7a3cab84622f14af9eb3949dc1f29f76e4693a9e9cbde
-
https://github.com/facebook/react-native/pull/36395/files#diff-2b25a23f0ed5ac2cf193ff05df77004c3eae39d5966e86a06d383f707d364cc8
-
facebook/react-native@33ebb5d#diff-efac1ff476300ebbe947340c1864ad44dae2ae4f24ab7837395b337303db6313


### Backward compatibility
<img width="306" alt="image"
src="https://github.com/software-mansion/react-native-reanimated/assets/36106620/94f37f2f-b46f-4878-aae4-dd04b3a438f9">

---------

Co-authored-by: Tomek Zawadzki <[email protected]>
Co-authored-by: Michał Mąka <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2023
1 parent 2c91519 commit fe587cf
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 29 deletions.
4 changes: 4 additions & 0 deletions Common/cpp/Fabric/ReanimatedCommitHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ ReanimatedCommitHook::~ReanimatedCommitHook() noexcept {
RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
ShadowTree const &,
RootShadowNode::Shared const &,
#if REACT_NATIVE_MINOR_VERSION >= 73
RootShadowNode::Unshared const &newRootShadowNode) noexcept {
#else
RootShadowNode::Unshared const &newRootShadowNode) const noexcept {
#endif
if (ReanimatedCommitMarker::isReanimatedCommit()) {
// ShadowTree commited by Reanimated, no need to apply updates from
// PropsRegistry
Expand Down
11 changes: 11 additions & 0 deletions Common/cpp/Fabric/ReanimatedCommitHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class ReanimatedCommitHook : public UIManagerCommitHook {

~ReanimatedCommitHook() noexcept override;

#if REACT_NATIVE_MINOR_VERSION >= 73
void commitHookWasRegistered(UIManager const &) noexcept override {}

void commitHookWasUnregistered(UIManager const &) noexcept override {}

RootShadowNode::Unshared shadowTreeWillCommit(
ShadowTree const &shadowTree,
RootShadowNode::Shared const &oldRootShadowNode,
RootShadowNode::Unshared const &newRootShadowNode) noexcept override;
#else
void commitHookWasRegistered(UIManager const &) const noexcept override {}

void commitHookWasUnregistered(UIManager const &) const noexcept override {}
Expand All @@ -28,6 +38,7 @@ class ReanimatedCommitHook : public UIManagerCommitHook {
RootShadowNode::Shared const &oldRootShadowNode,
RootShadowNode::Unshared const &newRootShadowNode)
const noexcept override;
#endif

private:
std::shared_ptr<PropsRegistry> propsRegistry_;
Expand Down
1 change: 0 additions & 1 deletion Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#ifndef NDEBUG
#include <utility>
#include "JSLogger.h"
#endif

namespace reanimated {
Expand Down
27 changes: 18 additions & 9 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#endif
#include <react/renderer/uimanager/UIManagerBinding.h>
#include <react/renderer/uimanager/primitives.h>
#if REACT_NATIVE_MINOR_VERSION >= 73 && defined(RCT_NEW_ARCH_ENABLED)
#include <react/utils/CoreFeatures.h>
#endif
#endif

#include <functional>
Expand All @@ -30,12 +33,13 @@
#include <fbjni/fbjni.h>
#endif

#ifndef NDEBUG
#include "JSLogger.h"
#endif

using namespace facebook;

#if REACT_NATIVE_MINOR_VERSION >= 73 && defined(RCT_NEW_ARCH_ENABLED)
// Android can't find the definition of this static field
bool CoreFeatures::useNativeState;
#endif

namespace reanimated {

NativeReanimatedModule::NativeReanimatedModule(
Expand Down Expand Up @@ -313,7 +317,7 @@ void NativeReanimatedModule::setShouldAnimateExiting(
const jsi::Value &viewTag,
const jsi::Value &shouldAnimate) {
layoutAnimationsManager_.setShouldAnimateExiting(
viewTag.asNumber(), shouldAnimate.asBool());
viewTag.asNumber(), shouldAnimate.getBool());
}

bool NativeReanimatedModule::isAnyHandlerWaitingForEvent(
Expand Down Expand Up @@ -416,16 +420,20 @@ bool NativeReanimatedModule::handleRawEvent(
// just ignore this event, because it's an event on unmounted component
return false;
}
const std::string &type = rawEvent.type;
const ValueFactory &payloadFactory = rawEvent.payloadFactory;

int tag = eventTarget->getTag();
std::string eventType = type;
auto eventType = rawEvent.type;
if (eventType.rfind("top", 0) == 0) {
eventType = "on" + eventType.substr(3);
}
jsi::Runtime &rt = uiWorkletRuntime_->getJSIRuntime();
#if REACT_NATIVE_MINOR_VERSION >= 73
const auto &eventPayload = rawEvent.eventPayload;
jsi::Value payload = eventPayload->asJSIValue(rt);
#else
const auto &payloadFactory = rawEvent.payloadFactory;
jsi::Value payload = payloadFactory(rt);
#endif

auto res = handleEvent(eventType, tag, std::move(payload), currentTime);
// TODO: we should call performOperations conditionally if event is handled
Expand Down Expand Up @@ -638,7 +646,8 @@ void NativeReanimatedModule::initializeFabric(
commitHook_ =
std::make_shared<ReanimatedCommitHook>(propsRegistry_, uiManager_);
#if REACT_NATIVE_MINOR_VERSION >= 73
mountHook_ = std::make_shared<ReanimatedMountHook>(propsRegistry, uiManager_);
mountHook_ =
std::make_shared<ReanimatedMountHook>(propsRegistry_, uiManager_);
#endif
}
#endif // RCT_NEW_ARCH_ENABLED
Expand Down
21 changes: 10 additions & 11 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
#include <hermes/hermes.h>
#endif

#include <hermes/inspector/RuntimeAdapter.h>
#include <hermes/inspector/chrome/Registration.h>

namespace reanimated {

using namespace facebook;
using namespace react;
#if REACT_NATIVE_MINOR_VERSION >= 73
using namespace facebook::hermes::inspector_modern;
#else
using namespace facebook::hermes::inspector;
#endif

#if HERMES_ENABLE_DEBUGGER

class HermesExecutorRuntimeAdapter
: public facebook::hermes::inspector::RuntimeAdapter {
class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
public:
explicit HermesExecutorRuntimeAdapter(
facebook::hermes::HermesRuntime &hermesRuntime,
Expand Down Expand Up @@ -81,11 +82,9 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
auto adapter =
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
#if REACT_NATIVE_MINOR_VERSION >= 71
debugToken_ = facebook::hermes::inspector::chrome::enableDebugging(
std::move(adapter), name);
debugToken_ = chrome::enableDebugging(std::move(adapter), name);
#else
facebook::hermes::inspector::chrome::enableDebugging(
std::move(adapter), name);
chrome::enableDebugging(std::move(adapter), name);
#endif // REACT_NATIVE_MINOR_VERSION
#else
// This is required by iOS, because there is an assertion in the destructor
Expand Down Expand Up @@ -127,9 +126,9 @@ ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
#if HERMES_ENABLE_DEBUGGER
// We have to disable debugging before the runtime is destroyed.
#if REACT_NATIVE_MINOR_VERSION >= 71
facebook::hermes::inspector::chrome::disableDebugging(debugToken_);
chrome::disableDebugging(debugToken_);
#else
facebook::hermes::inspector::chrome::disableDebugging(*runtime_);
chrome::disableDebugging(*runtime_);
#endif // REACT_NATIVE_MINOR_VERSION
#endif // HERMES_ENABLE_DEBUGGER
}
Expand Down
12 changes: 10 additions & 2 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@
#include <hermes/hermes.h>
#endif

#if REACT_NATIVE_MINOR_VERSION >= 71
#if REACT_NATIVE_MINOR_VERSION >= 73
#include <hermes/inspector-modern/chrome/Registration.h>
#else
#include <hermes/inspector/RuntimeAdapter.h>
#include <hermes/inspector/chrome/Registration.h>
#endif

namespace reanimated {

using namespace facebook;
using namespace react;
#if REACT_NATIVE_MINOR_VERSION >= 73
using namespace facebook::hermes::inspector_modern;
#else
using namespace facebook::hermes::inspector;
#endif

// ReentrancyCheck is copied from React Native
// from ReactCommon/hermes/executor/HermesExecutorFactory.cpp
Expand Down Expand Up @@ -127,7 +135,7 @@ class ReanimatedHermesRuntime
ReanimatedReentrancyCheck reentrancyCheck_;
#if HERMES_ENABLE_DEBUGGER
#if REACT_NATIVE_MINOR_VERSION >= 71
facebook::hermes::inspector::chrome::DebugSessionToken debugToken_;
chrome::DebugSessionToken debugToken_;
#endif // REACT_NATIVE_MINOR_VERSION >= 71
#endif // HERMES_ENABLE_DEBUGGER
};
Expand Down
3 changes: 2 additions & 1 deletion Common/cpp/Tools/SingleInstanceChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cxxabi.h>

#include <atomic>
#include <iostream>
#include <string>

Expand Down Expand Up @@ -41,7 +42,7 @@ class SingleInstanceChecker {

// A static field will exist separately for every class template.
// This has to be inline for automatic initialization.
inline static volatile int instanceCount_;
inline static std::atomic<int> instanceCount_;
};

template <class T>
Expand Down
5 changes: 3 additions & 2 deletions RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fabric_flags = fabric_enabled ? '-DRCT_NEW_ARCH_ENABLED' : ''
example_flag = config[:is_reanimated_example_app] ? '-DIS_REANIMATED_EXAMPLE_APP' : ''
version_flag = '-DREANIMATED_VERSION=' + reanimated_package_json["version"]
debug_flag = is_release ? '-DNDEBUG' : ''
ios_min_version = config[:react_native_minor_version] >= 73 ? '10.0' : '9.0'

Pod::Spec.new do |s|

Expand All @@ -30,7 +31,7 @@ Pod::Spec.new do |s|
s.license = "MIT"
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
s.author = { "author" => "[email protected]" }
s.platforms = { :ios => "9.0", :tvos => "9.0", :osx => "10.14" }
s.platforms = { :ios => ios_min_version, :tvos => "9.0", :osx => "10.14" }
s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" }

s.source_files = [
Expand All @@ -45,7 +46,7 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"DEFINES_MODULE" => "YES",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\"",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" \"$(PODS_ROOT)/Headers/Private/Yoga\"",
"FRAMEWORK_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}/React-hermes\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
}
Expand Down
8 changes: 6 additions & 2 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ project(Reanimated)
cmake_minimum_required(VERSION 3.8)

set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 17)
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 73)
set (CMAKE_CXX_STANDARD 20)
else()
set (CMAKE_CXX_STANDARD 17)
endif()

# default CMAKE_CXX_FLAGS: "-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-protector-all"

Expand All @@ -16,7 +20,7 @@ endif()

string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREANIMATED_VERSION=${REANIMATED_VERSION} -DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}")

string(APPEND CMAKE_CXX_FLAGS " -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all -std=c++17 -Wall -Werror")
string(APPEND CMAKE_CXX_FLAGS " -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all -std=c++${CMAKE_CXX_STANDARD} -Wall -Werror")

if(${IS_NEW_ARCHITECTURE_ENABLED})
string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
Expand Down
3 changes: 3 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ android {
if (REACT_NATIVE_MINOR_VERSION > 68) {
prefab true
prefabPublishing true
buildConfig true
}
}

Expand Down Expand Up @@ -363,6 +364,8 @@ android {
if (REANIMATED_MAJOR_VERSION > 2) {
if (REACT_NATIVE_MINOR_VERSION <= 67) {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/67"
} else if (REACT_NATIVE_MINOR_VERSION <= 72) {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/72"
} else {
srcDirs += "src/reactNativeVersionPatch/messageQueueThread/latest"
}
Expand Down
3 changes: 3 additions & 0 deletions android/src/main/cpp/NativeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <react/jni/JMessageQueueThread.h>
#include <react/jni/ReadableNativeArray.h>
#include <react/jni/ReadableNativeMap.h>
#ifdef RCT_NEW_ARCH_ENABLED
#include <react/fabric/Binding.h>
#endif

#include <memory>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/NativeProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#ifdef RCT_NEW_ARCH_ENABLED
#include <react/fabric/JFabricUIManager.h>
#include <react/renderer/scheduler/Scheduler.h>
#endif

#include <ReactCommon/CallInvokerHolder.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.swmansion.reanimated;

import com.facebook.proguard.annotations.DoNotStrip;
import com.swmansion.reanimated.ReanimatedMessageQueueThreadBase;

@DoNotStrip
public class ReanimatedMessageQueueThread extends ReanimatedMessageQueueThreadBase {
@Override
public boolean runOnQueue(Runnable runnable) {
return messageQueueThread.runOnQueue(runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public class ReanimatedMessageQueueThread extends ReanimatedMessageQueueThreadBa
public boolean runOnQueue(Runnable runnable) {
return messageQueueThread.runOnQueue(runnable);
}

@Override
public boolean isIdle() {
return messageQueueThread.isIdle();
}
}
4 changes: 4 additions & 0 deletions apple/LayoutReanimation/REASwizzledUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ - (RCTViewManagerUIBlock)reanimated_uiBlockWithLayoutUpdateForRootView:(RCTRootS
}

RCTUIManager *originalSelf = (RCTUIManager *)self;
#if REACT_NATIVE_MINOR_VERSION >= 73
NSPointerArray *affectedShadowViews = [NSPointerArray weakObjectsPointerArray];
#else
NSHashTable<RCTShadowView *> *affectedShadowViews = [NSHashTable weakObjectsHashTable];
#endif
[rootShadowView layoutWithAffectedShadowViews:affectedShadowViews];

if (!affectedShadowViews.count) {
Expand Down
4 changes: 3 additions & 1 deletion apple/REAModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTFabricSurface.h>
#import <React/RCTRuntimeExecutorFromBridge.h>
#import <React/RCTScheduler.h>
#import <React/RCTSurface.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <React/RCTSurfaceView.h>
#if REACT_NATIVE_MINOR_VERSION < 73
#import <React/RCTRuntimeExecutorFromBridge.h>
#endif
#endif

#ifdef RCT_NEW_ARCH_ENABLED
Expand Down

0 comments on commit fe587cf

Please sign in to comment.