Permalink
Browse files

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 #8900

Differential Revision: D3674754

fbshipit-source-id: e7844f00940bf0fdd6f7f5003dd4eeefa0c317a0
  • Loading branch information...
1 parent ce82428 commit 53c1da00477bdcb289292b81226a679e994850f4 @leeight leeight committed with Facebook Github Bot 0 Aug 5, 2016
@@ -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',
};
}
@@ -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];

0 comments on commit 53c1da0

Please sign in to comment.