mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
Use stiffness/damping/mass for card stack transition on React Native >= 50 (#3261)
This commit is contained in:
committed by
Brent Vatne
parent
50d5c8bc0a
commit
bc75a5b7b9
12
src/utils/ReactNativeFeatures.js
Normal file
12
src/utils/ReactNativeFeatures.js
Normal 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;
|
||||
};
|
||||
@@ -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 = ({
|
||||
|
||||
Reference in New Issue
Block a user