Browse Source

Improved animated components flow typing

Arnaud Vergnet 4 years ago
parent
commit
75b7412eb2

+ 9
- 8
src/components/Animations/AnimatedBottomBar.js View File

@@ -2,17 +2,18 @@
2 2
 
3 3
 import * as React from 'react';
4 4
 import {StyleSheet, View} from "react-native";
5
-import {FAB, IconButton, Surface, withTheme} from "react-native-paper";
5
+import {FAB, IconButton, Surface, Theme, withTheme} from "react-native-paper";
6 6
 import AutoHideHandler from "../../utils/AutoHideHandler";
7 7
 import * as Animatable from 'react-native-animatable';
8 8
 import CustomTabBar from "../Tabbar/CustomTabBar";
9
+import {StackNavigationProp} from "@react-navigation/stack";
9 10
 
10 11
 const AnimatedFAB = Animatable.createAnimatableComponent(FAB);
11 12
 
12 13
 type Props = {
13
-    navigation: Object,
14
-    theme: Object,
15
-    onPress: Function,
14
+    navigation: StackNavigationProp,
15
+    theme: Theme,
16
+    onPress: (action: string, data: any) => void,
16 17
     seekAttention: boolean,
17 18
 }
18 19
 
@@ -28,10 +29,10 @@ const DISPLAY_MODES = {
28 29
 
29 30
 class AnimatedBottomBar extends React.Component<Props, State> {
30 31
 
31
-    ref: Object;
32
+    ref: { current: null | Animatable.View };
32 33
     hideHandler: AutoHideHandler;
33 34
 
34
-    displayModeIcons: Object;
35
+    displayModeIcons: { [key: string]: string };
35 36
 
36 37
     state = {
37 38
         currentMode: DISPLAY_MODES.WEEK,
@@ -55,7 +56,7 @@ class AnimatedBottomBar extends React.Component<Props, State> {
55 56
     }
56 57
 
57 58
     onHideChange = (shouldHide: boolean) => {
58
-        if (this.ref.current) {
59
+        if (this.ref.current != null) {
59 60
             if (shouldHide)
60 61
                 this.ref.current.bounceOutDown(1000);
61 62
             else
@@ -63,7 +64,7 @@ class AnimatedBottomBar extends React.Component<Props, State> {
63 64
         }
64 65
     }
65 66
 
66
-    onScroll = (event: Object) => {
67
+    onScroll = (event: SyntheticEvent<EventTarget>) => {
67 68
         this.hideHandler.onScroll(event);
68 69
     };
69 70
 

+ 6
- 5
src/components/Animations/AnimatedFAB.js View File

@@ -6,18 +6,19 @@ import {FAB} from "react-native-paper";
6 6
 import AutoHideHandler from "../../utils/AutoHideHandler";
7 7
 import * as Animatable from 'react-native-animatable';
8 8
 import CustomTabBar from "../Tabbar/CustomTabBar";
9
+import {StackNavigationProp} from "@react-navigation/stack";
9 10
 
10 11
 type Props = {
11
-    navigation: Object,
12
+    navigation: StackNavigationProp,
12 13
     icon: string,
13
-    onPress: Function,
14
+    onPress: () => void,
14 15
 }
15 16
 
16 17
 const AnimatedFab = Animatable.createAnimatableComponent(FAB);
17 18
 
18 19
 export default class AnimatedFAB extends React.Component<Props> {
19 20
 
20
-    ref: Object;
21
+    ref: { current: null | Animatable.View };
21 22
     hideHandler: AutoHideHandler;
22 23
 
23 24
     constructor() {
@@ -27,12 +28,12 @@ export default class AnimatedFAB extends React.Component<Props> {
27 28
         this.hideHandler.addListener(this.onHideChange);
28 29
     }
29 30
 
30
-    onScroll = (event: Object) => {
31
+    onScroll = (event: SyntheticEvent<EventTarget>) => {
31 32
         this.hideHandler.onScroll(event);
32 33
     };
33 34
 
34 35
     onHideChange = (shouldHide: boolean) => {
35
-        if (this.ref.current) {
36
+        if (this.ref.current != null) {
36 37
             if (shouldHide)
37 38
                 this.ref.current.bounceOutDown(1000);
38 39
             else

+ 6
- 5
src/components/Animations/AnimatedFocusView.js View File

@@ -3,16 +3,17 @@
3 3
 import * as React from 'react';
4 4
 import * as Animatable from "react-native-animatable";
5 5
 import {CommonActions} from "@react-navigation/native";
6
+import {StackNavigationProp} from "@react-navigation/stack";
6 7
 
7 8
 type Props = {
8
-    navigation: Object,
9
-    route: Object,
10
-    children: React$Node
9
+    navigation: StackNavigationProp,
10
+    route: { params?: any, ... },
11
+    children: React.Node
11 12
 }
12 13
 
13 14
 export default class AnimatedFocusView extends React.Component<Props> {
14 15
 
15
-    ref: Object;
16
+    ref: { current: null | Animatable.View };
16 17
 
17 18
     constructor() {
18 19
         super();
@@ -24,7 +25,7 @@ export default class AnimatedFocusView extends React.Component<Props> {
24 25
     }
25 26
 
26 27
     onScreenFocus = () => {
27
-        if (this.props.route.params !== undefined) {
28
+        if (this.props.route.params != null) {
28 29
             if (this.props.route.params.animationDir && this.ref.current) {
29 30
                 if (this.props.route.params.animationDir === "right")
30 31
                     this.ref.current.fadeInRight(300);

Loading…
Cancel
Save