react-native-screens
react-native-screens copied to clipboard
Implement largeTitle on Android
This adds support for large header on Android, similar to what exists on iOS. The main issue is that we need a way to communicate scroll to CoordinatorLayout. Normally this is done using NestedScrollView or a RecyclerView as a direct child of CoordinatorLayout. This is however not really possible with the current setup and the way react native works.
I was able to get it working by making ReactScrollView inherit NestedScrollView to test but we will need to find a better solution as I don't think this is upstreamable. There might also be some subtle behavior differences when the NestedScrollView is not a direct child of the CoordinatorLayout. This is to be verified with a fully native app.
I need to investigate more how NestedScrollView works to forward scroll events to the parent CoordinatorLayout. Some options I see:
- Have a custom ScrollView component that would extend
NestedScrollView. Probably the easiest to implement but requires app changes to work. - Traverse subviews to find instances of
ReactScrollViewand find a way to hook into its scroll events. We could then have some proxyScrollViewthat we insert as a child ofCoordinatorLayoutthat sends the scroll events the way it expects it. The issue is we'd have to know and re-traverse whenever the view hierachy changes.
Summary of the changes:
- Use
CollapsingToolbarLayoutto implement large title behaviors - Adds support for existing
largeTitleandlargeTitleFontFamilyprops - Add
largeTitleFontSizebut currently unused,CollapsingToolbarLayoutonly allows passing a resource id for styling titles. See if we can hack something by traversing subviews. - Add new
collapsableprop to make the header hide during scroll, not sure about the name. It was simple to add support for this withCollapsingToolbarLayoutso I figured why not.
@kmagiera Is this something that you think can be merged eventually?
It still requires a significant amount of work / testing. I can't give a timeframe but I'll try working on this again when I have some free time.
would be awesome to see this on android, even though its not platform specific
I’ve implemented large titles for Android in my Navigation router for React Native. It’s powered by a 100% native CoordinatorLayout component.
import { ScrollView } from 'react-native';
import { CoordinatorLayout, NavigationBar, CollapsingBar } from 'navigation-react-native';
<CoordinatorLayout>
<NavigationBar
titleBar="Page title"
largeTitle={true}
style={{height: 180}}>
<CollapsingBar />
</NavigationBar>
<ScrollView nestedScrollEnabled={true} />
</CoordinatorLayout>
