InterpolationAnimatedNode fromDoubleArray should support the string type

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 https://github.com/facebook/react-native/pull/8900

Differential Revision: D3674754

fbshipit-source-id: e7844f00940bf0fdd6f7f5003dd4eeefa0c317a0
This commit is contained in:
leeight 2016-08-05 02:52:30 -07:00 committed by Facebook Github Bot 0
parent ce82428b15
commit 53c1da0047
2 changed files with 20 additions and 9 deletions

View File

@ -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',
};
}

View File

@ -26,15 +26,6 @@
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];