|
1 | 1 | // TODO: support commented props
|
2 |
| -import React, {PropsWithChildren, useMemo, useEffect, useRef, useState, useCallback} from 'react'; |
| 2 | +import React, {PropsWithChildren, useMemo, useEffect, useState, useCallback} from 'react'; |
3 | 3 | import _ from 'lodash';
|
4 | 4 | import {useAnimatedReaction, useSharedValue, withTiming, runOnJS} from 'react-native-reanimated';
|
5 | 5 | import {Constants} from '../../helpers';
|
6 |
| -import {orientations} from '../../helpers/Constants'; |
| 6 | +import {useOrientation} from '../../hooks'; |
7 | 7 | import {asBaseComponent} from '../../commons/new';
|
8 | 8 | import {LogService} from '../../services';
|
9 | 9 | import TabBarContext from './TabBarContext';
|
@@ -58,25 +58,16 @@ function TabController({
|
58 | 58 | children
|
59 | 59 | }: PropsWithChildren<TabControllerProps>) {
|
60 | 60 | const [screenWidth, setScreenWidth] = useState<number>(Constants.windowWidth);
|
61 |
| - const orientation = useRef<orientations>(Constants.orientation); |
62 |
| - const dimensionsChangeListener = useRef<any>(); |
63 | 61 |
|
64 | 62 | if (items?.length < 2) {
|
65 | 63 | console.error('TabController component expect a minimum of 2 items');
|
66 | 64 | }
|
67 | 65 |
|
68 |
| - useEffect(() => { |
69 |
| - const onOrientationChange = () => { |
70 |
| - if (orientation.current !== Constants.orientation) { |
71 |
| - orientation.current = Constants.orientation; |
72 |
| - setScreenWidth(Constants.windowWidth); |
73 |
| - } |
74 |
| - }; |
75 |
| - dimensionsChangeListener.current = Constants.addDimensionsEventListener(onOrientationChange); |
76 |
| - return () => { |
77 |
| - Constants.removeDimensionsEventListener(dimensionsChangeListener.current || onOrientationChange); |
78 |
| - }; |
79 |
| - }, []); |
| 66 | + useOrientation({ |
| 67 | + onOrientationChange: () => { |
| 68 | + setScreenWidth(Constants.windowWidth); |
| 69 | + } |
| 70 | + }); |
80 | 71 |
|
81 | 72 | const pageWidth = useMemo(() => {
|
82 | 73 | return carouselPageWidth || screenWidth;
|
|
0 commit comments