RCTTrackingAnimatedNode.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTTrackingAnimatedNode.h>
  8. #import <React/RCTValueAnimatedNode.h>
  9. #import <React/RCTNativeAnimatedNodesManager.h>
  10. @implementation RCTTrackingAnimatedNode {
  11. NSNumber *_animationId;
  12. NSNumber *_toValueNodeTag;
  13. NSNumber *_valueNodeTag;
  14. NSMutableDictionary *_animationConfig;
  15. }
  16. - (instancetype)initWithTag:(NSNumber *)tag
  17. config:(NSDictionary<NSString *, id> *)config
  18. {
  19. if ((self = [super initWithTag:tag config:config])) {
  20. _animationId = config[@"animationId"];
  21. _toValueNodeTag = config[@"toValue"];
  22. _valueNodeTag = config[@"value"];
  23. _animationConfig = [NSMutableDictionary dictionaryWithDictionary:config[@"animationConfig"]];
  24. }
  25. return self;
  26. }
  27. - (void)onDetachedFromNode:(RCTAnimatedNode *)parent
  28. {
  29. [self.manager stopAnimation:_animationId];
  30. [super onDetachedFromNode:parent];
  31. }
  32. - (void)performUpdate
  33. {
  34. [super performUpdate];
  35. // change animation config's "toValue" to reflect updated value of the parent node
  36. RCTValueAnimatedNode *node = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_toValueNodeTag];
  37. _animationConfig[@"toValue"] = @(node.value);
  38. [self.manager startAnimatingNode:_animationId
  39. nodeTag:_valueNodeTag
  40. config:_animationConfig
  41. endCallback:nil];
  42. }
  43. @end