Collapse header when scrolling
This commit is contained in:
parent
f3b7bafdca
commit
f70a289cdf
4 changed files with 40 additions and 13 deletions
|
@ -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": {
|
||||
|
|
|
@ -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 (
|
||||
<ProximoStack.Navigator
|
||||
initialRouteName="index"
|
||||
|
@ -62,13 +64,19 @@ function ProximoStackComponent() {
|
|||
}}
|
||||
component={ProximoMainScreen}
|
||||
/>
|
||||
{createCollapsibleStack(
|
||||
<ProximoStack.Screen
|
||||
name="proximo-list"
|
||||
options={{
|
||||
title: i18n.t('screens.proximoArticles')
|
||||
}}
|
||||
component={ProximoListScreen}
|
||||
/>
|
||||
/>,
|
||||
{
|
||||
collapsedColor: colors.surface,
|
||||
useNativeDriver: true /* Optional, default: true */,
|
||||
}
|
||||
)}
|
||||
<ProximoStack.Screen
|
||||
name="proximo-about"
|
||||
component={ProximoAboutScreen}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
// @flow
|
||||
|
||||
import * as React from 'react';
|
||||
import {FlatList, Image, Platform, ScrollView, View} from "react-native";
|
||||
import {Animated, FlatList, Image, Platform, ScrollView, View} from "react-native";
|
||||
import i18n from "i18n-js";
|
||||
import CustomModal from "../../components/Custom/CustomModal";
|
||||
import {RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
|
||||
import {stringMatchQuery} from "../../utils/Search";
|
||||
import ProximoListItem from "../../components/Lists/ProximoListItem";
|
||||
import MaterialHeaderButtons, {Item} from "../../components/Custom/HeaderButton";
|
||||
import {withCollapsible} from "../../utils/withCollapsible";
|
||||
|
||||
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
||||
|
||||
function sortPrice(a, b) {
|
||||
return a.price - b.price;
|
||||
|
@ -39,6 +42,7 @@ type Props = {
|
|||
navigation: Object,
|
||||
route: Object,
|
||||
theme: Object,
|
||||
collapsibleStack: Object,
|
||||
}
|
||||
|
||||
type State = {
|
||||
|
@ -322,7 +326,9 @@ class ProximoListScreen extends React.Component<Props, State> {
|
|||
|
||||
itemLayout = (data, index) => ({length: LIST_ITEM_HEIGHT, offset: LIST_ITEM_HEIGHT * index, index});
|
||||
|
||||
|
||||
render() {
|
||||
const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
|
||||
return (
|
||||
<View style={{
|
||||
height: '100%'
|
||||
|
@ -331,7 +337,7 @@ class ProximoListScreen extends React.Component<Props, State> {
|
|||
{this.state.modalCurrentDisplayItem}
|
||||
</CustomModal>
|
||||
{/*$FlowFixMe*/}
|
||||
<FlatList
|
||||
<AnimatedFlatList
|
||||
data={this.listData}
|
||||
extraData={this.state.currentSearchString + this.state.currentSortMode}
|
||||
keyExtractor={this.keyExtractor}
|
||||
|
@ -340,10 +346,14 @@ class ProximoListScreen extends React.Component<Props, State> {
|
|||
removeClippedSubviews={true}
|
||||
getItemLayout={this.itemLayout}
|
||||
initialNumToRender={10}
|
||||
// Animations
|
||||
onScroll={onScroll}
|
||||
contentContainerStyle={{paddingTop: containerPaddingTop}}
|
||||
scrollIndicatorInsets={{top: scrollIndicatorInsetTop}}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withTheme(ProximoListScreen);
|
||||
export default withCollapsible(withTheme(ProximoListScreen));
|
||||
|
|
8
src/utils/withCollapsible.js
Normal file
8
src/utils/withCollapsible.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import React from 'react';
|
||||
import {useCollapsibleStack} from "react-navigation-collapsible";
|
||||
|
||||
export const withCollapsible = (Component: any) => {
|
||||
return (props: any) => {
|
||||
return <Component collapsibleStack={useCollapsibleStack()} {...props} />;
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue