RCTValueAnimatedNode.m 999 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/RCTValueAnimatedNode.h>
  8. @interface RCTValueAnimatedNode ()
  9. @property (nonatomic, assign) CGFloat offset;
  10. @end
  11. @implementation RCTValueAnimatedNode
  12. @synthesize value = _value;
  13. - (instancetype)initWithTag:(NSNumber *)tag
  14. config:(NSDictionary<NSString *, id> *)config
  15. {
  16. if (self = [super initWithTag:tag config:config]) {
  17. _offset = [self.config[@"offset"] floatValue];
  18. _value = [self.config[@"value"] floatValue];
  19. }
  20. return self;
  21. }
  22. - (void)flattenOffset
  23. {
  24. _value += _offset;
  25. _offset = 0;
  26. }
  27. - (void)extractOffset
  28. {
  29. _offset += _value;
  30. _value = 0;
  31. }
  32. - (CGFloat)value
  33. {
  34. return _value + _offset;
  35. }
  36. - (void)setValue:(CGFloat)value
  37. {
  38. _value = value;
  39. if (_valueObserver) {
  40. [_valueObserver animatedNode:self didUpdateValue:_value];
  41. }
  42. }
  43. @end