Skip to content

Commit 82dba51

Browse files
ryangombaFacebook Github Bot 3
authored andcommitted
Modulo node
Summary: This diff adds ModuloAnimatedNode on iOS. It separates out code originally submitted in facebook#9048. Test plan (required) Set up an animation with a modulo node, and `useNativeModule: true`. Compare results with `useNativeModule: false`. Closes facebook#9626 Differential Revision: D3799636 fbshipit-source-id: 594499f11be41bf3ee709249056a3feedeace9eb
1 parent 7db93a3 commit 82dba51

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

Libraries/Animated/src/AnimatedImplementation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,11 @@ class AnimatedModulo extends AnimatedWithChildren {
11761176
this._modulus = modulus;
11771177
}
11781178

1179+
__makeNative() {
1180+
super.__makeNative();
1181+
this._a.__makeNative();
1182+
}
1183+
11791184
__getValue(): number {
11801185
return (this._a.__getValue() % this._modulus + this._modulus) % this._modulus;
11811186
}
@@ -1191,6 +1196,14 @@ class AnimatedModulo extends AnimatedWithChildren {
11911196
__detach(): void {
11921197
this._a.__removeChild(this);
11931198
}
1199+
1200+
__getNativeConfig(): any {
1201+
return {
1202+
type: 'modulus',
1203+
input: this._a.__getNativeTag(),
1204+
modulus: this._modulus,
1205+
};
1206+
}
11941207
}
11951208

11961209
class AnimatedDiffClamp extends AnimatedWithChildren {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTValueAnimatedNode.h"
11+
12+
@interface RCTModuloAnimatedNode : RCTValueAnimatedNode
13+
14+
@end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTModuloAnimatedNode.h"
11+
12+
@implementation RCTModuloAnimatedNode
13+
14+
- (void)performUpdate
15+
{
16+
[super performUpdate];
17+
NSNumber *inputNode = self.config[@"input"];
18+
NSNumber *modulus = self.config[@"modulus"];
19+
RCTValueAnimatedNode *parent = (RCTValueAnimatedNode *)self.parentNodes[inputNode];
20+
self.value = fmodf(parent.value, modulus.floatValue);
21+
}
22+
23+
@end

Libraries/NativeAnimation/RCTAnimation.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
13E501EE1D07A6C9005F35D8 /* RCTStyleAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E501E31D07A6C9005F35D8 /* RCTStyleAnimatedNode.m */; };
2020
13E501EF1D07A6C9005F35D8 /* RCTTransformAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E501E51D07A6C9005F35D8 /* RCTTransformAnimatedNode.m */; };
2121
13E501F01D07A6C9005F35D8 /* RCTValueAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E501E71D07A6C9005F35D8 /* RCTValueAnimatedNode.m */; };
22+
94DAE3F91D7334A70059942F /* RCTModuloAnimatedNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DAE3F81D7334A70059942F /* RCTModuloAnimatedNode.m */; };
2223
/* End PBXBuildFile section */
2324

2425
/* Begin PBXCopyFilesBuildPhase section */
@@ -59,6 +60,8 @@
5960
13E501E51D07A6C9005F35D8 /* RCTTransformAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTransformAnimatedNode.m; sourceTree = "<group>"; };
6061
13E501E61D07A6C9005F35D8 /* RCTValueAnimatedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTValueAnimatedNode.h; sourceTree = "<group>"; };
6162
13E501E71D07A6C9005F35D8 /* RCTValueAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTValueAnimatedNode.m; sourceTree = "<group>"; };
63+
94DAE3F71D7334A70059942F /* RCTModuloAnimatedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTModuloAnimatedNode.h; sourceTree = "<group>"; };
64+
94DAE3F81D7334A70059942F /* RCTModuloAnimatedNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTModuloAnimatedNode.m; sourceTree = "<group>"; };
6265
/* End PBXFileReference section */
6366

6467
/* Begin PBXFrameworksBuildPhase section */
@@ -91,6 +94,8 @@
9194
13E501DB1D07A6C9005F35D8 /* RCTAnimationDriverNode.m */,
9295
13E501DC1D07A6C9005F35D8 /* RCTInterpolationAnimatedNode.h */,
9396
13E501DD1D07A6C9005F35D8 /* RCTInterpolationAnimatedNode.m */,
97+
94DAE3F71D7334A70059942F /* RCTModuloAnimatedNode.h */,
98+
94DAE3F81D7334A70059942F /* RCTModuloAnimatedNode.m */,
9499
13E501DE1D07A6C9005F35D8 /* RCTMultiplicationAnimatedNode.h */,
95100
13E501DF1D07A6C9005F35D8 /* RCTMultiplicationAnimatedNode.m */,
96101
13E501E01D07A6C9005F35D8 /* RCTPropsAnimatedNode.h */,
@@ -176,6 +181,7 @@
176181
buildActionMask = 2147483647;
177182
files = (
178183
13E501F01D07A6C9005F35D8 /* RCTValueAnimatedNode.m in Sources */,
184+
94DAE3F91D7334A70059942F /* RCTModuloAnimatedNode.m in Sources */,
179185
13E501EE1D07A6C9005F35D8 /* RCTStyleAnimatedNode.m in Sources */,
180186
13E501CC1D07A644005F35D8 /* RCTAnimationUtils.m in Sources */,
181187
13E501CF1D07A644005F35D8 /* RCTNativeAnimatedModule.m in Sources */,

Libraries/NativeAnimation/RCTNativeAnimatedModule.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "RCTConvert.h"
1616
#import "RCTInterpolationAnimatedNode.h"
1717
#import "RCTLog.h"
18+
#import "RCTModuloAnimatedNode.h"
1819
#import "RCTMultiplicationAnimatedNode.h"
1920
#import "RCTPropsAnimatedNode.h"
2021
#import "RCTStyleAnimatedNode.h"
@@ -69,6 +70,7 @@ - (dispatch_queue_t)methodQueue
6970
@"interpolation" : [RCTInterpolationAnimatedNode class],
7071
@"addition" : [RCTAdditionAnimatedNode class],
7172
@"multiplication" : [RCTMultiplicationAnimatedNode class],
73+
@"modulus" : [RCTModuloAnimatedNode class],
7274
@"transform" : [RCTTransformAnimatedNode class]};
7375
});
7476

0 commit comments

Comments
 (0)