RCTDivisionAnimatedNode.m 981 B

123456789101112131415161718192021222324252627282930313233
  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/RCTDivisionAnimatedNode.h>
  8. #import <React/RCTLog.h>
  9. @implementation RCTDivisionAnimatedNode
  10. - (void)performUpdate
  11. {
  12. [super performUpdate];
  13. NSArray<NSNumber *> *inputNodes = self.config[@"input"];
  14. if (inputNodes.count > 1) {
  15. RCTValueAnimatedNode *parent1 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[0]];
  16. RCTValueAnimatedNode *parent2 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[1]];
  17. if ([parent1 isKindOfClass:[RCTValueAnimatedNode class]] &&
  18. [parent2 isKindOfClass:[RCTValueAnimatedNode class]]) {
  19. if (parent2.value == 0) {
  20. RCTLogError(@"Detected a division by zero in Animated.divide node");
  21. return;
  22. }
  23. self.value = parent1.value / parent2.value;
  24. }
  25. }
  26. }
  27. @end