const scaleCenterAndroidInterpolator = ({
current,
closing,
next
}: StackCardInterpolationProps) => {
const { add, multiply } = Animated;
const handleConditionalScale = (
condition: Animated.AnimatedInterpolation,
main: Animated.AnimatedInterpolation,
fallback: Animated.AnimatedInterpolation) => (
add(multiply(condition, main), multiply(condition.interpolate({
inputRange: [0, 1],
outputRange: [1, 0]
}), fallback))
)
const progress: Animated.AnimatedAddition = add(current.progress.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
extrapolate: 'clamp'
}), next ? next.progress.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
extrapolate: 'clamp'
}) : 0);
const opacity: Animated.AnimatedInterpolation = progress.interpolate({
inputRange: [0, 0.75, 0.875, 1, 1.0825, 1.2075, 2],
outputRange: [0, 0, 1, 1, 1, 1, 1]
});
const scale: Animated.AnimatedAddition = handleConditionalScale(closing, current.progress.interpolate({
inputRange: [0, 1],
outputRange: [0.925, 1],
extrapolate: 'clamp'
}), progress.interpolate({
inputRange: [0, 1, 2],
outputRange: [0.85, 1, 1.075]
}));
const overlayStyle: { opacity: Animated.AnimatedInterpolation } = {
opacity: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [0, 0.5],
extrapolate: 'clamp',
})
}
return {
cardStyle: {
opacity: opacity,
transform: [
{ scale }
],
},
overlayStyle
}
}