Skip to content

Commit

Permalink
InterpolationAnimatedNode fromDoubleArray should support the string type
Browse files Browse the repository at this point in the history
Summary:
The `NativeAnimationsExample` in Android can not work due to inputRange and outputRange were limited to double array type, which is different from iOS.

So we need let android version to support string array type.
Closes #8900

Differential Revision: D3674754

fbshipit-source-id: e7844f00940bf0fdd6f7f5003dd4eeefa0c317a0
  • Loading branch information
leeight authored and Facebook Github Bot 0 committed Aug 5, 2016
1 parent ce82428 commit 53c1da0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
20 changes: 20 additions & 0 deletions Libraries/Animated/src/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,30 @@ class AnimatedInterpolation extends AnimatedWithChildren {
super.__detach();
}

__transformDataType(range) {
// Change the string array type to number array
// So we can reuse the same logic in iOS and Android platform
return range.map(function (value) {
if (typeof value !== 'string') {
return value;
}
if (/deg$/.test(value)) {
let degrees = parseFloat(value, 10) || 0;
let radians = degrees * Math.PI / 180.0;
return radians;
} else {
// Assume radians
return parseFloat(value, 10) || 0;
}
});
}

__getNativeConfig(): any {
NativeAnimatedHelper.validateInterpolation(this._config);
return {
...this._config,
// Only the `outputRange` can contain strings so we don't need to tranform `inputRange` here
outputRange: this.__transformDataType(this._config.outputRange),
type: 'interpolation',
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ - (instancetype)initWithTag:(NSNumber *)tag
for (id value in config[@"outputRange"]) {
if ([value isKindOfClass:[NSNumber class]]) {
[outputRange addObject:value];
} else if ([value isKindOfClass:[NSString class]]) {
NSString *str = (NSString *)value;
if ([str hasSuffix:@"deg"]) {
double degrees = str.doubleValue;
[outputRange addObject:@(RCTDegreesToRadians(degrees))];
} else {
// Assume radians
[outputRange addObject:@(str.doubleValue)];
}
}
}
_outputRange = [outputRange copy];
Expand Down

0 comments on commit 53c1da0

Please sign in to comment.