Skip to content
Merged
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
4 changes: 4 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def toPlatformFileString(String path) {
return path
}

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def reactNativeRootDir = resolveReactNativeDirectory()

def reactProperties = new Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.util.Log;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.NativeViewHierarchyManager;
Expand All @@ -14,7 +13,7 @@
import javax.annotation.Nullable;

@ReactModule(name = ReanimatedModule.NAME)
public class ReanimatedModule extends ReactContextBaseJavaModule
public class ReanimatedModule extends NativeReanimatedModuleSpec
implements LifecycleEventListener, UIManagerModuleListener {

public static final String NAME = "ReanimatedModule";
Expand Down Expand Up @@ -91,17 +90,19 @@ public NodesManager getNodesManager() {
}

@ReactMethod(isBlockingSynchronousMethod = true)
public void installTurboModule(String valueUnpackerCode) {
public boolean installTurboModule(String valueUnpackerCode) {
// When debugging in chrome the JS context is not available.
// https://github.com/facebook/react-native/blob/v0.67.0-rc.6/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobCollector.java#L25
Utils.isChromeDebugger = getReactApplicationContext().getJavaScriptContextHolder().get() == 0;

if (!Utils.isChromeDebugger) {
this.getNodesManager().initWithContext(getReactApplicationContext(), valueUnpackerCode);
return true;
} else {
Log.w(
"[REANIMATED]",
"Unable to create Reanimated Native Module. You can ignore this message if you are using Chrome Debugger now.");
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* This code was copied from android/build/generated/source/codegen/java/com/swmansion/reanimated/NativeReanimatedModuleSpec.java
* which was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package com.swmansion.reanimated;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;

public abstract class NativeReanimatedModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public static final String NAME = "ReanimatedModule";

public NativeReanimatedModuleSpec(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public @Nonnull String getName() {
return NAME;
}

@ReactMethod(isBlockingSynchronousMethod = true)
@DoNotStrip
public abstract boolean installTurboModule(String valueUnpackerCode);
}
21 changes: 16 additions & 5 deletions apple/REAModule.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import <rnreanimated/rnreanimated.h>
#else
#import <React/RCTBridgeModule.h>
#endif // RCT_NEW_ARCH_ENABLED

#import <RNReanimated/REAAnimationsManager.h>
#import <RNReanimated/REANodesManager.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTUIManager.h>
#import <React/RCTUIManagerObserverCoordinator.h>
#import <React/RCTUIManagerUtils.h>

#import <RNReanimated/REAAnimationsManager.h>
#import <RNReanimated/REANodesManager.h>

@interface REAModule : RCTEventEmitter <RCTBridgeModule, RCTEventDispatcherObserver, RCTUIManagerObserver>
@interface REAModule : RCTEventEmitter
#ifdef RCT_NEW_ARCH_ENABLED
<NativeReanimatedModuleSpec,
#else
<RCTBridgeModule,
#endif // RCT_NEW_ARCH_ENABLED
RCTEventDispatcherObserver,
RCTUIManagerObserver>

@property (nonatomic, readonly) REANodesManager *nodesManager;
@property REAAnimationsManager *animationsManager;

#ifdef RCT_NEW_ARCH_ENABLED
- (void)installReanimatedAfterReload;
#endif
#endif // RCT_NEW_ARCH_ENABLED

@end
26 changes: 17 additions & 9 deletions apple/REAModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#import <React/RCTSurfaceView.h>
#if REACT_NATIVE_MINOR_VERSION < 73
#import <React/RCTRuntimeExecutorFromBridge.h>
#endif
#endif
#endif // REACT_NATIVE_MINOR_VERSION < 73
#endif // RCT_NEW_ARCH_ENABLED

#ifdef RCT_NEW_ARCH_ENABLED
#import <RNReanimated/REAInitializerRCTFabricSurface.h>
#endif
#endif // RCT_NEW_ARCH_ENABLED

#import <RNReanimated/NativeProxy.h>
#import <RNReanimated/REAModule.h>
Expand All @@ -28,7 +28,7 @@

#if __has_include(<UIKit/UIAccessibility.h>)
#import <UIKit/UIAccessibility.h>
#endif
#endif // __has_include(<UIKit/UIAccessibility.h>)

using namespace facebook::react;
using namespace reanimated;
Expand All @@ -46,18 +46,18 @@ - (void)_tryAndHandleError:(dispatch_block_t)block;
static __strong REAInitializerRCTFabricSurface *reaSurface;
#else
typedef void (^AnimatedOperation)(REANodesManager *nodesManager);
#endif
#endif // RCT_NEW_ARCH_ENABLED

@implementation REAModule {
#ifdef RCT_NEW_ARCH_ENABLED
__weak RCTSurfacePresenter *_surfacePresenter;
std::weak_ptr<NativeReanimatedModule> weakNativeReanimatedModule_;
#else
NSMutableArray<AnimatedOperation> *_operations;
#endif
#endif // RCT_NEW_ARCH_ENABLED
#ifndef NDEBUG
SingleInstanceChecker<REAModule> singleInstanceChecker_;
#endif
#endif // NDEBUG
bool hasListeners;
}

Expand All @@ -74,7 +74,7 @@ - (void)invalidate
{
#ifdef RCT_NEW_ARCH_ENABLED
[[NSNotificationCenter defaultCenter] removeObserver:self];
#endif
#endif // RCT_NEW_ARCH_ENABLED
[_nodesManager invalidate];
[super invalidate];
}
Expand Down Expand Up @@ -171,7 +171,7 @@ - (void)setBridge:(RCTBridge *)bridge
[_surfacePresenter registerSurface:reaSurface];
}
reaSurface.reaModule = self;
#endif
#endif // NDEBUG

if (_surfacePresenter == nil) {
// _surfacePresenter will be set in installReanimatedAfterReload
Expand Down Expand Up @@ -290,4 +290,12 @@ - (void)sendEventWithName:(NSString *)eventName body:(id)body
return nil;
}

#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeReanimatedModuleSpecJSI>(params);
}
#endif // RCT_NEW_ARCH_ENABLED

@end
6 changes: 3 additions & 3 deletions apple/REANodesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTSurfacePresenterStub.h>
#endif
#endif // RCT_NEW_ARCH_ENABLED

#import <RNReanimated/READisplayLink.h>

Expand Down Expand Up @@ -33,7 +33,7 @@ typedef void (^REAPerformOperations)();
surfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter;
#else
- (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIManager *)uiManager;
#endif
#endif // RCT_NEW_ARCH_ENABLED
- (void)invalidate;
- (void)operationsBatchDidComplete;

Expand All @@ -57,7 +57,7 @@ typedef void (^REAPerformOperations)();
nativeProps:(NSMutableDictionary *)nativeProps
trySynchronously:(BOOL)trySync;
- (NSString *)obtainProp:(nonnull NSNumber *)viewTag propName:(nonnull NSString *)propName;
#endif
#endif // RCT_NEW_ARCH_ENABLED
- (void)maybeFlushUIUpdatesQueue;

@end
28 changes: 14 additions & 14 deletions apple/REANodesManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#import <react/renderer/uimanager/UIManager.h>
#else
#import <stdatomic.h>
#endif
#endif // RCT_NEW_ARCH_ENABLED

#if __has_include(<RNScreens/RNSScreenStackHeaderConfig.h>)
#import <RNScreens/RNSScreenStackHeaderConfig.h>
#endif
#endif // __has_include(<RNScreens/RNSScreenStackHeaderConfig.h>)

#ifdef RCT_NEW_ARCH_ENABLED
using namespace facebook::react;
#endif
#endif // RCT_NEW_ARCH_ENABLED

// Interface below has been added in order to use private methods of RCTUIManager,
// RCTUIManager#UpdateView is a React Method which is exported to JS but in
Expand Down Expand Up @@ -148,7 +148,7 @@ - (BOOL)uiManager:(RCTUIManager *)manager performMountingWithBlock:(RCTUIManager

@end

#endif
#endif // RCT_NEW_ARCH_ENABLED

@implementation REANodesManager {
READisplayLink *_displayLink;
Expand All @@ -166,7 +166,7 @@ @implementation REANodesManager {
#else
NSMutableArray<REANativeAnimationOp> *_operationsInBatch;
volatile atomic_bool _shouldFlushUpdateBuffer;
#endif
#endif // RCT_NEW_ARCH_ENABLED
}

- (READisplayLink *)getDisplayLink
Expand All @@ -177,7 +177,7 @@ - (READisplayLink *)getDisplayLink
_displayLink = [READisplayLink displayLinkWithTarget:self selector:@selector(onAnimationFrame:)];
#if !TARGET_OS_OSX
_displayLink.preferredFramesPerSecond = 120; // will fallback to 60 fps for devices without Pro Motion display
#endif
#endif // TARGET_OS_OSX
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
return _displayLink;
Expand Down Expand Up @@ -226,7 +226,7 @@ - (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIMan
_viewRegistry = [_uiManager valueForKey:@"_viewRegistry"];
_shouldFlushUpdateBuffer = false;
}
#endif
#endif // RCT_NEW_ARCH_ENABLED
[self useDisplayLinkOnMainQueue:^(READisplayLink *displayLink) {
[displayLink setPaused:YES];
}];
Expand All @@ -247,7 +247,7 @@ - (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
{
_surfacePresenter = surfacePresenter;
}
#endif
#endif // RCT_NEW_ARCH_ENABLED

- (void)operationsBatchDidComplete
{
Expand Down Expand Up @@ -279,7 +279,7 @@ - (void)registerPerformOperations:(REAPerformOperations)performOperations
{
_performOperations = performOperations;
}
#endif
#endif // RCT_NEW_ARCH_ENABLED

- (void)startUpdatingOnAnimationFrame
{
Expand Down Expand Up @@ -360,7 +360,7 @@ - (void)performOperations
}
}
_wantRunUpdates = NO;
#endif
#endif // RCT_NEW_ARCH_ENABLED
}

#ifdef RCT_NEW_ARCH_ENABLED
Expand All @@ -378,7 +378,7 @@ - (void)enqueueUpdateViewOnNativeThread:(nonnull NSNumber *)reactTag
[uiManager updateView:reactTag viewName:viewName props:nativeProps];
}];
}
#endif
#endif // RCT_NEW_ARCH_ENABLED

- (void)dispatchEvent:(id<RCTEvent>)event
{
Expand Down Expand Up @@ -406,7 +406,7 @@ - (void)configureUiProps:(nonnull NSSet<NSString *> *)uiPropsSet
_uiProps = uiPropsSet;
_nativeProps = nativePropsSet;
}
#endif
#endif // RCT_NEW_ARCH_ENABLED

- (BOOL)isNativeViewMounted:(NSNumber *)viewTag
{
Expand All @@ -418,7 +418,7 @@ - (BOOL)isNativeViewMounted:(NSNumber *)viewTag
if ([view isKindOfClass:[RNSScreenStackHeaderConfig class]]) {
return ((RNSScreenStackHeaderConfig *)view).screenView != nil;
}
#endif
#endif // __has_include(<RNScreens/RNSScreenStackHeaderConfig.h>)
return NO;
}

Expand Down Expand Up @@ -529,7 +529,7 @@ - (NSString *)obtainProp:(nonnull NSNumber *)viewTag propName:(nonnull NSString
CGFloat alpha = view.alpha;
#else
CGFloat alpha = view.alphaValue;
#endif
#endif // TARGET_OS_OSX
result = [@(alpha) stringValue];
} else if ([propName isEqualToString:@"zIndex"]) {
NSInteger zIndex = view.reactZIndex;
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@
"typescript"
]
},
"codegenConfig": {
"name": "rnreanimated",
"type": "modules",
"jsSrcsDir": "./src/specs",
"android": {
"javaPackageName": "com.swmansion.reanimated"
}
},
"sideEffects": [
"./lib/reanimated2/core",
"./lib/index"
Expand Down
13 changes: 7 additions & 6 deletions src/createAnimatedComponent/JSPropsUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';
import {
NativeEventEmitter,
NativeModules,
findNodeHandle,
} from 'react-native';
import { NativeEventEmitter, Platform, findNodeHandle } from 'react-native';
import type { NativeModule } from 'react-native';
import { shouldBeUseWeb } from '../reanimated2/PlatformChecker';
import type { StyleProps } from '../reanimated2';
import { runOnJS, runOnUIImmediately } from '../reanimated2/threads';
Expand All @@ -13,6 +10,7 @@ import type {
IJSPropsUpdater,
InitialComponentProps,
} from './commonTypes';
import NativeReanimatedModule from '../specs/NativeReanimatedModule';

interface ListenerData {
viewTag: number;
Expand All @@ -27,7 +25,10 @@ class JSPropsUpdaterPaper implements IJSPropsUpdater {

constructor() {
this._reanimatedEventEmitter = new NativeEventEmitter(
NativeModules.ReanimatedModule
// NativeEventEmitter only uses this parameter on iOS.
Platform.OS === 'ios'
? (NativeReanimatedModule as unknown as NativeModule)
: undefined
);
}

Expand Down
Loading