RCTTransformAnimatedNode.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/RCTTransformAnimatedNode.h>
  8. #import <React/RCTValueAnimatedNode.h>
  9. @implementation RCTTransformAnimatedNode
  10. {
  11. NSMutableDictionary<NSString *, NSObject *> *_propsDictionary;
  12. }
  13. - (instancetype)initWithTag:(NSNumber *)tag
  14. config:(NSDictionary<NSString *, id> *)config
  15. {
  16. if ((self = [super initWithTag:tag config:config])) {
  17. _propsDictionary = [NSMutableDictionary new];
  18. }
  19. return self;
  20. }
  21. - (NSDictionary *)propsDictionary
  22. {
  23. return _propsDictionary;
  24. }
  25. - (void)performUpdate
  26. {
  27. [super performUpdate];
  28. NSArray<NSDictionary *> *transformConfigs = self.config[@"transforms"];
  29. NSMutableArray<NSDictionary *> *transform = [NSMutableArray arrayWithCapacity:transformConfigs.count];
  30. for (NSDictionary *transformConfig in transformConfigs) {
  31. NSString *type = transformConfig[@"type"];
  32. NSString *property = transformConfig[@"property"];
  33. NSNumber *value;
  34. if ([type isEqualToString: @"animated"]) {
  35. NSNumber *nodeTag = transformConfig[@"nodeTag"];
  36. RCTAnimatedNode *node = [self.parentNodes objectForKey:nodeTag];
  37. if (![node isKindOfClass:[RCTValueAnimatedNode class]]) {
  38. continue;
  39. }
  40. RCTValueAnimatedNode *parentNode = (RCTValueAnimatedNode *)node;
  41. value = @(parentNode.value);
  42. } else {
  43. value = transformConfig[@"value"];
  44. }
  45. [transform addObject:@{property: value}];
  46. }
  47. _propsDictionary[@"transform"] = transform;
  48. }
  49. @end