mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 05:34:15 +00:00
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:
parent
ce82428b15
commit
53c1da0047
@ -1008,10 +1008,30 @@ class AnimatedInterpolation extends AnimatedWithChildren {
|
|||||||
super.__detach();
|
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 {
|
__getNativeConfig(): any {
|
||||||
NativeAnimatedHelper.validateInterpolation(this._config);
|
NativeAnimatedHelper.validateInterpolation(this._config);
|
||||||
return {
|
return {
|
||||||
...this._config,
|
...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',
|
type: 'interpolation',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,6 @@
|
|||||||
for (id value in config[@"outputRange"]) {
|
for (id value in config[@"outputRange"]) {
|
||||||
if ([value isKindOfClass:[NSNumber class]]) {
|
if ([value isKindOfClass:[NSNumber class]]) {
|
||||||
[outputRange addObject:value];
|
[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];
|
_outputRange = [outputRange copy];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user