Browse Source

Improve remaining files to match linter

Arnaud Vergnet 1 year ago
parent
commit
1e81b2cd7b
39 changed files with 355 additions and 316 deletions
  1. 2
    2
      App.js
  2. 1
    0
      index.js
  3. 9
    8
      metro.config.js
  4. 2
    2
      src/components/Amicale/Vote/VoteNotAvailable.js
  5. 2
    2
      src/components/Amicale/Vote/VoteResults.js
  6. 2
    2
      src/components/Amicale/Vote/VoteWait.js
  7. 2
    2
      src/components/Animations/AnimatedAccordion.js
  8. 4
    3
      src/components/Animations/AnimatedBottomBar.js
  9. 1
    1
      src/components/Collapsible/CollapsibleComponent.js
  10. 2
    2
      src/components/Home/ActionsDashboardItem.js
  11. 2
    2
      src/components/Home/EventDashboardItem.js
  12. 2
    2
      src/components/Home/SmallDashboardItem.js
  13. 2
    2
      src/components/Lists/Clubs/ClubListItem.js
  14. 2
    2
      src/components/Lists/DashboardEdit/DashboardEditAccordion.js
  15. 2
    2
      src/components/Lists/DashboardEdit/DashboardEditItem.js
  16. 2
    2
      src/components/Lists/DashboardEdit/DashboardEditPreviewItem.js
  17. 2
    2
      src/components/Lists/Equipment/EquipmentListItem.js
  18. 2
    2
      src/components/Lists/PlanexGroups/GroupListAccordion.js
  19. 2
    2
      src/components/Lists/PlanexGroups/GroupListItem.js
  20. 2
    2
      src/components/Mascot/MascotPopup.js
  21. 2
    2
      src/components/Overrides/CustomAgenda.js
  22. 2
    2
      src/components/Overrides/CustomHTML.js
  23. 2
    2
      src/components/Overrides/CustomHeaderButton.js
  24. 2
    2
      src/components/Overrides/CustomModal.js
  25. 2
    2
      src/components/Overrides/CustomSlider.js
  26. 2
    2
      src/components/Screens/BasicLoadingScreen.js
  27. 9
    6
      src/components/Screens/ErrorView.js
  28. 1
    1
      src/components/Screens/WebSectionList.js
  29. 1
    1
      src/components/Screens/WebViewScreen.js
  30. 2
    2
      src/components/Tabbar/CustomTabBar.js
  31. 2
    2
      src/components/Tabbar/TabHomeIcon.js
  32. 2
    2
      src/components/Tabbar/TabIcon.js
  33. 1
    3
      src/screens/About/AboutScreen.js
  34. 165
    153
      src/screens/Game/logic/Piece.js
  35. 2
    2
      src/screens/Home/HomeScreen.js
  36. 2
    2
      src/screens/Planex/PlanexScreen.js
  37. 1
    1
      src/screens/Services/ServicesSectionScreen.js
  38. 69
    54
      src/utils/AutoHideHandler.js
  39. 39
    31
      src/utils/CollapsibleUtils.js

+ 2
- 2
App.js View File

@@ -10,7 +10,7 @@ import {OverflowMenuProvider} from 'react-navigation-header-buttons';
10 10
 import LocaleManager from './src/managers/LocaleManager';
11 11
 import AsyncStorageManager from './src/managers/AsyncStorageManager';
12 12
 import CustomIntroSlider from './src/components/Overrides/CustomIntroSlider';
13
-import type {CustomTheme} from './src/managers/ThemeManager';
13
+import type {CustomThemeType} from './src/managers/ThemeManager';
14 14
 import ThemeManager from './src/managers/ThemeManager';
15 15
 import MainNavigator from './src/navigation/MainNavigator';
16 16
 import AprilFoolsManager from './src/managers/AprilFoolsManager';
@@ -35,7 +35,7 @@ type StateType = {
35 35
   showIntro: boolean,
36 36
   showUpdate: boolean,
37 37
   showAprilFools: boolean,
38
-  currentTheme: CustomTheme | null,
38
+  currentTheme: CustomThemeType | null,
39 39
 };
40 40
 
41 41
 export default class App extends React.Component<null, StateType> {

+ 1
- 0
index.js View File

@@ -6,4 +6,5 @@ import {AppRegistry} from 'react-native';
6 6
 import App from './App';
7 7
 import {name as appName} from './app.json';
8 8
 
9
+// eslint-disable-next-line flowtype/require-return-type
9 10
 AppRegistry.registerComponent(appName, () => App);

+ 9
- 8
metro.config.js View File

@@ -6,12 +6,13 @@
6 6
  */
7 7
 
8 8
 module.exports = {
9
-    transformer: {
10
-        getTransformOptions: async () => ({
11
-            transform: {
12
-                experimentalImportSupport: false,
13
-                inlineRequires: false,
14
-            },
15
-        }),
16
-    },
9
+  transformer: {
10
+    // eslint-disable-next-line flowtype/require-return-type
11
+    getTransformOptions: async () => ({
12
+      transform: {
13
+        experimentalImportSupport: false,
14
+        inlineRequires: false,
15
+      },
16
+    }),
17
+  },
17 18
 };

+ 2
- 2
src/components/Amicale/Vote/VoteNotAvailable.js View File

@@ -4,10 +4,10 @@ import * as React from 'react';
4 4
 import {View} from 'react-native';
5 5
 import {Headline, withTheme} from 'react-native-paper';
6 6
 import i18n from 'i18n-js';
7
-import type {CustomTheme} from '../../../managers/ThemeManager';
7
+import type {CustomThemeType} from '../../../managers/ThemeManager';
8 8
 
9 9
 type PropsType = {
10
-  theme: CustomTheme,
10
+  theme: CustomThemeType,
11 11
 };
12 12
 
13 13
 class VoteNotAvailable extends React.Component<PropsType> {

+ 2
- 2
src/components/Amicale/Vote/VoteResults.js View File

@@ -12,12 +12,12 @@ import {
12 12
 import {FlatList, StyleSheet} from 'react-native';
13 13
 import i18n from 'i18n-js';
14 14
 import type {VoteTeamType} from '../../../screens/Amicale/VoteScreen';
15
-import type {CustomTheme} from '../../../managers/ThemeManager';
15
+import type {CustomThemeType} from '../../../managers/ThemeManager';
16 16
 
17 17
 type PropsType = {
18 18
   teams: Array<VoteTeamType>,
19 19
   dateEnd: string,
20
-  theme: CustomTheme,
20
+  theme: CustomThemeType,
21 21
 };
22 22
 
23 23
 const styles = StyleSheet.create({

+ 2
- 2
src/components/Amicale/Vote/VoteWait.js View File

@@ -9,14 +9,14 @@ import {
9 9
 } from 'react-native-paper';
10 10
 import {StyleSheet} from 'react-native';
11 11
 import i18n from 'i18n-js';
12
-import type {CustomTheme} from '../../../managers/ThemeManager';
12
+import type {CustomThemeType} from '../../../managers/ThemeManager';
13 13
 
14 14
 type PropsType = {
15 15
   startDate: string | null,
16 16
   justVoted: boolean,
17 17
   hasVoted: boolean,
18 18
   isVoteRunning: boolean,
19
-  theme: CustomTheme,
19
+  theme: CustomThemeType,
20 20
 };
21 21
 
22 22
 const styles = StyleSheet.create({

+ 2
- 2
src/components/Animations/AnimatedAccordion.js View File

@@ -5,10 +5,10 @@ import {View} from 'react-native';
5 5
 import {List, withTheme} from 'react-native-paper';
6 6
 import Collapsible from 'react-native-collapsible';
7 7
 import * as Animatable from 'react-native-animatable';
8
-import type {CustomTheme} from '../../managers/ThemeManager';
8
+import type {CustomThemeType} from '../../managers/ThemeManager';
9 9
 
10 10
 type PropsType = {
11
-  theme: CustomTheme,
11
+  theme: CustomThemeType,
12 12
   title: string,
13 13
   subtitle?: string,
14 14
   left?: () => React.Node,

+ 4
- 3
src/components/Animations/AnimatedBottomBar.js View File

@@ -7,13 +7,14 @@ import * as Animatable from 'react-native-animatable';
7 7
 import {StackNavigationProp} from '@react-navigation/stack';
8 8
 import AutoHideHandler from '../../utils/AutoHideHandler';
9 9
 import CustomTabBar from '../Tabbar/CustomTabBar';
10
-import type {CustomTheme} from '../../managers/ThemeManager';
10
+import type {CustomThemeType} from '../../managers/ThemeManager';
11
+import type {OnScrollType} from '../../utils/AutoHideHandler';
11 12
 
12 13
 const AnimatedFAB = Animatable.createAnimatableComponent(FAB);
13 14
 
14 15
 type PropsType = {
15 16
   navigation: StackNavigationProp,
16
-  theme: CustomTheme,
17
+  theme: CustomThemeType,
17 18
   onPress: (action: string, data?: string) => void,
18 19
   seekAttention: boolean,
19 20
 };
@@ -94,7 +95,7 @@ class AnimatedBottomBar extends React.Component<PropsType, StateType> {
94 95
     }
95 96
   };
96 97
 
97
-  onScroll = (event: SyntheticEvent<EventTarget>) => {
98
+  onScroll = (event: OnScrollType) => {
98 99
     this.hideHandler.onScroll(event);
99 100
   };
100 101
 

+ 1
- 1
src/components/Collapsible/CollapsibleComponent.js View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 import * as React from 'react';
4 4
 import {Collapsible} from 'react-navigation-collapsible';
5
-import {withCollapsible} from '../../utils/withCollapsible';
5
+import withCollapsible from '../../utils/withCollapsible';
6 6
 import CustomTabBar from '../Tabbar/CustomTabBar';
7 7
 
8 8
 export type CollapsibleComponentPropsType = {

+ 2
- 2
src/components/Home/ActionsDashboardItem.js View File

@@ -5,11 +5,11 @@ import {List, withTheme} from 'react-native-paper';
5 5
 import {View} from 'react-native';
6 6
 import i18n from 'i18n-js';
7 7
 import {StackNavigationProp} from '@react-navigation/stack';
8
-import type {CustomTheme} from '../../managers/ThemeManager';
8
+import type {CustomThemeType} from '../../managers/ThemeManager';
9 9
 
10 10
 type PropsType = {
11 11
   navigation: StackNavigationProp,
12
-  theme: CustomTheme,
12
+  theme: CustomThemeType,
13 13
 };
14 14
 
15 15
 class ActionsDashBoardItem extends React.Component<PropsType> {

+ 2
- 2
src/components/Home/EventDashboardItem.js View File

@@ -10,12 +10,12 @@ import {
10 10
 } from 'react-native-paper';
11 11
 import {StyleSheet, View} from 'react-native';
12 12
 import i18n from 'i18n-js';
13
-import type {CustomTheme} from '../../managers/ThemeManager';
13
+import type {CustomThemeType} from '../../managers/ThemeManager';
14 14
 
15 15
 type PropsType = {
16 16
   eventNumber: number,
17 17
   clickAction: () => void,
18
-  theme: CustomTheme,
18
+  theme: CustomThemeType,
19 19
   children?: React.Node,
20 20
 };
21 21
 

+ 2
- 2
src/components/Home/SmallDashboardItem.js View File

@@ -4,13 +4,13 @@ import * as React from 'react';
4 4
 import {Badge, TouchableRipple, withTheme} from 'react-native-paper';
5 5
 import {Dimensions, Image, View} from 'react-native';
6 6
 import * as Animatable from 'react-native-animatable';
7
-import type {CustomTheme} from '../../managers/ThemeManager';
7
+import type {CustomThemeType} from '../../managers/ThemeManager';
8 8
 
9 9
 type PropsType = {
10 10
   image: string | null,
11 11
   onPress: () => void | null,
12 12
   badgeCount: number | null,
13
-  theme: CustomTheme,
13
+  theme: CustomThemeType,
14 14
 };
15 15
 
16 16
 const AnimatableBadge = Animatable.createAnimatableComponent(Badge);

+ 2
- 2
src/components/Lists/Clubs/ClubListItem.js View File

@@ -7,14 +7,14 @@ import type {
7 7
   ClubCategoryType,
8 8
   ClubType,
9 9
 } from '../../../screens/Amicale/Clubs/ClubListScreen';
10
-import type {CustomTheme} from '../../../managers/ThemeManager';
10
+import type {CustomThemeType} from '../../../managers/ThemeManager';
11 11
 
12 12
 type PropsType = {
13 13
   onPress: () => void,
14 14
   categoryTranslator: (id: number) => ClubCategoryType,
15 15
   item: ClubType,
16 16
   height: number,
17
-  theme: CustomTheme,
17
+  theme: CustomThemeType,
18 18
 };
19 19
 
20 20
 class ClubListItem extends React.Component<PropsType> {

+ 2
- 2
src/components/Lists/DashboardEdit/DashboardEditAccordion.js View File

@@ -10,13 +10,13 @@ import type {
10 10
   ServiceCategoryType,
11 11
   ServiceItemType,
12 12
 } from '../../../managers/ServicesManager';
13
-import type {CustomTheme} from '../../../managers/ThemeManager';
13
+import type {CustomThemeType} from '../../../managers/ThemeManager';
14 14
 
15 15
 type PropsType = {
16 16
   item: ServiceCategoryType,
17 17
   activeDashboard: Array<string>,
18 18
   onPress: (service: ServiceItemType) => void,
19
-  theme: CustomTheme,
19
+  theme: CustomThemeType,
20 20
 };
21 21
 
22 22
 const LIST_ITEM_HEIGHT = 64;

+ 2
- 2
src/components/Lists/DashboardEdit/DashboardEditItem.js View File

@@ -3,7 +3,7 @@
3 3
 import * as React from 'react';
4 4
 import {Image} from 'react-native';
5 5
 import {List, withTheme} from 'react-native-paper';
6
-import type {CustomTheme} from '../../../managers/ThemeManager';
6
+import type {CustomThemeType} from '../../../managers/ThemeManager';
7 7
 import type {ServiceItemType} from '../../../managers/ServicesManager';
8 8
 
9 9
 type PropsType = {
@@ -11,7 +11,7 @@ type PropsType = {
11 11
   isActive: boolean,
12 12
   height: number,
13 13
   onPress: () => void,
14
-  theme: CustomTheme,
14
+  theme: CustomThemeType,
15 15
 };
16 16
 
17 17
 class DashboardEditItem extends React.Component<PropsType> {

+ 2
- 2
src/components/Lists/DashboardEdit/DashboardEditPreviewItem.js View File

@@ -3,13 +3,13 @@
3 3
 import * as React from 'react';
4 4
 import {TouchableRipple, withTheme} from 'react-native-paper';
5 5
 import {Dimensions, Image, View} from 'react-native';
6
-import type {CustomTheme} from '../../../managers/ThemeManager';
6
+import type {CustomThemeType} from '../../../managers/ThemeManager';
7 7
 
8 8
 type PropsType = {
9 9
   image: string,
10 10
   isActive: boolean,
11 11
   onPress: () => void,
12
-  theme: CustomTheme,
12
+  theme: CustomThemeType,
13 13
 };
14 14
 
15 15
 /**

+ 2
- 2
src/components/Lists/Equipment/EquipmentListItem.js View File

@@ -4,7 +4,7 @@ import * as React from 'react';
4 4
 import {Avatar, List, withTheme} from 'react-native-paper';
5 5
 import i18n from 'i18n-js';
6 6
 import {StackNavigationProp} from '@react-navigation/stack';
7
-import type {CustomTheme} from '../../../managers/ThemeManager';
7
+import type {CustomThemeType} from '../../../managers/ThemeManager';
8 8
 import type {DeviceType} from '../../../screens/Amicale/Equipment/EquipmentListScreen';
9 9
 import {
10 10
   getFirstEquipmentAvailability,
@@ -17,7 +17,7 @@ type PropsType = {
17 17
   userDeviceRentDates: [string, string],
18 18
   item: DeviceType,
19 19
   height: number,
20
-  theme: CustomTheme,
20
+  theme: CustomThemeType,
21 21
 };
22 22
 
23 23
 class EquipmentListItem extends React.Component<PropsType> {

+ 2
- 2
src/components/Lists/PlanexGroups/GroupListAccordion.js View File

@@ -10,7 +10,7 @@ import type {
10 10
   PlanexGroupType,
11 11
   PlanexGroupCategoryType,
12 12
 } from '../../../screens/Planex/GroupSelectionScreen';
13
-import type {CustomTheme} from '../../../managers/ThemeManager';
13
+import type {CustomThemeType} from '../../../managers/ThemeManager';
14 14
 
15 15
 type PropsType = {
16 16
   item: PlanexGroupCategoryType,
@@ -19,7 +19,7 @@ type PropsType = {
19 19
   currentSearchString: string,
20 20
   favoriteNumber: number,
21 21
   height: number,
22
-  theme: CustomTheme,
22
+  theme: CustomThemeType,
23 23
 };
24 24
 
25 25
 const LIST_ITEM_HEIGHT = 64;

+ 2
- 2
src/components/Lists/PlanexGroups/GroupListItem.js View File

@@ -2,11 +2,11 @@
2 2
 
3 3
 import * as React from 'react';
4 4
 import {IconButton, List, withTheme} from 'react-native-paper';
5
-import type {CustomTheme} from '../../../managers/ThemeManager';
5
+import type {CustomThemeType} from '../../../managers/ThemeManager';
6 6
 import type {PlanexGroupType} from '../../../screens/Planex/GroupSelectionScreen';
7 7
 
8 8
 type PropsType = {
9
-  theme: CustomTheme,
9
+  theme: CustomThemeType,
10 10
   onPress: () => void,
11 11
   onStarPress: () => void,
12 12
   item: PlanexGroupType,

+ 2
- 2
src/components/Mascot/MascotPopup.js View File

@@ -18,12 +18,12 @@ import {
18 18
   View,
19 19
 } from 'react-native';
20 20
 import Mascot from './Mascot';
21
-import type {CustomTheme} from '../../managers/ThemeManager';
21
+import type {CustomThemeType} from '../../managers/ThemeManager';
22 22
 import SpeechArrow from './SpeechArrow';
23 23
 import AsyncStorageManager from '../../managers/AsyncStorageManager';
24 24
 
25 25
 type PropsType = {
26
-  theme: CustomTheme,
26
+  theme: CustomThemeType,
27 27
   icon: string,
28 28
   title: string,
29 29
   message: string,

+ 2
- 2
src/components/Overrides/CustomAgenda.js View File

@@ -4,10 +4,10 @@ import * as React from 'react';
4 4
 import {View} from 'react-native';
5 5
 import {withTheme} from 'react-native-paper';
6 6
 import {Agenda} from 'react-native-calendars';
7
-import type {CustomTheme} from '../../managers/ThemeManager';
7
+import type {CustomThemeType} from '../../managers/ThemeManager';
8 8
 
9 9
 type PropsType = {
10
-  theme: CustomTheme,
10
+  theme: CustomThemeType,
11 11
   onRef: (ref: Agenda) => void,
12 12
 };
13 13
 

+ 2
- 2
src/components/Overrides/CustomHTML.js View File

@@ -5,10 +5,10 @@ import * as React from 'react';
5 5
 import {Text, withTheme} from 'react-native-paper';
6 6
 import HTML from 'react-native-render-html';
7 7
 import {Linking} from 'react-native';
8
-import type {CustomTheme} from '../../managers/ThemeManager';
8
+import type {CustomThemeType} from '../../managers/ThemeManager';
9 9
 
10 10
 type PropsType = {
11
-  theme: CustomTheme,
11
+  theme: CustomThemeType,
12 12
   html: string,
13 13
 };
14 14
 

+ 2
- 2
src/components/Overrides/CustomHeaderButton.js View File

@@ -4,10 +4,10 @@ import * as React from 'react';
4 4
 import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
5 5
 import {HeaderButton, HeaderButtons} from 'react-navigation-header-buttons';
6 6
 import {withTheme} from 'react-native-paper';
7
-import type {CustomTheme} from '../../managers/ThemeManager';
7
+import type {CustomThemeType} from '../../managers/ThemeManager';
8 8
 
9 9
 const MaterialHeaderButton = (props: {
10
-  theme: CustomTheme,
10
+  theme: CustomThemeType,
11 11
   color: string,
12 12
 }): React.Node => {
13 13
   const {color, theme} = props;

+ 2
- 2
src/components/Overrides/CustomModal.js View File

@@ -5,7 +5,7 @@ import {withTheme} from 'react-native-paper';
5 5
 import {Modalize} from 'react-native-modalize';
6 6
 import {View} from 'react-native-animatable';
7 7
 import CustomTabBar from '../Tabbar/CustomTabBar';
8
-import type {CustomTheme} from '../../managers/ThemeManager';
8
+import type {CustomThemeType} from '../../managers/ThemeManager';
9 9
 
10 10
 /**
11 11
  * Abstraction layer for Modalize component, using custom configuration
@@ -14,7 +14,7 @@ import type {CustomTheme} from '../../managers/ThemeManager';
14 14
  * @return {*}
15 15
  */
16 16
 function CustomModal(props: {
17
-  theme: CustomTheme,
17
+  theme: CustomThemeType,
18 18
   onRef: (re: Modalize) => void,
19 19
   children?: React.Node,
20 20
 }): React.Node {

+ 2
- 2
src/components/Overrides/CustomSlider.js View File

@@ -4,10 +4,10 @@ import * as React from 'react';
4 4
 import {Text, withTheme} from 'react-native-paper';
5 5
 import {View} from 'react-native-animatable';
6 6
 import Slider, {SliderProps} from '@react-native-community/slider';
7
-import type {CustomTheme} from '../../managers/ThemeManager';
7
+import type {CustomThemeType} from '../../managers/ThemeManager';
8 8
 
9 9
 type PropsType = {
10
-  theme: CustomTheme,
10
+  theme: CustomThemeType,
11 11
   valueSuffix?: string,
12 12
   ...SliderProps,
13 13
 };

+ 2
- 2
src/components/Screens/BasicLoadingScreen.js View File

@@ -3,7 +3,7 @@
3 3
 import * as React from 'react';
4 4
 import {View} from 'react-native';
5 5
 import {ActivityIndicator, withTheme} from 'react-native-paper';
6
-import type {CustomTheme} from '../../managers/ThemeManager';
6
+import type {CustomThemeType} from '../../managers/ThemeManager';
7 7
 
8 8
 /**
9 9
  * Component used to display a header button
@@ -12,7 +12,7 @@ import type {CustomTheme} from '../../managers/ThemeManager';
12 12
  * @return {*}
13 13
  */
14 14
 function BasicLoadingScreen(props: {
15
-  theme: CustomTheme,
15
+  theme: CustomThemeType,
16 16
   isAbsolute: boolean,
17 17
 }): React.Node {
18 18
   const {theme, isAbsolute} = props;

+ 9
- 6
src/components/Screens/ErrorView.js View File

@@ -8,11 +8,11 @@ import i18n from 'i18n-js';
8 8
 import * as Animatable from 'react-native-animatable';
9 9
 import {StackNavigationProp} from '@react-navigation/stack';
10 10
 import {ERROR_TYPE} from '../../utils/WebData';
11
-import type {CustomTheme} from '../../managers/ThemeManager';
11
+import type {CustomThemeType} from '../../managers/ThemeManager';
12 12
 
13 13
 type PropsType = {
14 14
   navigation: StackNavigationProp,
15
-  theme: CustomTheme,
15
+  theme: CustomThemeType,
16 16
   route: {name: string},
17 17
   onRefresh?: () => void,
18 18
   errorCode?: number,
@@ -47,7 +47,7 @@ const styles = StyleSheet.create({
47 47
 
48 48
 class ErrorView extends React.PureComponent<PropsType> {
49 49
   static defaultProps = {
50
-    onRefresh: (): void => null,
50
+    onRefresh: () => {},
51 51
     errorCode: 0,
52 52
     icon: '',
53 53
     message: '',
@@ -141,10 +141,12 @@ class ErrorView extends React.PureComponent<PropsType> {
141 141
           this.icon = 'alert-circle-outline';
142 142
           break;
143 143
       }
144
-      this.message += `\n\nCode ${props.errorCode}`;
144
+      this.message += `\n\nCode ${
145
+        props.errorCode != null ? props.errorCode : -1
146
+      }`;
145 147
     } else {
146
-      this.message = props.message;
147
-      this.icon = props.icon;
148
+      this.message = props.message != null ? props.message : '';
149
+      this.icon = props.icon != null ? props.icon : '';
148 150
     }
149 151
   }
150 152
 
@@ -168,6 +170,7 @@ class ErrorView extends React.PureComponent<PropsType> {
168 170
         <View style={styles.inner}>
169 171
           <View style={styles.iconContainer}>
170 172
             <MaterialCommunityIcons
173
+              // $FlowFixMe
171 174
               name={this.icon}
172 175
               size={150}
173 176
               color={props.theme.colors.textDisabled}

+ 1
- 1
src/components/Screens/WebSectionList.js View File

@@ -9,7 +9,7 @@ import {Collapsible} from 'react-navigation-collapsible';
9 9
 import {StackNavigationProp} from '@react-navigation/stack';
10 10
 import ErrorView from './ErrorView';
11 11
 import BasicLoadingScreen from './BasicLoadingScreen';
12
-import {withCollapsible} from '../../utils/withCollapsible';
12
+import withCollapsible from '../../utils/withCollapsible';
13 13
 import CustomTabBar from '../Tabbar/CustomTabBar';
14 14
 import {ERROR_TYPE, readData} from '../../utils/WebData';
15 15
 import CollapsibleSectionList from '../Collapsible/CollapsibleSectionList';

+ 1
- 1
src/components/Screens/WebViewScreen.js View File

@@ -14,7 +14,7 @@ import {withTheme} from 'react-native-paper';
14 14
 import {StackNavigationProp} from '@react-navigation/stack';
15 15
 import {Collapsible} from 'react-navigation-collapsible';
16 16
 import type {CustomThemeType} from '../../managers/ThemeManager';
17
-import {withCollapsible} from '../../utils/withCollapsible';
17
+import withCollapsible from '../../utils/withCollapsible';
18 18
 import MaterialHeaderButtons, {Item} from '../Overrides/CustomHeaderButton';
19 19
 import {ERROR_TYPE} from '../../utils/WebData';
20 20
 import ErrorView from './ErrorView';

+ 2
- 2
src/components/Tabbar/CustomTabBar.js View File

@@ -7,7 +7,7 @@ import {Collapsible} from 'react-navigation-collapsible';
7 7
 import {StackNavigationProp} from '@react-navigation/stack';
8 8
 import TabIcon from './TabIcon';
9 9
 import TabHomeIcon from './TabHomeIcon';
10
-import type {CustomTheme} from '../../managers/ThemeManager';
10
+import type {CustomThemeType} from '../../managers/ThemeManager';
11 11
 
12 12
 type RouteType = {
13 13
   name: string,
@@ -33,7 +33,7 @@ type PropsType = {
33 33
     },
34 34
   },
35 35
   navigation: StackNavigationProp,
36
-  theme: CustomTheme,
36
+  theme: CustomThemeType,
37 37
 };
38 38
 
39 39
 type StateType = {

+ 2
- 2
src/components/Tabbar/TabHomeIcon.js View File

@@ -6,13 +6,13 @@ import {FAB, TouchableRipple, withTheme} from 'react-native-paper';
6 6
 import * as Animatable from 'react-native-animatable';
7 7
 import FOCUSED_ICON from '../../../assets/tab-icon.png';
8 8
 import UNFOCUSED_ICON from '../../../assets/tab-icon-outline.png';
9
-import type {CustomTheme} from '../../managers/ThemeManager';
9
+import type {CustomThemeType} from '../../managers/ThemeManager';
10 10
 
11 11
 type PropsType = {
12 12
   focused: boolean,
13 13
   onPress: () => void,
14 14
   onLongPress: () => void,
15
-  theme: CustomTheme,
15
+  theme: CustomThemeType,
16 16
   tabBarHeight: number,
17 17
 };
18 18
 

+ 2
- 2
src/components/Tabbar/TabIcon.js View File

@@ -6,7 +6,7 @@ import {TouchableRipple, withTheme} from 'react-native-paper';
6 6
 import type {MaterialCommunityIconsGlyphs} from 'react-native-vector-icons/MaterialCommunityIcons';
7 7
 import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
8 8
 import * as Animatable from 'react-native-animatable';
9
-import type {CustomTheme} from '../../managers/ThemeManager';
9
+import type {CustomThemeType} from '../../managers/ThemeManager';
10 10
 
11 11
 type PropsType = {
12 12
   focused: boolean,
@@ -15,7 +15,7 @@ type PropsType = {
15 15
   icon: MaterialCommunityIconsGlyphs,
16 16
   onPress: () => void,
17 17
   onLongPress: () => void,
18
-  theme: CustomTheme,
18
+  theme: CustomThemeType,
19 19
   extraData: null | boolean | number | string,
20 20
 };
21 21
 

+ 1
- 3
src/screens/About/AboutScreen.js View File

@@ -145,9 +145,7 @@ class AboutScreen extends React.Component<PropsType> {
145 145
    */
146 146
   additionalDevData = [
147 147
     {
148
-      onPressCallback: () => {
149
-        console.log('Meme this');
150
-      },
148
+      onPressCallback: () => {},
151 149
       icon: 'account',
152 150
       text: 'Yohan SIMARD',
153 151
       showChevron: false,

+ 165
- 153
src/screens/Game/logic/Piece.js View File

@@ -1,14 +1,16 @@
1
-import ShapeL from "../Shapes/ShapeL";
2
-import ShapeI from "../Shapes/ShapeI";
3
-import ShapeJ from "../Shapes/ShapeJ";
4
-import ShapeO from "../Shapes/ShapeO";
5
-import ShapeS from "../Shapes/ShapeS";
6
-import ShapeT from "../Shapes/ShapeT";
7
-import ShapeZ from "../Shapes/ShapeZ";
8
-import type {Coordinates} from '../Shapes/BaseShape';
9
-import BaseShape from "../Shapes/BaseShape";
10
-import type {Grid} from "../components/GridComponent";
11
-import type {CustomTheme} from "../../../managers/ThemeManager";
1
+// @flow
2
+
3
+import ShapeL from '../Shapes/ShapeL';
4
+import ShapeI from '../Shapes/ShapeI';
5
+import ShapeJ from '../Shapes/ShapeJ';
6
+import ShapeO from '../Shapes/ShapeO';
7
+import ShapeS from '../Shapes/ShapeS';
8
+import ShapeT from '../Shapes/ShapeT';
9
+import ShapeZ from '../Shapes/ShapeZ';
10
+import type {CoordinatesType} from '../Shapes/BaseShape';
11
+import BaseShape from '../Shapes/BaseShape';
12
+import type {GridType} from '../components/GridComponent';
13
+import type {CustomThemeType} from '../../../managers/ThemeManager';
12 14
 
13 15
 /**
14 16
  * Class used as an abstraction layer for shapes.
@@ -16,157 +18,167 @@ import type {CustomTheme} from "../../../managers/ThemeManager";
16 18
  *
17 19
  */
18 20
 export default class Piece {
21
+  shapes = [ShapeL, ShapeI, ShapeJ, ShapeO, ShapeS, ShapeT, ShapeZ];
19 22
 
20
-    #shapes = [
21
-        ShapeL,
22
-        ShapeI,
23
-        ShapeJ,
24
-        ShapeO,
25
-        ShapeS,
26
-        ShapeT,
27
-        ShapeZ,
28
-    ];
29
-    #currentShape: BaseShape;
30
-    #theme: CustomTheme;
31
-
32
-    /**
33
-     * Initializes this piece's color and shape
34
-     *
35
-     * @param theme Object containing current theme
36
-     */
37
-    constructor(theme: CustomTheme) {
38
-        this.#currentShape = this.getRandomShape(theme);
39
-        this.#theme = theme;
40
-    }
23
+  currentShape: BaseShape;
41 24
 
42
-    /**
43
-     * Gets a random shape object
44
-     *
45
-     * @param theme Object containing current theme
46
-     */
47
-    getRandomShape(theme: CustomTheme) {
48
-        return new this.#shapes[Math.floor(Math.random() * 7)](theme);
49
-    }
25
+  theme: CustomThemeType;
50 26
 
51
-    /**
52
-     * Removes the piece from the given grid
53
-     *
54
-     * @param grid The grid to remove the piece from
55
-     */
56
-    removeFromGrid(grid: Grid) {
57
-        const pos: Array<Coordinates> = this.#currentShape.getCellsCoordinates(true);
58
-        for (let i = 0; i < pos.length; i++) {
59
-            grid[pos[i].y][pos[i].x] = {
60
-                color: this.#theme.colors.tetrisBackground,
61
-                isEmpty: true,
62
-                key: grid[pos[i].y][pos[i].x].key
63
-            };
64
-        }
65
-    }
27
+  /**
28
+   * Initializes this piece's color and shape
29
+   *
30
+   * @param theme Object containing current theme
31
+   */
32
+  constructor(theme: CustomThemeType) {
33
+    this.currentShape = this.getRandomShape(theme);
34
+    this.theme = theme;
35
+  }
66 36
 
67
-    /**
68
-     * Adds this piece to the given grid
69
-     *
70
-     * @param grid The grid to add the piece to
71
-     * @param isPreview Should we use this piece's current position to determine the cells?
72
-     */
73
-    toGrid(grid: Grid, isPreview: boolean) {
74
-        const pos: Array<Coordinates> = this.#currentShape.getCellsCoordinates(!isPreview);
75
-        for (let i = 0; i < pos.length; i++) {
76
-            grid[pos[i].y][pos[i].x] = {
77
-                color: this.#currentShape.getColor(),
78
-                isEmpty: false,
79
-                key: grid[pos[i].y][pos[i].x].key
80
-            };
81
-        }
82
-    }
37
+  /**
38
+   * Gets a random shape object
39
+   *
40
+   * @param theme Object containing current theme
41
+   */
42
+  getRandomShape(theme: CustomThemeType): BaseShape {
43
+    return new this.shapes[Math.floor(Math.random() * 7)](theme);
44
+  }
83 45
 
84
-    /**
85
-     * Checks if the piece's current position is valid
86
-     *
87
-     * @param grid The current game grid
88
-     * @param width The grid's width
89
-     * @param height The grid's height
90
-     * @return {boolean} If the position is valid
91
-     */
92
-    isPositionValid(grid: Grid, width: number, height: number) {
93
-        let isValid = true;
94
-        const pos: Array<Coordinates> = this.#currentShape.getCellsCoordinates(true);
95
-        for (let i = 0; i < pos.length; i++) {
96
-            if (pos[i].x >= width
97
-                || pos[i].x < 0
98
-                || pos[i].y >= height
99
-                || pos[i].y < 0
100
-                || !grid[pos[i].y][pos[i].x].isEmpty) {
101
-                isValid = false;
102
-                break;
103
-            }
104
-        }
105
-        return isValid;
106
-    }
46
+  /**
47
+   * Removes the piece from the given grid
48
+   *
49
+   * @param grid The grid to remove the piece from
50
+   */
51
+  removeFromGrid(grid: GridType) {
52
+    const pos: Array<CoordinatesType> = this.currentShape.getCellsCoordinates(
53
+      true,
54
+    );
55
+    pos.forEach((coordinates: CoordinatesType) => {
56
+      // eslint-disable-next-line no-param-reassign
57
+      grid[coordinates.y][coordinates.x] = {
58
+        color: this.theme.colors.tetrisBackground,
59
+        isEmpty: true,
60
+        key: grid[coordinates.y][coordinates.x].key,
61
+      };
62
+    });
63
+  }
107 64
 
108
-    /**
109
-     * Tries to move the piece by the given offset on the given grid
110
-     *
111
-     * @param x Position X offset
112
-     * @param y Position Y offset
113
-     * @param grid The grid to move the piece on
114
-     * @param width The grid's width
115
-     * @param height The grid's height
116
-     * @param freezeCallback Callback to use if the piece should freeze itself
117
-     * @return {boolean} True if the move was valid, false otherwise
118
-     */
119
-    tryMove(x: number, y: number, grid: Grid, width: number, height: number, freezeCallback: () => void) {
120
-        if (x > 1) x = 1; // Prevent moving from more than one tile
121
-        if (x < -1) x = -1;
122
-        if (y > 1) y = 1;
123
-        if (y < -1) y = -1;
124
-        if (x !== 0 && y !== 0) y = 0; // Prevent diagonal movement
125
-
126
-        this.removeFromGrid(grid);
127
-        this.#currentShape.move(x, y);
128
-        let isValid = this.isPositionValid(grid, width, height);
129
-
130
-        if (!isValid)
131
-            this.#currentShape.move(-x, -y);
132
-
133
-        let shouldFreeze = !isValid && y !== 0;
134
-        this.toGrid(grid, false);
135
-        if (shouldFreeze)
136
-            freezeCallback();
137
-        return isValid;
138
-    }
65
+  /**
66
+   * Adds this piece to the given grid
67
+   *
68
+   * @param grid The grid to add the piece to
69
+   * @param isPreview Should we use this piece's current position to determine the cells?
70
+   */
71
+  toGrid(grid: GridType, isPreview: boolean) {
72
+    const pos: Array<CoordinatesType> = this.currentShape.getCellsCoordinates(
73
+      !isPreview,
74
+    );
75
+    pos.forEach((coordinates: CoordinatesType) => {
76
+      // eslint-disable-next-line no-param-reassign
77
+      grid[coordinates.y][coordinates.x] = {
78
+        color: this.currentShape.getColor(),
79
+        isEmpty: false,
80
+        key: grid[coordinates.y][coordinates.x].key,
81
+      };
82
+    });
83
+  }
139 84
 
140
-    /**
141
-     * Tries to rotate the piece
142
-     *
143
-     * @param grid The grid to rotate the piece on
144
-     * @param width The grid's width
145
-     * @param height The grid's height
146
-     * @return {boolean} True if the rotation was valid, false otherwise
147
-     */
148
-    tryRotate(grid: Grid, width: number, height: number) {
149
-        this.removeFromGrid(grid);
150
-        this.#currentShape.rotate(true);
151
-        if (!this.isPositionValid(grid, width, height)) {
152
-            this.#currentShape.rotate(false);
153
-            this.toGrid(grid, false);
154
-            return false;
155
-        }
156
-        this.toGrid(grid, false);
157
-        return true;
85
+  /**
86
+   * Checks if the piece's current position is valid
87
+   *
88
+   * @param grid The current game grid
89
+   * @param width The grid's width
90
+   * @param height The grid's height
91
+   * @return {boolean} If the position is valid
92
+   */
93
+  isPositionValid(grid: GridType, width: number, height: number): boolean {
94
+    let isValid = true;
95
+    const pos: Array<CoordinatesType> = this.currentShape.getCellsCoordinates(
96
+      true,
97
+    );
98
+    for (let i = 0; i < pos.length; i += 1) {
99
+      if (
100
+        pos[i].x >= width ||
101
+        pos[i].x < 0 ||
102
+        pos[i].y >= height ||
103
+        pos[i].y < 0 ||
104
+        !grid[pos[i].y][pos[i].x].isEmpty
105
+      ) {
106
+        isValid = false;
107
+        break;
108
+      }
158 109
     }
110
+    return isValid;
111
+  }
159 112
 
160
-    /**
161
-     * Gets this piece used cells coordinates
162
-     *
163
-     * @return {Array<Coordinates>} An array of coordinates
164
-     */
165
-    getCoordinates(): Array<Coordinates> {
166
-        return this.#currentShape.getCellsCoordinates(true);
167
-    }
113
+  /**
114
+   * Tries to move the piece by the given offset on the given grid
115
+   *
116
+   * @param x Position X offset
117
+   * @param y Position Y offset
118
+   * @param grid The grid to move the piece on
119
+   * @param width The grid's width
120
+   * @param height The grid's height
121
+   * @param freezeCallback Callback to use if the piece should freeze itself
122
+   * @return {boolean} True if the move was valid, false otherwise
123
+   */
124
+  tryMove(
125
+    x: number,
126
+    y: number,
127
+    grid: GridType,
128
+    width: number,
129
+    height: number,
130
+    freezeCallback: () => void,
131
+  ): boolean {
132
+    let newX = x;
133
+    let newY = y;
134
+    if (x > 1) newX = 1; // Prevent moving from more than one tile
135
+    if (x < -1) newX = -1;
136
+    if (y > 1) newY = 1;
137
+    if (y < -1) newY = -1;
138
+    if (x !== 0 && y !== 0) newY = 0; // Prevent diagonal movement
139
+
140
+    this.removeFromGrid(grid);
141
+    this.currentShape.move(newX, newY);
142
+    const isValid = this.isPositionValid(grid, width, height);
143
+
144
+    if (!isValid) this.currentShape.move(-newX, -newY);
168 145
 
169
-    getCurrentShape() {
170
-        return this.#currentShape;
146
+    const shouldFreeze = !isValid && newY !== 0;
147
+    this.toGrid(grid, false);
148
+    if (shouldFreeze) freezeCallback();
149
+    return isValid;
150
+  }
151
+
152
+  /**
153
+   * Tries to rotate the piece
154
+   *
155
+   * @param grid The grid to rotate the piece on
156
+   * @param width The grid's width
157
+   * @param height The grid's height
158
+   * @return {boolean} True if the rotation was valid, false otherwise
159
+   */
160
+  tryRotate(grid: GridType, width: number, height: number): boolean {
161
+    this.removeFromGrid(grid);
162
+    this.currentShape.rotate(true);
163
+    if (!this.isPositionValid(grid, width, height)) {
164
+      this.currentShape.rotate(false);
165
+      this.toGrid(grid, false);
166
+      return false;
171 167
     }
168
+    this.toGrid(grid, false);
169
+    return true;
170
+  }
171
+
172
+  /**
173
+   * Gets this piece used cells coordinates
174
+   *
175
+   * @return {Array<CoordinatesType>} An array of coordinates
176
+   */
177
+  getCoordinates(): Array<CoordinatesType> {
178
+    return this.currentShape.getCellsCoordinates(true);
179
+  }
180
+
181
+  getCurrentShape(): BaseShape {
182
+    return this.currentShape;
183
+  }
172 184
 }

+ 2
- 2
src/screens/Home/HomeScreen.js View File

@@ -19,7 +19,7 @@ import MaterialHeaderButtons, {
19 19
   Item,
20 20
 } from '../../components/Overrides/CustomHeaderButton';
21 21
 import AnimatedFAB from '../../components/Animations/AnimatedFAB';
22
-import type {CustomTheme} from '../../managers/ThemeManager';
22
+import type {CustomThemeType} from '../../managers/ThemeManager';
23 23
 import ConnectionManager from '../../managers/ConnectionManager';
24 24
 import LogoutDialog from '../../components/Amicale/LogoutDialog';
25 25
 import AsyncStorageManager from '../../managers/AsyncStorageManager';
@@ -78,7 +78,7 @@ type RawDashboardType = {
78 78
 type PropsType = {
79 79
   navigation: StackNavigationProp,
80 80
   route: {params: {nextScreen: string, data: {...}}},
81
-  theme: CustomTheme,
81
+  theme: CustomThemeType,
82 82
 };
83 83
 
84 84
 type StateType = {

+ 2
- 2
src/screens/Planex/PlanexScreen.js View File

@@ -6,7 +6,7 @@ import i18n from 'i18n-js';
6 6
 import {View} from 'react-native';
7 7
 import {CommonActions} from '@react-navigation/native';
8 8
 import {StackNavigationProp} from '@react-navigation/stack';
9
-import type {CustomTheme} from '../../managers/ThemeManager';
9
+import type {CustomThemeType} from '../../managers/ThemeManager';
10 10
 import ThemeManager from '../../managers/ThemeManager';
11 11
 import WebViewScreen from '../../components/Screens/WebViewScreen';
12 12
 import AsyncStorageManager from '../../managers/AsyncStorageManager';
@@ -22,7 +22,7 @@ import MascotPopup from '../../components/Mascot/MascotPopup';
22 22
 type PropsType = {
23 23
   navigation: StackNavigationProp,
24 24
   route: {params: {group: PlanexGroupType}},
25
-  theme: CustomTheme,
25
+  theme: CustomThemeType,
26 26
 };
27 27
 
28 28
 type StateType = {

+ 1
- 1
src/screens/Services/ServicesSectionScreen.js View File

@@ -6,7 +6,7 @@ import {CommonActions} from '@react-navigation/native';
6 6
 import {StackNavigationProp} from '@react-navigation/stack';
7 7
 import CardList from '../../components/Lists/CardList/CardList';
8 8
 import CustomTabBar from '../../components/Tabbar/CustomTabBar';
9
-import {withCollapsible} from '../../utils/withCollapsible';
9
+import withCollapsible from '../../utils/withCollapsible';
10 10
 import type {ServiceCategoryType} from '../../managers/ServicesManager';
11 11
 
12 12
 type PropsType = {

+ 69
- 54
src/utils/AutoHideHandler.js View File

@@ -1,70 +1,85 @@
1 1
 // @flow
2 2
 
3
-import * as React from 'react';
4
-
5 3
 const speedOffset = 5;
6 4
 
5
+type ListenerFunctionType = (shouldHide: boolean) => void;
6
+
7
+export type OnScrollType = {
8
+  nativeEvent: {
9
+    contentInset: {bottom: number, left: number, right: number, top: number},
10
+    contentOffset: {x: number, y: number},
11
+    contentSize: {height: number, width: number},
12
+    layoutMeasurement: {height: number, width: number},
13
+    zoomScale: number,
14
+  },
15
+};
16
+
7 17
 /**
8 18
  * Class used to detect when to show or hide a component based on scrolling
9 19
  */
10 20
 export default class AutoHideHandler {
21
+  lastOffset: number;
11 22
 
12
-    lastOffset: number;
13
-    isHidden: boolean;
23
+  isHidden: boolean;
14 24
 
15
-    listeners: Array<Function>;
25
+  listeners: Array<ListenerFunctionType>;
16 26
 
17
-    constructor(startHidden: boolean) {
18
-        this.listeners = [];
19
-        this.isHidden = startHidden;
20
-    }
27
+  constructor(startHidden: boolean) {
28
+    this.listeners = [];
29
+    this.isHidden = startHidden;
30
+  }
21 31
 
22
-    /**
23
-     * Adds a listener to the hide event
24
-     *
25
-     * @param listener
26
-     */
27
-    addListener(listener: Function) {
28
-        this.listeners.push(listener);
29
-    }
32
+  /**
33
+   * Adds a listener to the hide event
34
+   *
35
+   * @param listener
36
+   */
37
+  addListener(listener: (shouldHide: boolean) => void) {
38
+    this.listeners.push(listener);
39
+  }
30 40
 
31
-    /**
32
-     * Notifies every listener whether they should hide or show.
33
-     *
34
-     * @param shouldHide
35
-     */
36
-    notifyListeners(shouldHide: boolean) {
37
-        for (let i = 0; i < this.listeners.length; i++) {
38
-            this.listeners[i](shouldHide);
39
-        }
40
-    }
41
+  /**
42
+   * Notifies every listener whether they should hide or show.
43
+   *
44
+   * @param shouldHide
45
+   */
46
+  notifyListeners(shouldHide: boolean) {
47
+    this.listeners.forEach((func: ListenerFunctionType) => {
48
+      func(shouldHide);
49
+    });
50
+  }
41 51
 
42
-    /**
43
-     * Callback to be used on the onScroll animated component event.
44
-     *
45
-     * Detects if the current speed exceeds a threshold and notifies listeners to hide or show.
46
-     *
47
-     * The hide even is triggered when the user scrolls down, and the show event on scroll up.
48
-     * This does not take into account the speed when the y coordinate is negative, to prevent hiding on over scroll.
49
-     * (When scrolling up and hitting the top on ios for example)
50
-     *
51
-     * //TODO Known issue:
52
-     * When refreshing a list with the pull down gesture on ios,
53
-     * this can trigger the hide event as it scrolls down the list to show the refresh indicator.
54
-     * Android shows the refresh indicator on top of the list so this is not an issue.
55
-     *
56
-     * @param nativeEvent The scroll event generated by the animated component onScroll prop
57
-     */
58
-    onScroll({nativeEvent}: Object) {
59
-        const speed = nativeEvent.contentOffset.y < 0 ? 0 : this.lastOffset - nativeEvent.contentOffset.y;
60
-        if (speed < -speedOffset && !this.isHidden) { // Go down
61
-            this.notifyListeners(true);
62
-            this.isHidden = true;
63
-        } else if (speed > speedOffset && this.isHidden) { // Go up
64
-            this.notifyListeners(false);
65
-            this.isHidden = false;
66
-        }
67
-        this.lastOffset = nativeEvent.contentOffset.y;
52
+  /**
53
+   * Callback to be used on the onScroll animated component event.
54
+   *
55
+   * Detects if the current speed exceeds a threshold and notifies listeners to hide or show.
56
+   *
57
+   * The hide even is triggered when the user scrolls down, and the show event on scroll up.
58
+   * This does not take into account the speed when the y coordinate is negative, to prevent hiding on over scroll.
59
+   * (When scrolling up and hitting the top on ios for example)
60
+   *
61
+   * //TODO Known issue:
62
+   * When refreshing a list with the pull down gesture on ios,
63
+   * this can trigger the hide event as it scrolls down the list to show the refresh indicator.
64
+   * Android shows the refresh indicator on top of the list so this is not an issue.
65
+   *
66
+   * @param event The scroll event generated by the animated component onScroll prop
67
+   */
68
+  onScroll(event: OnScrollType) {
69
+    const {nativeEvent} = event;
70
+    const speed =
71
+      nativeEvent.contentOffset.y < 0
72
+        ? 0
73
+        : this.lastOffset - nativeEvent.contentOffset.y;
74
+    if (speed < -speedOffset && !this.isHidden) {
75
+      // Go down
76
+      this.notifyListeners(true);
77
+      this.isHidden = true;
78
+    } else if (speed > speedOffset && this.isHidden) {
79
+      // Go up
80
+      this.notifyListeners(false);
81
+      this.isHidden = false;
68 82
     }
69
-
83
+    this.lastOffset = nativeEvent.contentOffset.y;
84
+  }
70 85
 }

+ 39
- 31
src/utils/CollapsibleUtils.js View File

@@ -1,9 +1,9 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {useTheme} from "react-native-paper";
5
-import {createCollapsibleStack} from "react-navigation-collapsible";
6
-import StackNavigator, {StackNavigationOptions} from "@react-navigation/stack";
4
+import {useTheme} from 'react-native-paper';
5
+import {createCollapsibleStack} from 'react-navigation-collapsible';
6
+import StackNavigator, {StackNavigationOptions} from '@react-navigation/stack';
7 7
 
8 8
 /**
9 9
  * Creates a navigation stack with the collapsible library, allowing the header to collapse on scroll.
@@ -22,32 +22,34 @@ import StackNavigator, {StackNavigationOptions} from "@react-navigation/stack";
22 22
  * @returns {JSX.Element}
23 23
  */
24 24
 export function createScreenCollapsibleStack(
25
-    name: string,
26
-    Stack: StackNavigator,
27
-    component: React.ComponentType<any>,
28
-    title: string,
29
-    useNativeDriver?: boolean,
30
-    options?: StackNavigationOptions,
31
-    headerColor?: string) {
32
-    const {colors} = useTheme();
33
-    const screenOptions = options != null ? options : {};
34
-    return createCollapsibleStack(
35
-        <Stack.Screen
36
-            name={name}
37
-            component={component}
38
-            options={{
39
-                title: title,
40
-                headerStyle: {
41
-                    backgroundColor: headerColor!=null ? headerColor :colors.surface,
42
-                },
43
-                ...screenOptions,
44
-            }}
45
-        />,
46
-        {
47
-            collapsedColor: headerColor!=null ? headerColor :colors.surface,
48
-            useNativeDriver: useNativeDriver != null ? useNativeDriver : true, // native driver does not work with webview
49
-        }
50
-    )
25
+  name: string,
26
+  Stack: StackNavigator,
27
+  // eslint-disable-next-line flowtype/no-weak-types
28
+  component: React.ComponentType<any>,
29
+  title: string,
30
+  useNativeDriver?: boolean,
31
+  options?: StackNavigationOptions,
32
+  headerColor?: string,
33
+): React.Node {
34
+  const {colors} = useTheme();
35
+  const screenOptions = options != null ? options : {};
36
+  return createCollapsibleStack(
37
+    <Stack.Screen
38
+      name={name}
39
+      component={component}
40
+      options={{
41
+        title,
42
+        headerStyle: {
43
+          backgroundColor: headerColor != null ? headerColor : colors.surface,
44
+        },
45
+        ...screenOptions,
46
+      }}
47
+    />,
48
+    {
49
+      collapsedColor: headerColor != null ? headerColor : colors.surface,
50
+      useNativeDriver: useNativeDriver != null ? useNativeDriver : true, // native driver does not work with webview
51
+    },
52
+  );
51 53
 }
52 54
 
53 55
 /**
@@ -62,6 +64,12 @@ export function createScreenCollapsibleStack(
62 64
  * @param title
63 65
  * @returns {JSX.Element}
64 66
  */
65
-export function getWebsiteStack(name: string, Stack: any, component: any, title: string) {
66
-    return createScreenCollapsibleStack(name, Stack, component, title, false);
67
+export function getWebsiteStack(
68
+  name: string,
69
+  Stack: StackNavigator,
70
+  // eslint-disable-next-line flowtype/no-weak-types
71
+  component: React.ComponentType<any>,
72
+  title: string,
73
+): React.Node {
74
+  return createScreenCollapsibleStack(name, Stack, component, title, false);
67 75
 }

Loading…
Cancel
Save