This gist provides an example of how to implement the iOS 11 Navigation Bar with Large Title for react-navigation. For more information on this navigation bar style, see https://medium.com/@PavelGnatyuk/large-title-and-search-in-ios-11-514d5e020cee and react-navigation/react-navigation#2749.
You can check out https://i.imgur.com/M8pv1ya.png to see an example of how this looks in an app where I'm using all of the components provided in this gist.
Notes:
- I've used the react-native-typography library as the source of the correct text styles for the header (title and left/right components) to match the text styles of the native iOS 11 Navigation Bar with Large Title.
- I have intentionally made is to that the header looks the same on both iOS and Android (aside from minor differences like the fonts used on iOS vs Android). This is what I needed for my use case, but if you wanted to render headers differently on Android you'd have to implement those changes for how the header renders on Android.
- I have provided the relevant dependencies from my
package.json
file. The versions you see in this file are the ones I'm currently using and that I've tested with. I haven't tested with newer versions ofreact-native
orreact-navigation
, so it's possible that there are some changes required to support those newer versions. - In the cases where I've copied a component from
react-navigation
(e.g.Header.js
) and then modified it, I've tried to leave comments explaining the changes I've made. This should make it easier to retain or implement the same changes in the situation where there is a new version ofreact-navigation
which contains significant changes to the component I originally copied. - You will need to copy the iOS back icon images from
react-navigation
into your own project source folder (so that the back button looks the same on Android as it does on iOS). See the comments in theHeaderLargeBackButton.js
file for more info on this.
Potential improvements:
- Make the header automatically shrink/expand based on the user scrolling up/down on the screen. This is how the native iOS 11 Navigation Bar with Large Title behaves, but I have not tried to implement this same behaviour yet.
Thanks for the example! I did got an error about closing the
<Text>
tag on https://gist.github.com/jordanmkoncz/3d6ea2773399916afe1c9f58a17e6931#file-headerbuttonexample-js-L22