Browse Source

Collapse header when scrolling

Arnaud Vergnet 4 years ago
parent
commit
f70a289cdf

+ 1
- 0
package.json View File

@@ -52,6 +52,7 @@
52 52
     "react-native-safe-area-context": "0.7.3",
53 53
     "react-native-screens": "~2.2.0",
54 54
     "react-native-webview": "8.1.1",
55
+    "react-navigation-collapsible": "^5.4.0",
55 56
     "react-navigation-header-buttons": "^3.0.5"
56 57
   },
57 58
   "devDependencies": {

+ 18
- 10
src/navigation/MainTabNavigator.js View File

@@ -13,12 +13,12 @@ import ProximoAboutScreen from "../screens/Proximo/ProximoAboutScreen";
13 13
 import PlanexScreen from '../screens/Websites/PlanexScreen';
14 14
 import {MaterialCommunityIcons} from "@expo/vector-icons";
15 15
 import AsyncStorageManager from "../managers/AsyncStorageManager";
16
-import {withTheme} from 'react-native-paper';
16
+import {useTheme, withTheme} from 'react-native-paper';
17 17
 import i18n from "i18n-js";
18 18
 import ClubDisplayScreen from "../screens/Amicale/Clubs/ClubDisplayScreen";
19 19
 import ScannerScreen from "../screens/ScannerScreen";
20 20
 import MaterialHeaderButtons, {Item} from "../components/Custom/HeaderButton";
21
-
21
+import {createCollapsibleStack} from 'react-navigation-collapsible';
22 22
 
23 23
 const TAB_ICONS = {
24 24
     home: 'triangle',
@@ -44,7 +44,9 @@ function getDrawerButton(navigation: Object) {
44 44
 
45 45
 const ProximoStack = createStackNavigator();
46 46
 
47
-function ProximoStackComponent() {
47
+function ProximoStackComponent(props: Object) {
48
+
49
+    const {colors} = useTheme();
48 50
     return (
49 51
         <ProximoStack.Navigator
50 52
             initialRouteName="index"
@@ -62,13 +64,19 @@ function ProximoStackComponent() {
62 64
                 }}
63 65
                 component={ProximoMainScreen}
64 66
             />
65
-            <ProximoStack.Screen
66
-                name="proximo-list"
67
-                options={{
68
-                    title: i18n.t('screens.proximoArticles')
69
-                }}
70
-                component={ProximoListScreen}
71
-            />
67
+            {createCollapsibleStack(
68
+                <ProximoStack.Screen
69
+                    name="proximo-list"
70
+                    options={{
71
+                        title: i18n.t('screens.proximoArticles')
72
+                    }}
73
+                    component={ProximoListScreen}
74
+                />,
75
+                {
76
+                    collapsedColor: colors.surface,
77
+                    useNativeDriver: true /* Optional, default: true */,
78
+                }
79
+            )}
72 80
             <ProximoStack.Screen
73 81
                 name="proximo-about"
74 82
                 component={ProximoAboutScreen}

+ 13
- 3
src/screens/Proximo/ProximoListScreen.js View File

@@ -1,13 +1,16 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {FlatList, Image, Platform, ScrollView, View} from "react-native";
4
+import {Animated, FlatList, Image, Platform, ScrollView, View} from "react-native";
5 5
 import i18n from "i18n-js";
6 6
 import CustomModal from "../../components/Custom/CustomModal";
7 7
 import {RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
8 8
 import {stringMatchQuery} from "../../utils/Search";
9 9
 import ProximoListItem from "../../components/Lists/ProximoListItem";
10 10
 import MaterialHeaderButtons, {Item} from "../../components/Custom/HeaderButton";
11
+import {withCollapsible} from "../../utils/withCollapsible";
12
+
13
+const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
11 14
 
12 15
 function sortPrice(a, b) {
13 16
     return a.price - b.price;
@@ -39,6 +42,7 @@ type Props = {
39 42
     navigation: Object,
40 43
     route: Object,
41 44
     theme: Object,
45
+    collapsibleStack: Object,
42 46
 }
43 47
 
44 48
 type State = {
@@ -322,7 +326,9 @@ class ProximoListScreen extends React.Component<Props, State> {
322 326
 
323 327
     itemLayout = (data, index) => ({length: LIST_ITEM_HEIGHT, offset: LIST_ITEM_HEIGHT * index, index});
324 328
 
329
+
325 330
     render() {
331
+        const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack;
326 332
         return (
327 333
             <View style={{
328 334
                 height: '100%'
@@ -331,7 +337,7 @@ class ProximoListScreen extends React.Component<Props, State> {
331 337
                     {this.state.modalCurrentDisplayItem}
332 338
                 </CustomModal>
333 339
                 {/*$FlowFixMe*/}
334
-                <FlatList
340
+                <AnimatedFlatList
335 341
                     data={this.listData}
336 342
                     extraData={this.state.currentSearchString + this.state.currentSortMode}
337 343
                     keyExtractor={this.keyExtractor}
@@ -340,10 +346,14 @@ class ProximoListScreen extends React.Component<Props, State> {
340 346
                     removeClippedSubviews={true}
341 347
                     getItemLayout={this.itemLayout}
342 348
                     initialNumToRender={10}
349
+                    // Animations
350
+                    onScroll={onScroll}
351
+                    contentContainerStyle={{paddingTop: containerPaddingTop}}
352
+                    scrollIndicatorInsets={{top: scrollIndicatorInsetTop}}
343 353
                 />
344 354
             </View>
345 355
         );
346 356
     }
347 357
 }
348 358
 
349
-export default withTheme(ProximoListScreen);
359
+export default withCollapsible(withTheme(ProximoListScreen));

+ 8
- 0
src/utils/withCollapsible.js View File

@@ -0,0 +1,8 @@
1
+import React from 'react';
2
+import {useCollapsibleStack} from "react-navigation-collapsible";
3
+
4
+export const withCollapsible = (Component: any) => {
5
+    return (props: any) => {
6
+        return <Component collapsibleStack={useCollapsibleStack()} {...props} />;
7
+    };
8
+};

Loading…
Cancel
Save