|
1 | | -import React, { createContext, useContext, useState } from 'react'; |
| 1 | +import React, { createContext, useContext, useMemo, useState } from 'react'; |
2 | 2 | import { useSharedValue, type SharedValue } from 'react-native-reanimated'; |
3 | 3 | import type { |
4 | 4 | RouteIndexToTabContentWidthMap, |
@@ -33,16 +33,25 @@ export const TabLayoutContextProvider: React.FC = React.memo( |
33 | 33 | const routeIndexToTabOffsetMapSV = useSharedValue({}); |
34 | 34 | const routeIndexToTabContentWidthMapSV = useSharedValue({}); |
35 | 35 |
|
| 36 | + const value = useMemo( |
| 37 | + () => ({ |
| 38 | + routeIndexToTabContentWidthMap, |
| 39 | + setRouteIndexToTabContentWidthMap, |
| 40 | + routeIndexToTabWidthMapSV, |
| 41 | + routeIndexToTabOffsetMapSV, |
| 42 | + routeIndexToTabContentWidthMapSV, |
| 43 | + }), |
| 44 | + [ |
| 45 | + routeIndexToTabContentWidthMap, |
| 46 | + setRouteIndexToTabContentWidthMap, |
| 47 | + routeIndexToTabWidthMapSV, |
| 48 | + routeIndexToTabOffsetMapSV, |
| 49 | + routeIndexToTabContentWidthMapSV, |
| 50 | + ] |
| 51 | + ); |
| 52 | + |
36 | 53 | return ( |
37 | | - <TabLayoutContext.Provider |
38 | | - value={{ |
39 | | - routeIndexToTabContentWidthMap, |
40 | | - setRouteIndexToTabContentWidthMap, |
41 | | - routeIndexToTabWidthMapSV, |
42 | | - routeIndexToTabOffsetMapSV, |
43 | | - routeIndexToTabContentWidthMapSV, |
44 | | - }} |
45 | | - > |
| 54 | + <TabLayoutContext.Provider value={value}> |
46 | 55 | {children} |
47 | 56 | </TabLayoutContext.Provider> |
48 | 57 | ); |
|
0 commit comments