Skip to content

Commit

Permalink
Fork RCTAnimatedModule to unblock brideless mode
Browse files Browse the repository at this point in the history
Summary:
The Animated native module cannot be converted to a TM because it has perf regressions when used in conjunction with Paper renderer. Instead of fixing these complicated perf issues (which will disappear when Fabric ships this half), temporarily fork the native module. The new fork is converted to a TM, and only used to unblock bridgeless mode testing.

Changelog:[Internal]

Reviewed By: RSNara

Differential Revision: D22651010

fbshipit-source-id: 912123ef38ac8c66025b7bba34a65ec6d98f330d
  • Loading branch information
Peter Argany authored and facebook-github-bot committed Jul 27, 2020
1 parent 509e9db commit d1c3c2d
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Libraries/Animated/src/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

'use strict';

import NativeAnimatedNonTurboModule from './NativeAnimatedModule';
import NativeAnimatedTurboModule from './NativeAnimatedTurboModule';
import NativeEventEmitter from '../../EventEmitter/NativeEventEmitter';
import Platform from '../../Utilities/Platform';
import type {EventConfig} from './AnimatedEvent';
import NativeAnimatedModule from './NativeAnimatedModule';
import type {
EventMapping,
AnimatedNodeConfig,
Expand All @@ -22,6 +24,12 @@ import type {AnimationConfig, EndCallback} from './animations/Animation';
import type {InterpolationConfigType} from './nodes/AnimatedInterpolation';
import invariant from 'invariant';

// TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%.
const NativeAnimatedModule =
Platform.OS === 'ios' && global.RN$Bridgeless
? NativeAnimatedTurboModule
: NativeAnimatedNonTurboModule;

let __nativeAnimatedNodeTagCount = 1; /* used for animated nodes */
let __nativeAnimationIdCount = 1; /* used for started animations */

Expand Down
18 changes: 18 additions & 0 deletions Libraries/Animated/src/NativeAnimatedTurboModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';
import {Spec} from './NativeAnimatedModule';

export default (TurboModuleRegistry.get<Spec>(
'NativeAnimatedTurboModule',
): ?Spec);
1 change: 1 addition & 0 deletions Libraries/NativeAnimation/RCTAnimationPlugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Class RCTAnimationClassProvider(const char *name);

// Lookup functions
Class RCTNativeAnimatedModuleCls(void) __attribute__((used));
Class RCTNativeAnimatedTurboModuleCls(void) __attribute__((used));

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions Libraries/NativeAnimation/RCTAnimationPlugins.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Class RCTAnimationClassProvider(const char *name) {
static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
{"NativeAnimatedModule", RCTNativeAnimatedModuleCls},
{"NativeAnimatedTurboModule", RCTNativeAnimatedTurboModuleCls},
};

auto p = sCoreModuleClassMap.find(name);
Expand Down
3 changes: 3 additions & 0 deletions Libraries/NativeAnimation/RCTNativeAnimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#import "RCTValueAnimatedNode.h"

// TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%.
// NOTE: This module is temporarily forked (see RCTNativeAnimatedTurboModule).
// When making any changes, be sure to apply them to the fork as well.
@interface RCTNativeAnimatedModule : RCTEventEmitter <RCTBridgeModule, RCTValueAnimatedNodeObserver, RCTEventDispatcherObserver, RCTUIManagerObserver, RCTSurfacePresenterObserver>

@end
4 changes: 2 additions & 2 deletions Libraries/NativeAnimation/RCTNativeAnimatedModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ - (void)setBridge:(RCTBridge *)bridge
}];
}

RCT_EXPORT_METHOD(getValue:(double)nodeTag saveCallback:(RCTResponseSenderBlock)saveCallback) {
RCT_EXPORT_METHOD(getValue:(double)nodeTag saveValueCallback:(RCTResponseSenderBlock)saveValueCallback) {
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
[nodesManager getValue:[NSNumber numberWithDouble:nodeTag] saveCallback:saveCallback];
[nodesManager getValue:[NSNumber numberWithDouble:nodeTag] saveCallback:saveValueCallback];
}];
}

Expand Down
23 changes: 23 additions & 0 deletions Libraries/NativeAnimation/RCTNativeAnimatedTurboModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTSurfacePresenterStub.h>
#import <React/RCTUIManager.h>
#import <React/RCTUIManagerObserverCoordinator.h>
#import <React/RCTUIManagerUtils.h>

#import "RCTValueAnimatedNode.h"

// TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%.
// NOTE: This module is temporarily forked (see RCTNativeAnimatedModule).
// When making any changes, be sure to apply them to the fork as well.
@interface RCTNativeAnimatedTurboModule: RCTEventEmitter <RCTBridgeModule, RCTValueAnimatedNodeObserver, RCTEventDispatcherObserver, RCTUIManagerObserver, RCTSurfacePresenterObserver>

@end
Loading

0 comments on commit d1c3c2d

Please sign in to comment.