diff --git a/Libraries/Animated/src/Interpolation.js b/Libraries/Animated/src/Interpolation.js index 32d363ccbbed51..1539f309f4c327 100644 --- a/Libraries/Animated/src/Interpolation.js +++ b/Libraries/Animated/src/Interpolation.js @@ -75,6 +75,7 @@ class Interpolation { ); var range = findRange(input, inputRange); + var mapping = config.mapping || passThrough; return interpolate( input, inputRange[range], @@ -84,11 +85,16 @@ class Interpolation { easing, extrapolateLeft, extrapolateRight, + mapping, ); }; } } +function passThrough(input: any): any { + return input; +} + function interpolate( input: number, inputMin: number, @@ -98,13 +104,14 @@ function interpolate( easing: ((input: number) => number), extrapolateLeft: ExtrapolateType, extrapolateRight: ExtrapolateType, + mapping: ((input: number) => any) ) { var result = input; // Extrapolate if (result < inputMin) { if (extrapolateLeft === 'identity') { - return result; + return mapping(result); } else if (extrapolateLeft === 'clamp') { result = inputMin; } else if (extrapolateLeft === 'extend') { @@ -114,7 +121,7 @@ function interpolate( if (result > inputMax) { if (extrapolateRight === 'identity') { - return result; + return mapping(result); } else if (extrapolateRight === 'clamp') { result = inputMax; } else if (extrapolateRight === 'extend') { @@ -123,14 +130,14 @@ function interpolate( } if (outputMin === outputMax) { - return outputMin; + return mapping(outputMin); } if (inputMin === inputMax) { if (input <= inputMin) { - return outputMin; + return mapping(outputMin); } - return outputMax; + return mapping(outputMax); } // Input Range @@ -154,7 +161,7 @@ function interpolate( result = result * (outputMax - outputMin) + outputMin; } - return result; + return mapping(result); } function colorToRgba(input: string): string {