Use stiffness/damping/mass for card stack transition on React Native >= 50 (#3261)

This commit is contained in:
Adam Miskiewicz
2018-01-11 18:08:42 -08:00
committed by Brent Vatne
parent 50d5c8bc0a
commit bc75a5b7b9
2 changed files with 30 additions and 5 deletions

View File

@@ -0,0 +1,12 @@
/* @flow */
import { NativeModules } from 'react-native';
const { PlatformConstants } = NativeModules;
export const supportsImprovedSpringAnimation = () => {
if (PlatformConstants && PlatformConstants.reactNativeVersion) {
const { major, minor } = PlatformConstants.reactNativeVersion;
return minor >= 50 || (major === 0 && minor === 0); // `master` has major + minor set to 0
}
return false;
};

View File

@@ -9,12 +9,25 @@ import type {
} from '../../TypeDefinition';
import CardStackStyleInterpolator from './CardStackStyleInterpolator';
import * as ReactNativeFeatures from '../../utils/ReactNativeFeatures';
const IOSTransitionSpec = ({
duration: 500,
easing: Easing.bezier(0.2833, 0.99, 0.31833, 0.99),
timing: Animated.timing,
}: NavigationTransitionSpec);
let IOSTransitionSpec;
if (ReactNativeFeatures.supportsImprovedSpringAnimation()) {
// These are the exact values from UINavigationController's animation configuration
IOSTransitionSpec = ({
timing: Animated.spring,
stiffness: 1000,
damping: 500,
mass: 3,
}: NavigationTransitionSpec);
} else {
// This is an approximation of the IOS spring animation using a derived bezier curve
IOSTransitionSpec = ({
duration: 500,
easing: Easing.bezier(0.2833, 0.99, 0.31833, 0.99),
timing: Animated.timing,
}: NavigationTransitionSpec);
}
// Standard iOS navigation transition
const SlideFromRightIOS = ({