From 6bb609ebeae14e4465bdbad06972ec68be450139 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Fri, 16 Feb 2018 12:41:59 -0800 Subject: [PATCH] Header transition presets with support for standard iOS transition style (#3526) Header transition presets with approximate support for UIKit transition style --- .../examples/NavigationPlayground/js/App.js | 15 +- .../NavigationPlayground/js/SimpleStack.js | 36 +-- .../js/StackWithHeaderPreset.js | 68 ++++++ .../react-navigation/flow/react-navigation.js | 1 + packages/react-navigation/package.json | 2 +- .../src/navigators/StackNavigator.js | 2 + .../DrawerNavigator-test.js.snap | 9 +- .../__snapshots__/StackNavigator-test.js.snap | 24 +- .../src/views/CardStack/CardStack.js | 16 ++ .../views/CardStack/CardStackTransitioner.js | 2 + .../src/views/Header/Header.js | 215 ++++++++++++++++-- .../views/Header/HeaderStyleInterpolator.js | 146 +++++++++--- .../src/views/Header/HeaderTitle.js | 2 +- .../views/Header/ModularHeaderBackButton.js | 118 ++++++++++ .../src/views/TouchableItem.js | 1 + .../src/views/assets/back-icon-mask.png | Bin 0 -> 1887 bytes .../src/views/assets/back-icon.png | Bin 379 -> 491 bytes 17 files changed, 573 insertions(+), 84 deletions(-) create mode 100644 packages/react-navigation/examples/NavigationPlayground/js/StackWithHeaderPreset.js create mode 100644 packages/react-navigation/src/views/Header/ModularHeaderBackButton.js create mode 100644 packages/react-navigation/src/views/assets/back-icon-mask.png diff --git a/packages/react-navigation/examples/NavigationPlayground/js/App.js b/packages/react-navigation/examples/NavigationPlayground/js/App.js index 774a30ba..ac4cb796 100644 --- a/packages/react-navigation/examples/NavigationPlayground/js/App.js +++ b/packages/react-navigation/examples/NavigationPlayground/js/App.js @@ -1,7 +1,7 @@ /* @flow */ import React from 'react'; -import { Constants, ScreenOrientation } from 'expo'; +import { Asset, Constants, ScreenOrientation } from 'expo'; ScreenOrientation.allow(ScreenOrientation.Orientation.ALL); @@ -28,13 +28,14 @@ import StacksInTabs from './StacksInTabs'; import StacksOverTabs from './StacksOverTabs'; import StacksWithKeys from './StacksWithKeys'; import SimpleStack from './SimpleStack'; +import StackWithHeaderPreset from './StackWithHeaderPreset'; import SimpleTabs from './SimpleTabs'; import TabAnimations from './TabAnimations'; const ExampleInfo = { SimpleStack: { name: 'Stack Example', - description: 'A card stack!', + description: 'A card stack', }, SimpleTabs: { name: 'Tabs Example', @@ -44,6 +45,10 @@ const ExampleInfo = { name: 'Drawer Example', description: 'Android-style drawer navigation', }, + StackWithHeaderPreset: { + name: 'UIKit-style Header Transitions', + description: 'Masked back button and sliding header items. iOS only.', + }, // MultipleDrawer: { // name: 'Multiple Drawer Example', // description: 'Add any drawer you need', @@ -102,6 +107,7 @@ const ExampleRoutes = { // MultipleDrawer: { // screen: MultipleDrawer, // }, + StackWithHeaderPreset: StackWithHeaderPreset, TabsInDrawer: TabsInDrawer, CustomTabs: CustomTabs, CustomTransitioner: CustomTransitioner, @@ -128,6 +134,11 @@ class MainScreen extends React.Component { scrollY: new Animated.Value(0), }; + componentWillMount() { + Asset.fromModule(require('react-navigation/src/views/assets/back-icon-mask.png')).downloadAsync(); + Asset.fromModule(require('react-navigation/src/views/assets/back-icon.png')).downloadAsync(); + } + render() { const { navigation } = this.props; diff --git a/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js b/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js index 1717799f..173066ca 100644 --- a/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js +++ b/packages/react-navigation/examples/NavigationPlayground/js/SimpleStack.js @@ -19,14 +19,12 @@ type MyNavScreenProps = { class MyBackButton extends React.Component { render() { - return ( -