@fountain-ui/lab 1.21.1 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commonjs/AnimatedY/AnimatedY.js +10 -14
- package/build/commonjs/AnimatedY/AnimatedY.js.map +1 -1
- package/build/commonjs/AnimatedY/AnimatedYProps.js.map +1 -1
- package/build/commonjs/AnimatedY/index.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetNative.js +8 -2
- package/build/commonjs/BottomSheet/BottomSheetNative.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetProps.js.map +1 -1
- package/build/commonjs/BottomSheet/BottomSheetWeb.js +2 -6
- package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
- package/build/commonjs/BottomSheet/TransparentBackdrop.js +1 -1
- package/build/commonjs/BottomSheet/TransparentBackdrop.js.map +1 -1
- package/build/commonjs/BottomSheet/index.js.map +1 -1
- package/build/commonjs/BottomSheet/index.native.js.map +1 -1
- package/build/commonjs/Carousel/CarouselNative.js.map +1 -1
- package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
- package/build/commonjs/Carousel/CarouselWeb.js +1 -1
- package/build/commonjs/Carousel/CarouselWeb.js.map +1 -1
- package/build/commonjs/Carousel/index.js.map +1 -1
- package/build/commonjs/Carousel/index.native.js.map +1 -1
- package/build/commonjs/Carousel/utils.js +1 -1
- package/build/commonjs/Carousel/utils.js.map +1 -1
- package/build/commonjs/ComicViewer/ComicViewer.js +168 -0
- package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -0
- package/build/commonjs/ComicViewer/ComicViewerItemProps.js +6 -0
- package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +1 -0
- package/build/commonjs/ComicViewer/ComicViewerProps.js +2 -0
- package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -0
- package/build/commonjs/ComicViewer/ViewerItem.js +88 -0
- package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -0
- package/build/commonjs/ComicViewer/index.js +16 -0
- package/build/commonjs/ComicViewer/index.js.map +1 -0
- package/build/commonjs/DateTimePicker/DateTimePicker.js +7 -1
- package/build/commonjs/DateTimePicker/DateTimePicker.js.map +1 -1
- package/build/commonjs/DateTimePicker/DateTimePickerProps.js.map +1 -1
- package/build/commonjs/DateTimePicker/DateTimePickerProvider.js.map +1 -1
- package/build/commonjs/DateTimePicker/YearPicker.js +22 -17
- package/build/commonjs/DateTimePicker/YearPicker.js.map +1 -1
- package/build/commonjs/DateTimePicker/index.js +4 -4
- package/build/commonjs/DateTimePicker/index.js.map +1 -1
- package/build/commonjs/DateTimePicker/utils.js +2 -1
- package/build/commonjs/DateTimePicker/utils.js.map +1 -1
- package/build/commonjs/FlipCard/FlipCard.js +7 -13
- package/build/commonjs/FlipCard/FlipCard.js.map +1 -1
- package/build/commonjs/FlipCard/FlipCardProps.js.map +1 -1
- package/build/commonjs/FlipCard/index.js.map +1 -1
- package/build/commonjs/StatusBarProvider/Provider.js +1 -1
- package/build/commonjs/StatusBarProvider/Provider.js.map +1 -1
- package/build/commonjs/StatusBarProvider/StatusBarProvider.js.map +1 -1
- package/build/commonjs/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
- package/build/commonjs/StatusBarProvider/index.js.map +1 -1
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +90 -22
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerNative.js +46 -36
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerWeb.js +32 -25
- package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/commonjs/ViewPager/index.js.map +1 -1
- package/build/commonjs/ViewPager/index.native.js.map +1 -1
- package/build/commonjs/ViewPager/utils.js +3 -39
- package/build/commonjs/ViewPager/utils.js.map +1 -1
- package/build/commonjs/hooks/index.js.map +1 -1
- package/build/commonjs/hooks/useAppbarStyles.js.map +1 -1
- package/build/commonjs/hooks/useElevationStyle.js.map +1 -1
- package/build/commonjs/hooks/useHeight.js +5 -4
- package/build/commonjs/hooks/useHeight.js.map +1 -1
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +56 -57
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js +9 -11
- package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
- package/build/commonjs/index.js +25 -4
- package/build/commonjs/index.js.map +1 -1
- package/build/module/AnimatedY/AnimatedY.js +11 -10
- package/build/module/AnimatedY/AnimatedY.js.map +1 -1
- package/build/module/AnimatedY/AnimatedYProps.js.map +1 -1
- package/build/module/AnimatedY/index.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetNative.js +8 -2
- package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
- package/build/module/BottomSheet/BottomSheetWeb.js +2 -6
- package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
- package/build/module/BottomSheet/TransparentBackdrop.js +1 -1
- package/build/module/BottomSheet/TransparentBackdrop.js.map +1 -1
- package/build/module/BottomSheet/index.js.map +1 -1
- package/build/module/BottomSheet/index.native.js.map +1 -1
- package/build/module/Carousel/CarouselNative.js.map +1 -1
- package/build/module/Carousel/CarouselProps.js.map +1 -1
- package/build/module/Carousel/CarouselWeb.js +1 -1
- package/build/module/Carousel/CarouselWeb.js.map +1 -1
- package/build/module/Carousel/index.js.map +1 -1
- package/build/module/Carousel/index.native.js.map +1 -1
- package/build/module/Carousel/utils.js.map +1 -1
- package/build/module/ComicViewer/ComicViewer.js +151 -0
- package/build/module/ComicViewer/ComicViewer.js.map +1 -0
- package/build/module/ComicViewer/ComicViewerItemProps.js +2 -0
- package/build/module/ComicViewer/ComicViewerItemProps.js.map +1 -0
- package/build/module/ComicViewer/ComicViewerProps.js +2 -0
- package/build/module/ComicViewer/ComicViewerProps.js.map +1 -0
- package/build/module/ComicViewer/ViewerItem.js +72 -0
- package/build/module/ComicViewer/ViewerItem.js.map +1 -0
- package/build/module/ComicViewer/index.js +2 -0
- package/build/module/ComicViewer/index.js.map +1 -0
- package/build/module/DateTimePicker/DateTimePicker.js +7 -1
- package/build/module/DateTimePicker/DateTimePicker.js.map +1 -1
- package/build/module/DateTimePicker/DateTimePickerProps.js.map +1 -1
- package/build/module/DateTimePicker/DateTimePickerProvider.js.map +1 -1
- package/build/module/DateTimePicker/YearPicker.js +22 -17
- package/build/module/DateTimePicker/YearPicker.js.map +1 -1
- package/build/module/DateTimePicker/index.js.map +1 -1
- package/build/module/DateTimePicker/utils.js +2 -1
- package/build/module/DateTimePicker/utils.js.map +1 -1
- package/build/module/FlipCard/FlipCard.js +7 -7
- package/build/module/FlipCard/FlipCard.js.map +1 -1
- package/build/module/FlipCard/FlipCardProps.js.map +1 -1
- package/build/module/FlipCard/index.js.map +1 -1
- package/build/module/StatusBarProvider/Provider.js.map +1 -1
- package/build/module/StatusBarProvider/StatusBarProvider.js.map +1 -1
- package/build/module/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
- package/build/module/StatusBarProvider/index.js.map +1 -1
- package/build/module/ViewPager/ChildrenMemoizedPage.js +85 -23
- package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/module/ViewPager/ViewPagerNative.js +43 -32
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
- package/build/module/ViewPager/ViewPagerWeb.js +26 -23
- package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
- package/build/module/ViewPager/index.js.map +1 -1
- package/build/module/ViewPager/index.native.js.map +1 -1
- package/build/module/ViewPager/utils.js +1 -31
- package/build/module/ViewPager/utils.js.map +1 -1
- package/build/module/hooks/index.js.map +1 -1
- package/build/module/hooks/useAppbarStyles.js.map +1 -1
- package/build/module/hooks/useElevationStyle.js.map +1 -1
- package/build/module/hooks/useHeight.js +4 -3
- package/build/module/hooks/useHeight.js.map +1 -1
- package/build/module/hooks/useUnstableCollapsibleAppBar.js +58 -43
- package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/module/hooks/useUnstableToggleDisplayStyle.js +9 -7
- package/build/module/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
- package/build/module/index.js +2 -0
- package/build/module/index.js.map +1 -1
- package/build/typescript/AnimatedY/AnimatedY.d.ts +0 -1
- package/build/typescript/BottomSheet/BottomSheetNative.d.ts +0 -1
- package/build/typescript/BottomSheet/BottomSheetWeb.d.ts +0 -1
- package/build/typescript/BottomSheet/TransparentBackdrop.d.ts +0 -1
- package/build/typescript/Carousel/CarouselNative.d.ts +0 -1
- package/build/typescript/ComicViewer/ComicViewer.d.ts +2 -0
- package/build/typescript/ComicViewer/ComicViewerItemProps.d.ts +12 -0
- package/build/typescript/ComicViewer/ComicViewerProps.d.ts +76 -0
- package/build/typescript/ComicViewer/ViewerItem.d.ts +7 -0
- package/build/typescript/ComicViewer/index.d.ts +3 -0
- package/build/typescript/DateTimePicker/DateTimePicker.d.ts +0 -1
- package/build/typescript/DateTimePicker/YearPicker.d.ts +0 -1
- package/build/typescript/FlipCard/FlipCard.d.ts +0 -1
- package/build/typescript/StatusBarProvider/StatusBarProvider.d.ts +0 -1
- package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +2 -1
- package/build/typescript/ViewPager/ViewPagerNative.d.ts +4 -2
- package/build/typescript/ViewPager/ViewPagerProps.d.ts +20 -19
- package/build/typescript/ViewPager/ViewPagerWeb.d.ts +4 -2
- package/build/typescript/ViewPager/index.d.ts +1 -1
- package/build/typescript/ViewPager/utils.d.ts +2 -19
- package/build/typescript/hooks/useUnstableCollapsibleAppBar.d.ts +2 -3
- package/build/typescript/hooks/useUnstableToggleDisplayStyle.d.ts +2 -2
- package/build/typescript/index.d.ts +2 -0
- package/package.json +13 -13
- package/src/AnimatedY/AnimatedY.tsx +13 -10
- package/src/BottomSheet/BottomSheetNative.tsx +6 -0
- package/src/ComicViewer/ComicViewer.tsx +162 -0
- package/src/ComicViewer/ComicViewerItemProps.ts +15 -0
- package/src/ComicViewer/ComicViewerProps.ts +90 -0
- package/src/ComicViewer/ViewerItem.tsx +76 -0
- package/src/ComicViewer/index.ts +3 -0
- package/src/DateTimePicker/DateTimePicker.tsx +6 -0
- package/src/DateTimePicker/YearPicker.tsx +2 -1
- package/src/FlipCard/FlipCard.tsx +8 -8
- package/src/ViewPager/ChildrenMemoizedPage.tsx +91 -22
- package/src/ViewPager/ViewPagerNative.tsx +47 -35
- package/src/ViewPager/ViewPagerProps.ts +20 -19
- package/src/ViewPager/ViewPagerWeb.tsx +34 -29
- package/src/ViewPager/index.ts +1 -1
- package/src/ViewPager/utils.tsx +2 -55
- package/src/hooks/useHeight.ts +2 -2
- package/src/hooks/useUnstableCollapsibleAppBar.ts +59 -42
- package/src/hooks/useUnstableToggleDisplayStyle.ts +8 -6
- package/src/index.ts +3 -0
- package/build/commonjs/hooks/useWidth.js +0 -29
- package/build/commonjs/hooks/useWidth.js.map +0 -1
- package/build/module/hooks/useWidth.js +0 -15
- package/build/module/hooks/useWidth.js.map +0 -1
- package/build/typescript/hooks/useWidth.d.ts +0 -2
- package/src/hooks/useWidth.ts +0 -17
|
@@ -1,66 +1,78 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { Children, forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
|
|
2
|
+
import type { ViewPagerOnPageSelectedEvent } from 'react-native-pager-view';
|
|
3
|
+
import RNViewPager from 'react-native-pager-view';
|
|
4
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
3
5
|
import type ViewPagerProps from './ViewPagerProps';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
defaultEnableVisibleHint,
|
|
7
|
-
defaultLoading,
|
|
8
|
-
defaultPageComponent,
|
|
9
|
-
usePageRenderer,
|
|
10
|
-
} from './utils';
|
|
6
|
+
import type { ViewPagerInstance } from './ViewPagerProps';
|
|
7
|
+
import { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
const ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {
|
|
13
10
|
const {
|
|
14
11
|
children,
|
|
15
|
-
|
|
16
|
-
index,
|
|
12
|
+
initialPage = defaultInitialPage,
|
|
17
13
|
keyboardDismissMode = 'on-drag',
|
|
18
14
|
loading = defaultLoading,
|
|
19
15
|
onChange,
|
|
20
16
|
pageComponent = defaultPageComponent,
|
|
21
|
-
enableNeighborPageRerender = defaultEnableNeighborPageRerender,
|
|
22
17
|
pageForceRerenderKey,
|
|
23
18
|
scrollEnabled = true,
|
|
24
19
|
style,
|
|
25
20
|
} = props;
|
|
26
21
|
|
|
27
|
-
const
|
|
28
|
-
const pagerRef =
|
|
22
|
+
const sharedIndex = useSharedValue<number>(initialPage);
|
|
23
|
+
const pagerRef = useRef<RNViewPager | null>(null);
|
|
29
24
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
const setPage = (newIndex: number) => {
|
|
26
|
+
requestAnimationFrame(() => {
|
|
27
|
+
pagerRef.current?.setPage(newIndex);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
useImperativeHandle(
|
|
32
|
+
ref,
|
|
33
|
+
() => ({ setPage }),
|
|
34
|
+
[],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const handlePageSelected = useCallback((e: ViewPagerOnPageSelectedEvent) => {
|
|
38
|
+
const currentIndex = sharedIndex.value;
|
|
39
|
+
const nextIndex = e.nativeEvent.position;
|
|
40
|
+
|
|
41
|
+
if (currentIndex === nextIndex) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
indexRef.current = e.nativeEvent.position;
|
|
45
|
+
sharedIndex.value = nextIndex;
|
|
41
46
|
|
|
42
47
|
if (onChange) {
|
|
43
|
-
onChange(
|
|
48
|
+
onChange(nextIndex);
|
|
44
49
|
}
|
|
45
50
|
}, [onChange]);
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
if (index !== indexRef.current) {
|
|
49
|
-
pagerRef.current?.setPage(index);
|
|
50
|
-
}
|
|
51
|
-
}, [index]);
|
|
52
|
+
const PageComponent = pageComponent;
|
|
52
53
|
|
|
53
54
|
return (
|
|
54
55
|
<RNViewPager
|
|
55
|
-
|
|
56
|
+
ref={pagerRef}
|
|
57
|
+
initialPage={initialPage}
|
|
56
58
|
keyboardDismissMode={keyboardDismissMode}
|
|
57
59
|
onPageSelected={handlePageSelected}
|
|
58
60
|
pageMargin={8}
|
|
59
|
-
ref={pagerRef}
|
|
60
61
|
scrollEnabled={scrollEnabled}
|
|
61
62
|
style={style}
|
|
62
63
|
>
|
|
63
|
-
{
|
|
64
|
+
{Children.map(children, (child, index) => (
|
|
65
|
+
<PageComponent
|
|
66
|
+
key={index}
|
|
67
|
+
children={child}
|
|
68
|
+
index={index}
|
|
69
|
+
loading={loading}
|
|
70
|
+
rerenderKey={pageForceRerenderKey}
|
|
71
|
+
sharedIndex={sharedIndex}
|
|
72
|
+
/>
|
|
73
|
+
))}
|
|
64
74
|
</RNViewPager>
|
|
65
75
|
);
|
|
66
|
-
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export default ViewPager;
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from 'react';
|
|
2
2
|
import type { ViewProps } from 'react-native';
|
|
3
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
3
4
|
import type { ComponentProps } from '@fountain-ui/core';
|
|
4
5
|
|
|
5
6
|
export type KeyboardDismissMode = 'none' | 'on-drag';
|
|
6
7
|
|
|
7
|
-
export type PageProps =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export type PageProps = PropsWithChildren<ViewProps> & {
|
|
9
|
+
index: number;
|
|
10
|
+
loading: ViewPagerProps['loading'];
|
|
11
|
+
sharedIndex: SharedValue<number>;
|
|
12
|
+
rerenderKey?: ViewPagerProps['pageForceRerenderKey'];
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
export type PageComponent =
|
|
15
|
+
export type PageComponent = ComponentType<PageProps>;
|
|
14
16
|
|
|
15
17
|
export type Loading = 'lazy' | 'eager';
|
|
16
18
|
|
|
17
|
-
export
|
|
19
|
+
export interface ViewPagerInstance {
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
21
|
+
* Function to scroll to a specific page in the ViewPager. Invalid index is ignored.
|
|
22
|
+
* @param index
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
setPage: (index: number) => void;
|
|
25
|
+
}
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @default false
|
|
26
|
-
*/
|
|
27
|
-
enableVisibleHint?: boolean;
|
|
27
|
+
export default interface ViewPagerProps extends ComponentProps<{
|
|
28
|
+
ref?: Ref<ViewPagerInstance>;
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @default false
|
|
31
|
+
* Collection of ViewPager components.
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
children?: ReactNode;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Index of initial page that should be selected.
|
|
37
|
+
* @default 0
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
+
initialPage?: number;
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { Children, forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { StyleSheet } from '@fountain-ui/core';
|
|
3
5
|
import type ViewPagerProps from './ViewPagerProps';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
defaultEnableVisibleHint,
|
|
7
|
-
defaultLoading,
|
|
8
|
-
defaultPageComponent,
|
|
9
|
-
usePageRenderer,
|
|
10
|
-
} from './utils';
|
|
6
|
+
import type { ViewPagerInstance } from './ViewPagerProps';
|
|
7
|
+
import { defaultInitialPage, defaultLoading, defaultPageComponent } from './utils';
|
|
11
8
|
|
|
12
9
|
const styles = StyleSheet.create({
|
|
13
10
|
root: {
|
|
@@ -15,38 +12,46 @@ const styles = StyleSheet.create({
|
|
|
15
12
|
overflow: 'auto',
|
|
16
13
|
position: 'relative',
|
|
17
14
|
},
|
|
18
|
-
none: { display: 'none' },
|
|
19
15
|
});
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
const ViewPager = forwardRef<ViewPagerInstance, ViewPagerProps>(function ViewPager(props, ref) {
|
|
22
18
|
const {
|
|
23
19
|
children,
|
|
24
|
-
|
|
25
|
-
enableNeighborPageRerender = defaultEnableNeighborPageRerender,
|
|
26
|
-
index,
|
|
20
|
+
initialPage = defaultInitialPage,
|
|
27
21
|
loading = defaultLoading,
|
|
28
22
|
pageComponent = defaultPageComponent,
|
|
29
23
|
pageForceRerenderKey,
|
|
30
24
|
style,
|
|
31
25
|
} = props;
|
|
32
26
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
const sharedIndex = useSharedValue<number>(initialPage);
|
|
28
|
+
|
|
29
|
+
const setPage = (newIndex: number) => {
|
|
30
|
+
sharedIndex.value = newIndex;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
useImperativeHandle(
|
|
34
|
+
ref,
|
|
35
|
+
() => ({ setPage }),
|
|
36
|
+
[],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const PageComponent = pageComponent;
|
|
41
40
|
|
|
42
41
|
return (
|
|
43
42
|
<View style={[styles.root, style]}>
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
{Children.map(children, (child, index) => (
|
|
44
|
+
<PageComponent
|
|
45
|
+
key={index}
|
|
46
|
+
children={child}
|
|
47
|
+
index={index}
|
|
48
|
+
loading={loading}
|
|
49
|
+
rerenderKey={pageForceRerenderKey}
|
|
50
|
+
sharedIndex={sharedIndex}
|
|
51
|
+
/>
|
|
52
|
+
))}
|
|
50
53
|
</View>
|
|
51
54
|
);
|
|
52
|
-
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export default ViewPager;
|
package/src/ViewPager/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from './ViewPagerWeb';
|
|
2
|
-
export type { default as ViewPagerProps } from './ViewPagerProps';
|
|
2
|
+
export type { default as ViewPagerProps, ViewPagerInstance } from './ViewPagerProps';
|
package/src/ViewPager/utils.tsx
CHANGED
|
@@ -1,62 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { Loading, PageComponent } from './ViewPagerProps';
|
|
3
3
|
import ChildrenMemoizedPage from './ChildrenMemoizedPage';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
visited?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface PageRenderOption {
|
|
10
|
-
enableVisibleHint: boolean;
|
|
11
|
-
enableNeighborPageRerender: boolean;
|
|
12
|
-
index: number;
|
|
13
|
-
loading: Loading;
|
|
14
|
-
pageComponent: PageComponent;
|
|
15
|
-
pageForceRerenderKey?: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface PageRenderer {
|
|
19
|
-
(children: ViewPagerProps['children']): React.ReactNode;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const defaultEnableVisibleHint: boolean = false;
|
|
23
|
-
|
|
24
|
-
export const defaultEnableNeighborPageRerender: boolean = false;
|
|
5
|
+
export const defaultInitialPage: number = 0;
|
|
25
6
|
|
|
26
7
|
export const defaultLoading: Loading = 'lazy';
|
|
27
8
|
|
|
28
9
|
export const defaultPageComponent: PageComponent = ChildrenMemoizedPage;
|
|
29
|
-
|
|
30
|
-
export const usePageRenderer = ({
|
|
31
|
-
enableVisibleHint,
|
|
32
|
-
index: currentIndex,
|
|
33
|
-
loading,
|
|
34
|
-
pageComponent: PageComponent,
|
|
35
|
-
pageForceRerenderKey,
|
|
36
|
-
enableNeighborPageRerender,
|
|
37
|
-
}: PageRenderOption): PageRenderer => {
|
|
38
|
-
const pagesStateRef = React.useRef<Array<PageState>>([]);
|
|
39
|
-
|
|
40
|
-
pagesStateRef.current[currentIndex] = {
|
|
41
|
-
...pagesStateRef.current[currentIndex],
|
|
42
|
-
visited: true,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return (children => React.Children.map(children, (child, index) => {
|
|
46
|
-
const visited = pagesStateRef.current[index]?.visited ?? false;
|
|
47
|
-
const content = (loading === 'eager' || visited) ? child : null;
|
|
48
|
-
|
|
49
|
-
const isVisible = enableVisibleHint ? (index === currentIndex) : false;
|
|
50
|
-
const isNeighborIndex = index === currentIndex - 1 || index === currentIndex + 1;
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<PageComponent
|
|
54
|
-
key={index}
|
|
55
|
-
children={content}
|
|
56
|
-
isNeighbor={enableNeighborPageRerender && isNeighborIndex}
|
|
57
|
-
isVisible={isVisible}
|
|
58
|
-
rerenderKey={pageForceRerenderKey}
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
61
|
-
}));
|
|
62
|
-
};
|
package/src/hooks/useHeight.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ViewProps } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
import { useWorkletCallback } from 'react-native-reanimated';
|
|
4
4
|
|
|
5
5
|
type OnLayoutCallback = ViewProps['onLayout'];
|
|
6
6
|
|
|
7
7
|
export default function useHeight(initialHeight = 0): [number, OnLayoutCallback] {
|
|
8
8
|
const [height, setHeight] = React.useState<number>(initialHeight);
|
|
9
9
|
|
|
10
|
-
const onLayout =
|
|
10
|
+
const onLayout = useWorkletCallback((e) => {
|
|
11
11
|
setHeight(e.nativeEvent.layout.height);
|
|
12
12
|
}, []);
|
|
13
13
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useRef } from 'react';
|
|
2
2
|
import { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
import {
|
|
5
|
+
useAnimatedScrollHandler,
|
|
6
|
+
useAnimatedStyle,
|
|
7
|
+
useDerivedValue,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
withTiming,
|
|
10
|
+
} from 'react-native-reanimated';
|
|
4
11
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
12
|
import useAppbarStyles from './useAppbarStyles';
|
|
6
13
|
import useElevationStyle from './useElevationStyle';
|
|
@@ -22,13 +29,12 @@ export interface ContentInsets {
|
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
export interface Options {
|
|
25
|
-
translucent?: boolean;
|
|
26
32
|
shouldTranslateYReset?: boolean;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export interface CollapsibleAppBar {
|
|
30
36
|
appBarStyle: ViewStyleProp;
|
|
31
|
-
vectorY:
|
|
37
|
+
vectorY: SharedValue<number>;
|
|
32
38
|
onAppBarLayout: OnLayoutCallback;
|
|
33
39
|
onCollapsibleToolbarLayout: OnLayoutCallback;
|
|
34
40
|
onScroll: OnScroll;
|
|
@@ -37,7 +43,6 @@ export interface CollapsibleAppBar {
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
const defaultOptions: Required<Options> = {
|
|
40
|
-
translucent: false,
|
|
41
46
|
shouldTranslateYReset: false,
|
|
42
47
|
};
|
|
43
48
|
|
|
@@ -45,7 +50,6 @@ const ANIMATION_DURATION_MILLIS = 100;
|
|
|
45
50
|
|
|
46
51
|
const SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';
|
|
47
52
|
|
|
48
|
-
|
|
49
53
|
function useLargerValueOfLastTwoValues(value: number) {
|
|
50
54
|
const refLatestTwoValues = useRef([0, 0]);
|
|
51
55
|
|
|
@@ -55,12 +59,8 @@ function useLargerValueOfLastTwoValues(value: number) {
|
|
|
55
59
|
return Math.max(...refLatestTwoValues.current);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
|
|
59
62
|
export default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {
|
|
60
|
-
const {
|
|
61
|
-
translucent,
|
|
62
|
-
shouldTranslateYReset,
|
|
63
|
-
}: Required<Options> = {
|
|
63
|
+
const { shouldTranslateYReset }: Required<Options> = {
|
|
64
64
|
...defaultOptions,
|
|
65
65
|
...userOptions,
|
|
66
66
|
};
|
|
@@ -73,38 +73,55 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
73
73
|
const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);
|
|
74
74
|
const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();
|
|
75
75
|
|
|
76
|
-
const maxTranslateY =
|
|
76
|
+
const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);
|
|
77
77
|
|
|
78
|
-
const translateY =
|
|
79
|
-
const lastTranslateY =
|
|
80
|
-
const lastOffsetY =
|
|
81
|
-
const prevOffsetY =
|
|
82
|
-
const overlapped =
|
|
83
|
-
const vectorY =
|
|
78
|
+
const translateY = useSharedValue<number>(0);
|
|
79
|
+
const lastTranslateY = useSharedValue<number>(0);
|
|
80
|
+
const lastOffsetY = useSharedValue<number>(0);
|
|
81
|
+
const prevOffsetY = useSharedValue<number>(0);
|
|
82
|
+
const overlapped = useSharedValue<boolean>(false);
|
|
83
|
+
const vectorY = useSharedValue<number>(0);
|
|
84
84
|
|
|
85
85
|
const elevationStyle = useElevationStyle(4);
|
|
86
|
-
const animatedStyle =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
86
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
87
|
+
const transform = [{ translateY: translateY.value }];
|
|
88
|
+
|
|
89
|
+
if (Platform.OS === 'web') {
|
|
90
|
+
return {
|
|
91
|
+
transform,
|
|
92
|
+
boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (Platform.OS === 'android') {
|
|
96
|
+
return {
|
|
97
|
+
transform,
|
|
98
|
+
elevation: overlapped.value ? elevationStyle?.elevation : 0,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (Platform.OS === 'ios') {
|
|
102
|
+
return {
|
|
103
|
+
transform,
|
|
104
|
+
shadowColor: elevationStyle?.shadowColor,
|
|
105
|
+
shadowOffset: elevationStyle?.shadowOffset,
|
|
106
|
+
shadowRadius: elevationStyle?.shadowRadius,
|
|
107
|
+
shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {};
|
|
111
|
+
}, [
|
|
112
|
+
/**
|
|
113
|
+
* FIXME: Consider add `elevationStyle` to dependencies.
|
|
114
|
+
*/
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
const indexRef = useRef<number>(0);
|
|
118
|
+
const offsetsRef = useRef<Array<number>>([]);
|
|
102
119
|
|
|
103
120
|
const onScrollViewChanged = (nextIndex: number) => {
|
|
104
121
|
const prevIndex = indexRef.current;
|
|
105
122
|
if (prevIndex === nextIndex) {
|
|
106
123
|
if (shouldTranslateYReset) {
|
|
107
|
-
translateY.value =
|
|
124
|
+
translateY.value = withTiming(0, {
|
|
108
125
|
duration: ANIMATION_DURATION_MILLIS,
|
|
109
126
|
});
|
|
110
127
|
|
|
@@ -128,7 +145,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
128
145
|
|
|
129
146
|
// If next ScrollView's offset is too short, expand app bar.
|
|
130
147
|
if (translateY.value < 0 && savedOffsetY < appBarHeight) {
|
|
131
|
-
translateY.value =
|
|
148
|
+
translateY.value = withTiming(0, {
|
|
132
149
|
duration: ANIMATION_DURATION_MILLIS,
|
|
133
150
|
});
|
|
134
151
|
|
|
@@ -136,7 +153,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
136
153
|
}
|
|
137
154
|
};
|
|
138
155
|
|
|
139
|
-
const scrollHandler =
|
|
156
|
+
const scrollHandler = useAnimatedScrollHandler({
|
|
140
157
|
onBeginDrag: () => {
|
|
141
158
|
lastTranslateY.value = translateY.value;
|
|
142
159
|
},
|
|
@@ -162,13 +179,13 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
162
179
|
} else {
|
|
163
180
|
if (offsetY > -maxTy) {
|
|
164
181
|
if (ty === 0) {
|
|
165
|
-
translateY.value =
|
|
182
|
+
translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {
|
|
166
183
|
duration: ANIMATION_DURATION_MILLIS,
|
|
167
184
|
});
|
|
168
185
|
}
|
|
169
186
|
} else {
|
|
170
187
|
if (ty === maxTy) {
|
|
171
|
-
translateY.value =
|
|
188
|
+
translateY.value = withTiming(0, {
|
|
172
189
|
duration: ANIMATION_DURATION_MILLIS,
|
|
173
190
|
});
|
|
174
191
|
}
|
|
@@ -201,17 +218,17 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
201
218
|
|
|
202
219
|
overlapped.value = offsetY + nextTranslateY > 0;
|
|
203
220
|
|
|
204
|
-
translateY.value =
|
|
221
|
+
translateY.value = withTiming(nextTranslateY, {
|
|
205
222
|
duration: ANIMATION_DURATION_MILLIS,
|
|
206
223
|
});
|
|
207
224
|
},
|
|
208
|
-
});
|
|
225
|
+
}, []);
|
|
209
226
|
|
|
210
227
|
const hasCollapsible = collapsibleToolbarHeight > 0;
|
|
211
228
|
|
|
212
229
|
const appBarStyle = [
|
|
213
230
|
animatedStyle,
|
|
214
|
-
|
|
231
|
+
{ paddingTop: safeAreaInsets.top },
|
|
215
232
|
hasCollapsible ? styles.floating : undefined,
|
|
216
233
|
];
|
|
217
234
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
2
|
+
import { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
|
|
2
3
|
|
|
3
4
|
export default function useAnimatedDisplayStyle(
|
|
4
|
-
vectorY:
|
|
5
|
+
vectorY: SharedValue<number>,
|
|
5
6
|
threshold: number = 200,
|
|
6
7
|
defaultDisplay: 'flex' | 'none' = 'flex',
|
|
7
8
|
) {
|
|
8
|
-
const display =
|
|
9
|
+
const display = useSharedValue(defaultDisplay);
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
useAnimatedReaction(
|
|
11
12
|
() => vectorY.value,
|
|
12
13
|
(vy) => {
|
|
13
14
|
if (vy >= threshold) {
|
|
@@ -16,9 +17,10 @@ export default function useAnimatedDisplayStyle(
|
|
|
16
17
|
display.value = 'flex';
|
|
17
18
|
}
|
|
18
19
|
},
|
|
20
|
+
[threshold],
|
|
19
21
|
);
|
|
20
22
|
|
|
21
|
-
return
|
|
23
|
+
return useAnimatedStyle(() => ({
|
|
22
24
|
display: display.value,
|
|
23
|
-
}));
|
|
25
|
+
}), []);
|
|
24
26
|
};
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,9 @@ export * from './FlipCard';
|
|
|
13
13
|
export { default as ViewPager } from './ViewPager';
|
|
14
14
|
export * from './ViewPager';
|
|
15
15
|
|
|
16
|
+
export { default as ComicViewer } from './ComicViewer';
|
|
17
|
+
export * from './ComicViewer';
|
|
18
|
+
|
|
16
19
|
export { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';
|
|
17
20
|
export * from './StatusBarProvider';
|
|
18
21
|
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = useWidth;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function useWidth() {
|
|
15
|
-
const window = (0, _reactNative.useWindowDimensions)();
|
|
16
|
-
|
|
17
|
-
const [width, setWidth] = _react.default.useState(window.width);
|
|
18
|
-
|
|
19
|
-
const onLayout = _react.default.useCallback(e => {
|
|
20
|
-
const newWidth = e.nativeEvent.layout.width;
|
|
21
|
-
|
|
22
|
-
if (newWidth > 0 && Math.round(newWidth) !== Math.round(width)) {
|
|
23
|
-
setWidth(newWidth);
|
|
24
|
-
}
|
|
25
|
-
}, []);
|
|
26
|
-
|
|
27
|
-
return [width, onLayout];
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=useWidth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useWidth.ts"],"names":["useWidth","window","width","setWidth","React","useState","onLayout","useCallback","e","newWidth","nativeEvent","layout","Math","round"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEe,SAASA,QAAT,GAAqD;AAChE,QAAMC,MAAM,GAAG,uCAAf;;AACA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBC,eAAMC,QAAN,CAAeJ,MAAM,CAACC,KAAtB,CAA1B;;AAEA,QAAMI,QAAQ,GAAGF,eAAMG,WAAN,CAAmBC,CAAD,IAA0B;AACzD,UAAMC,QAAQ,GAAGD,CAAC,CAACE,WAAF,CAAcC,MAAd,CAAqBT,KAAtC;;AAEA,QAAIO,QAAQ,GAAG,CAAX,IAAgBG,IAAI,CAACC,KAAL,CAAWJ,QAAX,MAAyBG,IAAI,CAACC,KAAL,CAAWX,KAAX,CAA7C,EAAgE;AAC5DC,MAAAA,QAAQ,CAACM,QAAD,CAAR;AACH;AACJ,GANgB,EAMd,EANc,CAAjB;;AAQA,SAAO,CAACP,KAAD,EAAQI,QAAR,CAAP;AACH","sourcesContent":["import React from 'react';\nimport { LayoutChangeEvent, useWindowDimensions, ViewProps } from 'react-native';\n\nexport default function useWidth(): [number, ViewProps['onLayout']] {\n const window = useWindowDimensions();\n const [width, setWidth] = React.useState(window.width);\n\n const onLayout = React.useCallback((e: LayoutChangeEvent) => {\n const newWidth = e.nativeEvent.layout.width;\n\n if (newWidth > 0 && Math.round(newWidth) !== Math.round(width)) {\n setWidth(newWidth);\n }\n }, []);\n\n return [width, onLayout];\n}"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useWindowDimensions } from 'react-native';
|
|
3
|
-
export default function useWidth() {
|
|
4
|
-
const window = useWindowDimensions();
|
|
5
|
-
const [width, setWidth] = React.useState(window.width);
|
|
6
|
-
const onLayout = React.useCallback(e => {
|
|
7
|
-
const newWidth = e.nativeEvent.layout.width;
|
|
8
|
-
|
|
9
|
-
if (newWidth > 0 && Math.round(newWidth) !== Math.round(width)) {
|
|
10
|
-
setWidth(newWidth);
|
|
11
|
-
}
|
|
12
|
-
}, []);
|
|
13
|
-
return [width, onLayout];
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=useWidth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useWidth.ts"],"names":["React","useWindowDimensions","useWidth","window","width","setWidth","useState","onLayout","useCallback","e","newWidth","nativeEvent","layout","Math","round"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAA4BC,mBAA5B,QAAkE,cAAlE;AAEA,eAAe,SAASC,QAAT,GAAqD;AAChE,QAAMC,MAAM,GAAGF,mBAAmB,EAAlC;AACA,QAAM,CAACG,KAAD,EAAQC,QAAR,IAAoBL,KAAK,CAACM,QAAN,CAAeH,MAAM,CAACC,KAAtB,CAA1B;AAEA,QAAMG,QAAQ,GAAGP,KAAK,CAACQ,WAAN,CAAmBC,CAAD,IAA0B;AACzD,UAAMC,QAAQ,GAAGD,CAAC,CAACE,WAAF,CAAcC,MAAd,CAAqBR,KAAtC;;AAEA,QAAIM,QAAQ,GAAG,CAAX,IAAgBG,IAAI,CAACC,KAAL,CAAWJ,QAAX,MAAyBG,IAAI,CAACC,KAAL,CAAWV,KAAX,CAA7C,EAAgE;AAC5DC,MAAAA,QAAQ,CAACK,QAAD,CAAR;AACH;AACJ,GANgB,EAMd,EANc,CAAjB;AAQA,SAAO,CAACN,KAAD,EAAQG,QAAR,CAAP;AACH","sourcesContent":["import React from 'react';\nimport { LayoutChangeEvent, useWindowDimensions, ViewProps } from 'react-native';\n\nexport default function useWidth(): [number, ViewProps['onLayout']] {\n const window = useWindowDimensions();\n const [width, setWidth] = React.useState(window.width);\n\n const onLayout = React.useCallback((e: LayoutChangeEvent) => {\n const newWidth = e.nativeEvent.layout.width;\n\n if (newWidth > 0 && Math.round(newWidth) !== Math.round(width)) {\n setWidth(newWidth);\n }\n }, []);\n\n return [width, onLayout];\n}"]}
|
package/src/hooks/useWidth.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { LayoutChangeEvent, useWindowDimensions, ViewProps } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export default function useWidth(): [number, ViewProps['onLayout']] {
|
|
5
|
-
const window = useWindowDimensions();
|
|
6
|
-
const [width, setWidth] = React.useState(window.width);
|
|
7
|
-
|
|
8
|
-
const onLayout = React.useCallback((e: LayoutChangeEvent) => {
|
|
9
|
-
const newWidth = e.nativeEvent.layout.width;
|
|
10
|
-
|
|
11
|
-
if (newWidth > 0 && Math.round(newWidth) !== Math.round(width)) {
|
|
12
|
-
setWidth(newWidth);
|
|
13
|
-
}
|
|
14
|
-
}, []);
|
|
15
|
-
|
|
16
|
-
return [width, onLayout];
|
|
17
|
-
}
|