-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Native Animated] Support for animated tracking in native driver #17896
Changes from 10 commits
2a3055e
ea5353f
ada41b0
e149b17
9a34873
0590afa
9df5509
bfc6b58
c29611b
27f5d43
a64dbf6
e929b04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* 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 "RCTAnimatedNode.h" | ||
|
||
|
||
@interface RCTTrackingAnimatedNode : RCTAnimatedNode | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 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 "RCTTrackingAnimatedNode.h" | ||
#import "RCTValueAnimatedNode.h" | ||
#import "RCTNativeAnimatedNodesManager.h" | ||
|
||
@implementation RCTTrackingAnimatedNode { | ||
NSNumber *_animationId; | ||
NSNumber *_nodeTag; | ||
NSNumber *_valueNodeTag; | ||
NSMutableDictionary *_animationConfig; | ||
} | ||
|
||
- (instancetype)initWithTag:(NSNumber *)tag | ||
config:(NSDictionary<NSString *, id> *)config | ||
{ | ||
if ((self = [super initWithTag:tag config:config])) { | ||
_animationId = config[@"animationId"]; | ||
_nodeTag = config[@"toValue"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this _toValueNodeTag, kind of confusing which is what because of _valueNodeTag. |
||
_valueNodeTag = config[@"value"]; | ||
_animationConfig = [NSMutableDictionary dictionaryWithDictionary:config[@"animationConfig"]]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)onDetachedFromNode:(RCTAnimatedNode *)parent | ||
{ | ||
[self.manager stopAnimation:_animationId]; | ||
[super onDetachedFromNode:parent]; | ||
} | ||
|
||
- (void)performUpdate | ||
{ | ||
[super performUpdate]; | ||
|
||
// change animation config's "toValue" to reflect updated value of the parent node | ||
RCTValueAnimatedNode *node = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_nodeTag]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: dictionary notation (a[@"b"]) for this and next line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parentNodes is of type |
||
[_animationConfig setValue:@(node.value) forKey:@"toValue"]; | ||
|
||
[self.manager startAnimatingNode:_animationId | ||
nodeTag:_valueNodeTag | ||
config:_animationConfig | ||
endCallback:nil]; | ||
} | ||
|
||
@end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call this
updateAnimationConfig
instead since it doesn't "reset" the animation completely but only updates certain parameters.