Skip to content
Closed
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
9 changes: 2 additions & 7 deletions Libraries/Animated/src/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/
'use strict';

import NativeEventEmitter from '../../EventEmitter/NativeEventEmitter';
import type {
EventMapping,
AnimatedNodeConfig,
AnimatingNodeConfig,
} from './NativeAnimatedModule';
import NativeAnimatedModule from './NativeAnimatedModule';
import RCTDeviceEventEmitter from '../../EventEmitter/RCTDeviceEventEmitter';
import invariant from 'invariant';

import type {AnimationConfig, EndCallback} from './animations/Animation';
Expand All @@ -25,8 +25,6 @@ import type {EventConfig} from './AnimatedEvent';
let __nativeAnimatedNodeTagCount = 1; /* used for animated nodes */
let __nativeAnimationIdCount = 1; /* used for started animations */

let nativeEventEmitter;

let queueConnections = false;
let queue = [];

Expand Down Expand Up @@ -312,9 +310,6 @@ module.exports = {
transformDataType,
// $FlowExpectedError - unsafe getter lint suppresion
get nativeEventEmitter() {
if (!nativeEventEmitter) {
nativeEventEmitter = new NativeEventEmitter(NativeAnimatedModule);
}
return nativeEventEmitter;
return RCTDeviceEventEmitter;
},
};
15 changes: 15 additions & 0 deletions Libraries/NativeAnimation/RCTAnimatedValueChangeEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 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/RCTEventDispatcher.h>

@interface RCTAnimatedValueChangeEvent : NSObject <RCTEvent>

- (instancetype)initWithNodeTag:(NSNumber *)nodeTag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not a viewTag, should we don't implement viewTag property at all and mark viewTag as optional in the protocol.

Copy link
Contributor Author

@janicduplessis janicduplessis Aug 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be possible, we only use viewTag to generate an id for the event based on viewTag + eventName + coalescingKey. We could make view tag optional for events that are not related to views and only use coalescingKey to identify these events. (https://github.com/facebook/react-native/blob/master/React/Base/RCTEventDispatcher.m#L34)

value:(CGFloat)value NS_DESIGNATED_INITIALIZER;

@end
53 changes: 53 additions & 0 deletions Libraries/NativeAnimation/RCTAnimatedValueChangeEvent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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 "RCTAnimatedValueChangeEvent.h"

@implementation RCTAnimatedValueChangeEvent
{
CGFloat _value;
}

@synthesize viewTag = _viewTag;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do not declare this as regular @-properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the _bridge for native modules, it implements properties from the RCTEvent protocol. Based this on other events (https://github.com/facebook/react-native/blob/master/React/Views/RCTScrollView.m#L51)

@synthesize eventName = _eventName;
@synthesize coalescingKey = _coalescingKey;

- (instancetype)initWithNodeTag:(NSNumber *)nodeTag
value:(CGFloat)value
{
if (self = [super init]) {
_eventName = @"onAnimatedValueUpdate";
_viewTag = nodeTag;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RCTEvent protocol is a bit specific to views events but the coalescing logic can be used for any kind of event. Ideally this would not be called viewTag but for now we use this to coalesce events by node tag. It would have also been possible to use coalescingKey instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we make it less specific or simply better? Let's do this. 😄

_coalescingKey = 0;
_value = value;
}
return self;
}

RCT_NOT_IMPLEMENTED(- (instancetype)init)

- (BOOL)canCoalesce
{
return YES;
}

- (RCTAnimatedValueChangeEvent *)coalesceWithEvent:(RCTAnimatedValueChangeEvent *)newEvent
{
return newEvent;
}

+ (NSString *)moduleDotMethod
{
return @"RCTDeviceEventEmitter.emit";
}

- (NSArray *)arguments
{
return @[_eventName, @{@"tag": _viewTag, @"value": @(_value)}];
}

@end
12 changes: 12 additions & 0 deletions Libraries/NativeAnimation/RCTAnimation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
13E501EE1D07A6C9005F35D8 /* RCTStyleAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E501E31D07A6C9005F35D8 /* RCTStyleAnimatedNode.m */; };
13E501EF1D07A6C9005F35D8 /* RCTTransformAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E501E51D07A6C9005F35D8 /* RCTTransformAnimatedNode.m */; };
13E501F01D07A6C9005F35D8 /* RCTValueAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E501E71D07A6C9005F35D8 /* RCTValueAnimatedNode.m */; };
192EE0091F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 192EE0071F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h */; };
192EE00A1F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 192EE0071F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h */; };
192EE00B1F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 192EE0081F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m */; };
192EE00C1F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 192EE0081F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m */; };
192F69811E823F4A008692C7 /* RCTAnimationUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 13E501B71D07A644005F35D8 /* RCTAnimationUtils.h */; };
192F69821E823F4A008692C7 /* RCTNativeAnimatedModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 13E501BD1D07A644005F35D8 /* RCTNativeAnimatedModule.h */; };
192F69831E823F4A008692C7 /* RCTNativeAnimatedNodesManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94DA09161DC7971C00AEA8C9 /* RCTNativeAnimatedNodesManager.h */; };
Expand Down Expand Up @@ -208,6 +212,8 @@
13E501E51D07A6C9005F35D8 /* RCTTransformAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTransformAnimatedNode.m; sourceTree = "<group>"; };
13E501E61D07A6C9005F35D8 /* RCTValueAnimatedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTValueAnimatedNode.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
13E501E71D07A6C9005F35D8 /* RCTValueAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTValueAnimatedNode.m; sourceTree = "<group>"; };
192EE0071F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAnimatedValueChangeEvent.h; sourceTree = "<group>"; };
192EE0081F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAnimatedValueChangeEvent.m; sourceTree = "<group>"; };
193F64F21D776EC6004D1CAA /* RCTDiffClampAnimatedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTDiffClampAnimatedNode.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
193F64F31D776EC6004D1CAA /* RCTDiffClampAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDiffClampAnimatedNode.m; sourceTree = "<group>"; };
194804EB1E975D8E00623005 /* RCTDecayAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDecayAnimation.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -277,6 +283,8 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
192EE0071F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h */,
192EE0081F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m */,
13E501B71D07A644005F35D8 /* RCTAnimationUtils.h */,
13E501B81D07A644005F35D8 /* RCTAnimationUtils.m */,
13E501BD1D07A644005F35D8 /* RCTNativeAnimatedModule.h */,
Expand Down Expand Up @@ -333,6 +341,7 @@
192F698D1E823F4A008692C7 /* RCTModuloAnimatedNode.h in Headers */,
192F698E1E823F4A008692C7 /* RCTMultiplicationAnimatedNode.h in Headers */,
192F698F1E823F4A008692C7 /* RCTPropsAnimatedNode.h in Headers */,
192EE00A1F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h in Headers */,
192F69901E823F4A008692C7 /* RCTStyleAnimatedNode.h in Headers */,
192F69911E823F4A008692C7 /* RCTTransformAnimatedNode.h in Headers */,
192F69921E823F4A008692C7 /* RCTValueAnimatedNode.h in Headers */,
Expand Down Expand Up @@ -360,6 +369,7 @@
1980B7251E80D1C4004DC789 /* RCTModuloAnimatedNode.h in Headers */,
1980B7271E80D1C4004DC789 /* RCTMultiplicationAnimatedNode.h in Headers */,
1980B7291E80D1C4004DC789 /* RCTPropsAnimatedNode.h in Headers */,
192EE0091F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.h in Headers */,
1980B72B1E80D1C4004DC789 /* RCTStyleAnimatedNode.h in Headers */,
1980B72D1E80D1C4004DC789 /* RCTTransformAnimatedNode.h in Headers */,
1980B72F1E80D1C4004DC789 /* RCTValueAnimatedNode.h in Headers */,
Expand Down Expand Up @@ -460,6 +470,7 @@
2D3B5EFC1D9B0B4800451313 /* RCTMultiplicationAnimatedNode.m in Sources */,
44DB7D982024F75100588FCD /* RCTTrackingAnimatedNode.m in Sources */,
2D3B5EFD1D9B0B4800451313 /* RCTPropsAnimatedNode.m in Sources */,
192EE00C1F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m in Sources */,
944244D01DB962DA0032A02B /* RCTFrameAnimation.m in Sources */,
944244D11DB962DC0032A02B /* RCTSpringAnimation.m in Sources */,
9476E8EC1DC9232D005D5CD1 /* RCTNativeAnimatedNodesManager.m in Sources */,
Expand Down Expand Up @@ -487,6 +498,7 @@
13E501E91D07A6C9005F35D8 /* RCTAnimatedNode.m in Sources */,
44DB7D972024F75100588FCD /* RCTTrackingAnimatedNode.m in Sources */,
13E501EB1D07A6C9005F35D8 /* RCTInterpolationAnimatedNode.m in Sources */,
192EE00B1F54CEA00003D5E2 /* RCTAnimatedValueChangeEvent.m in Sources */,
13E501E81D07A6C9005F35D8 /* RCTAdditionAnimatedNode.m in Sources */,
5C9894951D999639008027DB /* RCTDivisionAnimatedNode.m in Sources */,
13E501EF1D07A6C9005F35D8 /* RCTTransformAnimatedNode.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Libraries/NativeAnimation/RCTNativeAnimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

#import "RCTValueAnimatedNode.h"

@interface RCTNativeAnimatedModule : RCTEventEmitter <RCTBridgeModule, RCTValueAnimatedNodeObserver, RCTEventDispatcherObserver, RCTUIManagerObserver, RCTSurfacePresenterObserver>
@interface RCTNativeAnimatedModule : NSObject <RCTBridgeModule, RCTValueAnimatedNodeObserver, RCTEventDispatcherObserver, RCTUIManagerObserver, RCTSurfacePresenterObserver>

@end
14 changes: 6 additions & 8 deletions Libraries/NativeAnimation/RCTNativeAnimatedModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#import "RCTNativeAnimatedModule.h"

#import "RCTAnimatedValueChangeEvent.h"
#import "RCTNativeAnimatedNodesManager.h"

typedef void (^AnimatedOperation)(RCTNativeAnimatedNodesManager *nodesManager);
Expand All @@ -21,6 +22,8 @@ @implementation RCTNativeAnimatedModule
NSMutableDictionary<NSNumber *, NSNumber *> *_animIdIsManagedByFabric;
}

@synthesize bridge = _bridge;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just serious, is this a special reason to use syntesize here? Why should not use just a ivar?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or why don't add this as a prop to class interface inside this (.m) file?
To me, @syntesize always looks like or something redundant/old-fasioned or something very specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand @synthesize is used to implement properties from a protocol without having to redefine them (https://github.com/facebook/react-native/blob/master/React/Base/RCTBridgeModule.h#L87). It's pretty much used for every native module that needs to access the bridge.


RCT_EXPORT_MODULE();

- (void)invalidate
Expand All @@ -41,7 +44,7 @@ - (dispatch_queue_t)methodQueue

- (void)setBridge:(RCTBridge *)bridge
{
[super setBridge:bridge];
_bridge = bridge;

_nodesManager = [[RCTNativeAnimatedNodesManager alloc] initWithBridge:self.bridge];
_operations = [NSMutableArray new];
Expand Down Expand Up @@ -293,15 +296,10 @@ - (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager

#pragma mark -- Events

- (NSArray<NSString *> *)supportedEvents
{
return @[@"onAnimatedValueUpdate"];
}

- (void)animatedNode:(RCTValueAnimatedNode *)node didUpdateValue:(CGFloat)value
{
[self sendEventWithName:@"onAnimatedValueUpdate"
body:@{@"tag": node.nodeTag, @"value": @(value)}];
RCTAnimatedValueChangeEvent *event = [[RCTAnimatedValueChangeEvent alloc] initWithNodeTag:node.nodeTag value:value];
[self.bridge.eventDispatcher sendEvent:event];
}

- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
Expand Down