From f70a289cdfae130eaba679a246e339a6994cd149 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sat, 11 Apr 2020 22:35:57 +0200 Subject: [PATCH] Collapse header when scrolling --- package.json | 1 + src/navigation/MainTabNavigator.js | 28 +++++++++++++++--------- src/screens/Proximo/ProximoListScreen.js | 16 +++++++++++--- src/utils/withCollapsible.js | 8 +++++++ 4 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 src/utils/withCollapsible.js diff --git a/package.json b/package.json index b8657aa..f898812 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "react-native-safe-area-context": "0.7.3", "react-native-screens": "~2.2.0", "react-native-webview": "8.1.1", + "react-navigation-collapsible": "^5.4.0", "react-navigation-header-buttons": "^3.0.5" }, "devDependencies": { diff --git a/src/navigation/MainTabNavigator.js b/src/navigation/MainTabNavigator.js index 358e890..6623e15 100644 --- a/src/navigation/MainTabNavigator.js +++ b/src/navigation/MainTabNavigator.js @@ -13,12 +13,12 @@ import ProximoAboutScreen from "../screens/Proximo/ProximoAboutScreen"; import PlanexScreen from '../screens/Websites/PlanexScreen'; import {MaterialCommunityIcons} from "@expo/vector-icons"; import AsyncStorageManager from "../managers/AsyncStorageManager"; -import {withTheme} from 'react-native-paper'; +import {useTheme, withTheme} from 'react-native-paper'; import i18n from "i18n-js"; import ClubDisplayScreen from "../screens/Amicale/Clubs/ClubDisplayScreen"; import ScannerScreen from "../screens/ScannerScreen"; import MaterialHeaderButtons, {Item} from "../components/Custom/HeaderButton"; - +import {createCollapsibleStack} from 'react-navigation-collapsible'; const TAB_ICONS = { home: 'triangle', @@ -44,7 +44,9 @@ function getDrawerButton(navigation: Object) { const ProximoStack = createStackNavigator(); -function ProximoStackComponent() { +function ProximoStackComponent(props: Object) { + + const {colors} = useTheme(); return ( - + {createCollapsibleStack( + , + { + collapsedColor: colors.surface, + useNativeDriver: true /* Optional, default: true */, + } + )} { itemLayout = (data, index) => ({length: LIST_ITEM_HEIGHT, offset: LIST_ITEM_HEIGHT * index, index}); + render() { + const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack; return ( { {this.state.modalCurrentDisplayItem} {/*$FlowFixMe*/} - { removeClippedSubviews={true} getItemLayout={this.itemLayout} initialNumToRender={10} + // Animations + onScroll={onScroll} + contentContainerStyle={{paddingTop: containerPaddingTop}} + scrollIndicatorInsets={{top: scrollIndicatorInsetTop}} /> ); } } -export default withTheme(ProximoListScreen); +export default withCollapsible(withTheme(ProximoListScreen)); diff --git a/src/utils/withCollapsible.js b/src/utils/withCollapsible.js new file mode 100644 index 0000000..0cb5cad --- /dev/null +++ b/src/utils/withCollapsible.js @@ -0,0 +1,8 @@ +import React from 'react'; +import {useCollapsibleStack} from "react-navigation-collapsible"; + +export const withCollapsible = (Component: any) => { + return (props: any) => { + return ; + }; +};