Skip to content

Commit

Permalink
Modulo node
Browse files Browse the repository at this point in the history
Summary:
This diff adds ModuloAnimatedNode on iOS. It separates out code originally submitted in #9048.

Test plan (required)

Set up an animation with a modulo node, and `useNativeModule: true`. Compare results with `useNativeModule: false`.
Closes #9626

Differential Revision: D3799636

fbshipit-source-id: 594499f11be41bf3ee709249056a3feedeace9eb
  • Loading branch information
ryangomba authored and Facebook Github Bot 3 committed Aug 31, 2016
1 parent 7db93a3 commit 82dba51
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Libraries/Animated/src/AnimatedImplementation.js
Expand Up @@ -1176,6 +1176,11 @@ class AnimatedModulo extends AnimatedWithChildren {
this._modulus = modulus;
}

__makeNative() {
super.__makeNative();
this._a.__makeNative();
}

__getValue(): number {
return (this._a.__getValue() % this._modulus + this._modulus) % this._modulus;
}
Expand All @@ -1191,6 +1196,14 @@ class AnimatedModulo extends AnimatedWithChildren {
__detach(): void {
this._a.__removeChild(this);
}

__getNativeConfig(): any {
return {
type: 'modulus',
input: this._a.__getNativeTag(),
modulus: this._modulus,
};
}
}

class AnimatedDiffClamp extends AnimatedWithChildren {
Expand Down
14 changes: 14 additions & 0 deletions Libraries/NativeAnimation/Nodes/RCTModuloAnimatedNode.h
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTValueAnimatedNode.h"

@interface RCTModuloAnimatedNode : RCTValueAnimatedNode

@end
23 changes: 23 additions & 0 deletions Libraries/NativeAnimation/Nodes/RCTModuloAnimatedNode.m
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTModuloAnimatedNode.h"

@implementation RCTModuloAnimatedNode

- (void)performUpdate
{
[super performUpdate];
NSNumber *inputNode = self.config[@"input"];
NSNumber *modulus = self.config[@"modulus"];
RCTValueAnimatedNode *parent = (RCTValueAnimatedNode *)self.parentNodes[inputNode];
self.value = fmodf(parent.value, modulus.floatValue);
}

@end
Expand Up @@ -19,6 +19,7 @@
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 */; };
94DAE3F91D7334A70059942F /* RCTModuloAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DAE3F81D7334A70059942F /* RCTModuloAnimatedNode.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -59,6 +60,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; path = RCTValueAnimatedNode.h; sourceTree = "<group>"; };
13E501E71D07A6C9005F35D8 /* RCTValueAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTValueAnimatedNode.m; sourceTree = "<group>"; };
94DAE3F71D7334A70059942F /* RCTModuloAnimatedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTModuloAnimatedNode.h; sourceTree = "<group>"; };
94DAE3F81D7334A70059942F /* RCTModuloAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTModuloAnimatedNode.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -91,6 +94,8 @@
13E501DB1D07A6C9005F35D8 /* RCTAnimationDriverNode.m */,
13E501DC1D07A6C9005F35D8 /* RCTInterpolationAnimatedNode.h */,
13E501DD1D07A6C9005F35D8 /* RCTInterpolationAnimatedNode.m */,
94DAE3F71D7334A70059942F /* RCTModuloAnimatedNode.h */,
94DAE3F81D7334A70059942F /* RCTModuloAnimatedNode.m */,
13E501DE1D07A6C9005F35D8 /* RCTMultiplicationAnimatedNode.h */,
13E501DF1D07A6C9005F35D8 /* RCTMultiplicationAnimatedNode.m */,
13E501E01D07A6C9005F35D8 /* RCTPropsAnimatedNode.h */,
Expand Down Expand Up @@ -176,6 +181,7 @@
buildActionMask = 2147483647;
files = (
13E501F01D07A6C9005F35D8 /* RCTValueAnimatedNode.m in Sources */,
94DAE3F91D7334A70059942F /* RCTModuloAnimatedNode.m in Sources */,
13E501EE1D07A6C9005F35D8 /* RCTStyleAnimatedNode.m in Sources */,
13E501CC1D07A644005F35D8 /* RCTAnimationUtils.m in Sources */,
13E501CF1D07A644005F35D8 /* RCTNativeAnimatedModule.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/NativeAnimation/RCTNativeAnimatedModule.m
Expand Up @@ -15,6 +15,7 @@
#import "RCTConvert.h"
#import "RCTInterpolationAnimatedNode.h"
#import "RCTLog.h"
#import "RCTModuloAnimatedNode.h"
#import "RCTMultiplicationAnimatedNode.h"
#import "RCTPropsAnimatedNode.h"
#import "RCTStyleAnimatedNode.h"
Expand Down Expand Up @@ -69,6 +70,7 @@ - (dispatch_queue_t)methodQueue
@"interpolation" : [RCTInterpolationAnimatedNode class],
@"addition" : [RCTAdditionAnimatedNode class],
@"multiplication" : [RCTMultiplicationAnimatedNode class],
@"modulus" : [RCTModuloAnimatedNode class],
@"transform" : [RCTTransformAnimatedNode class]};
});

Expand Down

0 comments on commit 82dba51

Please sign in to comment.