1
- import React , { type FunctionComponent , RefAttributes , useEffect , useRef , useState } from "react" ;
1
+ import React , { useCallback , useEffect , useRef , useState , memo } from "react" ;
2
2
import { ActivityIndicator , StyleSheet } from "react-native" ;
3
-
4
3
import { useTheme } from "@react-navigation/native" ;
5
-
6
- import Reanimated , {
7
- FadeIn ,
8
- FadeOut ,
9
- LinearTransition ,
10
- ZoomIn
11
- } from "react-native-reanimated" ;
12
-
4
+ import Reanimated , { FadeIn , FadeOut , LinearTransition , ZoomIn } from "react-native-reanimated" ;
13
5
import { animPapillon } from "@/utils/ui/animations" ;
14
6
import { PressableScale } from "react-native-pressable-scale" ;
15
7
import { NativeText } from "../Global/NativeComponents" ;
@@ -18,8 +10,8 @@ import type { RouteParameters } from "@/router/helpers/types";
18
10
import { useOnlineStatus } from "@/hooks/useOnlineStatus" ;
19
11
20
12
interface WidgetContainerProps {
21
- widget : React . ForwardRefExoticComponent < WidgetProps & RefAttributes < unknown > >
22
- navigation ?: NativeStackNavigationProp < RouteParameters , keyof RouteParameters >
13
+ widget : React . ForwardRefExoticComponent < WidgetProps & React . RefAttributes < unknown > > ;
14
+ navigation ?: NativeStackNavigationProp < RouteParameters , keyof RouteParameters > ;
23
15
}
24
16
25
17
export interface WidgetProps {
@@ -32,7 +24,7 @@ export interface WidgetProps {
32
24
const Widget : React . FC < WidgetContainerProps > = ( { widget : DynamicWidget , navigation } ) => {
33
25
const theme = useTheme ( ) ;
34
26
const { colors } = theme ;
35
- const widgetRef = useRef < FunctionComponent < WidgetProps > | null > ( null ) ;
27
+ const widgetRef = useRef < React . FunctionComponent < WidgetProps > | null > ( null ) ;
36
28
const { isOnline } = useOnlineStatus ( ) ;
37
29
38
30
const [ loading , setLoading ] = useState ( true ) ;
@@ -44,12 +36,12 @@ const Widget: React.FC<WidgetContainerProps> = ({ widget: DynamicWidget, navigat
44
36
}
45
37
} , [ isOnline , loading ] ) ;
46
38
47
- const handlePress = ( ) => {
39
+ const handlePress = useCallback ( ( ) => {
48
40
const location = ( widgetRef . current as any ) ?. handlePress ( ) ;
49
41
if ( location ) {
50
42
navigation ?. navigate ( location ) ;
51
43
}
52
- } ;
44
+ } , [ navigation ] ) ;
53
45
54
46
return (
55
47
< Reanimated . View
@@ -61,22 +53,11 @@ const Widget: React.FC<WidgetContainerProps> = ({ widget: DynamicWidget, navigat
61
53
entering = { animPapillon ( ZoomIn ) . withInitialValues ( { transform : [ { scale : 0.7 } ] , opacity : 0 } ) }
62
54
exiting = { FadeOut . duration ( 150 ) }
63
55
>
64
- < PressableScale
65
- onPress = { ( ) => handlePress ( ) }
66
- >
56
+ < PressableScale onPress = { handlePress } >
67
57
< Reanimated . View
68
- entering = {
69
- FadeIn . springify ( ) . mass ( 1 ) . damping ( 20 ) . stiffness ( 300 )
70
- }
71
- exiting = {
72
- FadeOut
73
- }
74
- style = { [
75
- styles . widget ,
76
- {
77
- backgroundColor : colors . card ,
78
- }
79
- ] }
58
+ entering = { FadeIn . springify ( ) . mass ( 1 ) . damping ( 20 ) . stiffness ( 300 ) }
59
+ exiting = { FadeOut }
60
+ style = { [ styles . widget , { backgroundColor : colors . card } ] }
80
61
>
81
62
{ loading && (
82
63
< Reanimated . View
@@ -94,20 +75,17 @@ const Widget: React.FC<WidgetContainerProps> = ({ widget: DynamicWidget, navigat
94
75
exiting = { FadeOut . duration ( 150 ) }
95
76
>
96
77
< ActivityIndicator />
97
- < NativeText variant = "subtitle" >
98
- Chargement...
99
- </ NativeText >
78
+ < NativeText variant = "subtitle" > Chargement...</ NativeText >
100
79
</ Reanimated . View >
101
80
) }
102
-
103
81
< Reanimated . View
104
82
style = { [
105
83
styles . widgetContent ,
106
84
{
107
85
backgroundColor : theme . dark ? colors . primary + "09" : colors . primary + "11" ,
108
86
overflow : "hidden" ,
109
87
opacity : loading ? 0 : 1 ,
110
- }
88
+ } ,
111
89
] }
112
90
>
113
91
< DynamicWidget
@@ -118,7 +96,6 @@ const Widget: React.FC<WidgetContainerProps> = ({ widget: DynamicWidget, navigat
118
96
hidden = { hidden }
119
97
/>
120
98
</ Reanimated . View >
121
-
122
99
</ Reanimated . View >
123
100
</ PressableScale >
124
101
</ Reanimated . View >
@@ -135,14 +112,10 @@ const styles = StyleSheet.create({
135
112
borderRadius : 17 ,
136
113
borderCurve : "continuous" ,
137
114
shadowColor : "#000" ,
138
- shadowOffset : {
139
- width : 0 ,
140
- height : 0.5 ,
141
- } ,
115
+ shadowOffset : { width : 0 , height : 0.5 } ,
142
116
shadowOpacity : 0.3 ,
143
117
shadowRadius : 3 ,
144
118
} ,
145
-
146
119
widgetContent : {
147
120
width : "100%" ,
148
121
height : "100%" ,
@@ -152,4 +125,4 @@ const styles = StyleSheet.create({
152
125
} ,
153
126
} ) ;
154
127
155
- export default Widget ;
128
+ export default memo ( Widget ) ;
0 commit comments