Add headerBackgroundTransitionPreset with 'toggle' 'translate' and 'fade' options
This commit is contained in:
parent
dd58b6cc8f
commit
e5ac256dc2
|
@ -1,9 +1,6 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { StyleSheet, View, Text } from 'react-native';
|
import { StyleSheet, View, Text } from 'react-native';
|
||||||
import {
|
import { createStackNavigator } from 'react-navigation-stack';
|
||||||
createStackNavigator,
|
|
||||||
HeaderStyleInterpolator,
|
|
||||||
} from 'react-navigation-stack';
|
|
||||||
|
|
||||||
function createHeaderBackgroundExample(options = {}) {
|
function createHeaderBackgroundExample(options = {}) {
|
||||||
return createStackNavigator(
|
return createStackNavigator(
|
||||||
|
@ -94,15 +91,10 @@ function createHeaderBackgroundExample(options = {}) {
|
||||||
}
|
}
|
||||||
export const HeaderBackgroundDefault = createHeaderBackgroundExample();
|
export const HeaderBackgroundDefault = createHeaderBackgroundExample();
|
||||||
export const HeaderBackgroundTranslate = createHeaderBackgroundExample({
|
export const HeaderBackgroundTranslate = createHeaderBackgroundExample({
|
||||||
transitionConfig: () => ({
|
headerBackgroundTransitionPreset: 'translate',
|
||||||
headerBackgroundInterpolator:
|
|
||||||
HeaderStyleInterpolator.forBackgroundWithTranslation,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
export const HeaderBackgroundFade = createHeaderBackgroundExample({
|
export const HeaderBackgroundFade = createHeaderBackgroundExample({
|
||||||
transitionConfig: () => ({
|
headerBackgroundTransitionPreset: 'fade',
|
||||||
headerBackgroundInterpolator: HeaderStyleInterpolator.forBackgroundWithFade,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|
|
@ -21,6 +21,7 @@ import { PanGestureHandler, State } from 'react-native-gesture-handler';
|
||||||
import Card from './StackViewCard';
|
import Card from './StackViewCard';
|
||||||
import Header from '../Header/Header';
|
import Header from '../Header/Header';
|
||||||
import TransitionConfigs from './StackViewTransitionConfigs';
|
import TransitionConfigs from './StackViewTransitionConfigs';
|
||||||
|
import HeaderStyleInterpolator from '../Header/HeaderStyleInterpolator';
|
||||||
import StackGestureContext from '../../utils/StackGestureContext';
|
import StackGestureContext from '../../utils/StackGestureContext';
|
||||||
import clamp from '../../utils/clamp';
|
import clamp from '../../utils/clamp';
|
||||||
import { supportsImprovedSpringAnimation } from '../../utils/ReactNativeFeatures';
|
import { supportsImprovedSpringAnimation } from '../../utils/ReactNativeFeatures';
|
||||||
|
@ -43,7 +44,12 @@ const EaseInOut = Easing.inOut(Easing.ease);
|
||||||
* Enumerate possible values for validation
|
* Enumerate possible values for validation
|
||||||
*/
|
*/
|
||||||
const HEADER_LAYOUT_PRESET_VALUES = ['center', 'left'];
|
const HEADER_LAYOUT_PRESET_VALUES = ['center', 'left'];
|
||||||
const HEADER_TRANSITION_PRESET_VALUES = ['uikit', 'fade-in-place'];
|
const HEADER_TRANSITION_PRESET_VALUES = ['fade-in-place', 'uikit'];
|
||||||
|
const HEADER_BACKGROUND_TRANSITION_PRESET_VALUES = [
|
||||||
|
'toggle',
|
||||||
|
'fade',
|
||||||
|
'translate',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The max duration of the card animation in milliseconds after released gesture.
|
* The max duration of the card animation in milliseconds after released gesture.
|
||||||
|
@ -138,13 +144,18 @@ class StackViewLayout extends React.Component {
|
||||||
// Handle the case where the header option is a function, and provide the default
|
// Handle the case where the header option is a function, and provide the default
|
||||||
const renderHeader = header || (props => <Header {...props} />);
|
const renderHeader = header || (props => <Header {...props} />);
|
||||||
|
|
||||||
const {
|
let {
|
||||||
headerLeftInterpolator,
|
headerLeftInterpolator,
|
||||||
headerTitleInterpolator,
|
headerTitleInterpolator,
|
||||||
headerRightInterpolator,
|
headerRightInterpolator,
|
||||||
headerBackgroundInterpolator,
|
headerBackgroundInterpolator,
|
||||||
} = this._getTransitionConfig();
|
} = this._getTransitionConfig();
|
||||||
|
|
||||||
|
let backgroundTransitionPresetInterpolator = this._getHeaderBackgroundTransitionPreset();
|
||||||
|
if (backgroundTransitionPresetInterpolator) {
|
||||||
|
headerBackgroundInterpolator = backgroundTransitionPresetInterpolator;
|
||||||
|
}
|
||||||
|
|
||||||
const { transitionProps, ...passProps } = this.props;
|
const { transitionProps, ...passProps } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -640,6 +651,35 @@ class StackViewLayout extends React.Component {
|
||||||
return 'float';
|
return 'float';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getHeaderBackgroundTransitionPreset() {
|
||||||
|
const { headerBackgroundTransitionPreset } = this.props;
|
||||||
|
if (headerBackgroundTransitionPreset) {
|
||||||
|
if (
|
||||||
|
HEADER_BACKGROUND_TRANSITION_PRESET_VALUES.includes(
|
||||||
|
headerBackgroundTransitionPreset
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (headerBackgroundTransitionPreset === 'fade') {
|
||||||
|
return HeaderStyleInterpolator.forBackgroundWithFade;
|
||||||
|
} else if (headerBackgroundTransitionPreset === 'translate') {
|
||||||
|
return HeaderStyleInterpolator.forBackgroundWithTranslation;
|
||||||
|
} else if (headerBackgroundTransitionPreset === 'toggle') {
|
||||||
|
return HeaderStyleInterpolator.forBackgroundWithInactiveHidden;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (__DEV__) {
|
||||||
|
console.error(
|
||||||
|
`Invalid configuration applied for headerBackgroundTransitionPreset - expected one of ${HEADER_BACKGROUND_TRANSITION_PRESET.join(
|
||||||
|
', '
|
||||||
|
)} but received ${JSON.stringify(headerBackgroundTransitionPreset)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
_getHeaderLayoutPreset() {
|
_getHeaderLayoutPreset() {
|
||||||
const { headerLayoutPreset } = this.props;
|
const { headerLayoutPreset } = this.props;
|
||||||
if (headerLayoutPreset) {
|
if (headerLayoutPreset) {
|
||||||
|
|
Loading…
Reference in New Issue