Value offsets
Summary: This diff adds support for value offsets on iOS. It separates out code originally submitted in #9048. Test plan (required) Set up an animation with an offset, and `useNativeModule: true`. Compare results with `useNativeModule: false`. Closes https://github.com/facebook/react-native/pull/9627 Differential Revision: D3924410 fbshipit-source-id: 8177a25a5f6b9e33f00ea66143c782aeea24507d
This commit is contained in:
parent
7a02b400be
commit
9462a73189
|
@ -727,6 +727,9 @@ class AnimatedValue extends AnimatedWithChildren {
|
|||
*/
|
||||
setOffset(offset: number): void {
|
||||
this._offset = offset;
|
||||
if (this.__isNative) {
|
||||
NativeAnimatedAPI.setAnimatedNodeOffset(this.__getNativeTag(), offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -736,6 +739,9 @@ class AnimatedValue extends AnimatedWithChildren {
|
|||
flattenOffset(): void {
|
||||
this._value += this._offset;
|
||||
this._offset = 0;
|
||||
if (this.__isNative) {
|
||||
NativeAnimatedAPI.flattenAnimatedNodeOffset(this.__getNativeTag());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,6 +65,14 @@ const API = {
|
|||
assertNativeAnimatedModule();
|
||||
NativeAnimatedModule.setAnimatedNodeValue(nodeTag, value);
|
||||
},
|
||||
setAnimatedNodeOffset: function(nodeTag: number, offset: number): void {
|
||||
assertNativeAnimatedModule();
|
||||
NativeAnimatedModule.setAnimatedNodeOffset(nodeTag, offset);
|
||||
},
|
||||
flattenAnimatedNodeOffset: function(nodeTag: number): void {
|
||||
assertNativeAnimatedModule();
|
||||
NativeAnimatedModule.flattenAnimatedNodeOffset(nodeTag);
|
||||
},
|
||||
connectAnimatedNodeToView: function(nodeTag: number, viewTag: number): void {
|
||||
assertNativeAnimatedModule();
|
||||
NativeAnimatedModule.connectAnimatedNodeToView(nodeTag, viewTag);
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
@interface RCTValueAnimatedNode : RCTAnimatedNode
|
||||
|
||||
- (void)setOffset:(CGFloat)offset;
|
||||
- (void)flattenOffset;
|
||||
|
||||
@property (nonatomic, assign) CGFloat value;
|
||||
@property (nonatomic, weak) id<RCTValueAnimatedNodeObserver> valueObserver;
|
||||
|
||||
|
|
|
@ -9,8 +9,37 @@
|
|||
|
||||
#import "RCTValueAnimatedNode.h"
|
||||
|
||||
@interface RCTValueAnimatedNode ()
|
||||
|
||||
@property (nonatomic, assign) CGFloat offset;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTValueAnimatedNode
|
||||
|
||||
@synthesize value = _value;
|
||||
|
||||
- (instancetype)initWithTag:(NSNumber *)tag
|
||||
config:(NSDictionary<NSString *, id> *)config
|
||||
{
|
||||
if (self = [super initWithTag:tag config:config]) {
|
||||
_offset = [self.config[@"offset"] floatValue];
|
||||
_value = [self.config[@"value"] floatValue];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)flattenOffset
|
||||
{
|
||||
_value += _offset;
|
||||
_offset = 0;
|
||||
}
|
||||
|
||||
- (CGFloat)value
|
||||
{
|
||||
return _value + _offset;
|
||||
}
|
||||
|
||||
- (void)setValue:(CGFloat)value
|
||||
{
|
||||
_value = value;
|
||||
|
|
|
@ -175,6 +175,32 @@ RCT_EXPORT_METHOD(setAnimatedNodeValue:(nonnull NSNumber *)nodeTag
|
|||
[valueNode setNeedsUpdate];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setAnimatedNodeOffset:(nonnull NSNumber *)nodeTag
|
||||
offset:(nonnull NSNumber *)offset)
|
||||
{
|
||||
RCTAnimatedNode *node = _animationNodes[nodeTag];
|
||||
if (![node isKindOfClass:[RCTValueAnimatedNode class]]) {
|
||||
RCTLogError(@"Not a value node.");
|
||||
return;
|
||||
}
|
||||
|
||||
RCTValueAnimatedNode *valueNode = (RCTValueAnimatedNode *)node;
|
||||
[valueNode setOffset:offset.floatValue];
|
||||
[_updatedValueNodes addObject:valueNode];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(flattenAnimatedNodeOffset:(nonnull NSNumber *)nodeTag)
|
||||
{
|
||||
RCTAnimatedNode *node = _animationNodes[nodeTag];
|
||||
if (![node isKindOfClass:[RCTValueAnimatedNode class]]) {
|
||||
RCTLogError(@"Not a value node.");
|
||||
return;
|
||||
}
|
||||
|
||||
RCTValueAnimatedNode *valueNode = (RCTValueAnimatedNode *)node;
|
||||
[valueNode flattenOffset];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(connectAnimatedNodeToView:(nonnull NSNumber *)nodeTag
|
||||
viewTag:(nonnull NSNumber *)viewTag)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue