@fountain-ui/lab 2.0.0-beta.5 → 2.0.0-beta.8
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 +3 -5
- 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 +1 -1
- 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 +16 -11
- package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
- package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +1 -1
- package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
- package/build/commonjs/ComicViewer/ViewerItem.js +4 -3
- package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
- package/build/commonjs/ComicViewer/index.js.map +1 -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 +21 -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 +5 -11
- 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 +1 -1
- package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerNative.js +19 -16
- package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
- 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 +13 -11
- 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 +49 -46
- package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js +7 -9
- package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
- package/build/commonjs/index.js +10 -10
- package/build/commonjs/index.js.map +1 -1
- package/build/module/AnimatedY/AnimatedY.js +4 -4
- 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 +1 -1
- 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 +16 -11
- package/build/module/ComicViewer/ComicViewer.js.map +1 -1
- package/build/module/ComicViewer/ComicViewerItemProps.js.map +1 -1
- package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
- package/build/module/ComicViewer/ViewerItem.js +4 -3
- package/build/module/ComicViewer/ViewerItem.js.map +1 -1
- package/build/module/ComicViewer/index.js.map +1 -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 +21 -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 +5 -5
- 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 +1 -1
- package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
- package/build/module/ViewPager/ViewPagerNative.js +15 -10
- package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
- package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
- 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 +11 -10
- 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 +51 -38
- package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
- package/build/module/hooks/useUnstableToggleDisplayStyle.js +7 -5
- package/build/module/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
- 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 +0 -1
- 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/ViewPagerNative.d.ts +0 -1
- package/build/typescript/ViewPager/ViewPagerWeb.d.ts +0 -1
- package/build/typescript/hooks/useUnstableCollapsibleAppBar.d.ts +2 -3
- package/build/typescript/hooks/useUnstableToggleDisplayStyle.d.ts +2 -2
- package/package.json +11 -10
- package/src/AnimatedY/AnimatedY.tsx +4 -4
- package/src/FlipCard/FlipCard.tsx +6 -6
- package/src/ViewPager/ViewPagerNative.tsx +18 -11
- package/src/hooks/useHeight.ts +2 -2
- package/src/hooks/useUnstableCollapsibleAppBar.ts +47 -34
- package/src/hooks/useUnstableToggleDisplayStyle.ts +6 -5
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fountain-ui/lab",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Fountain-UI Team",
|
|
6
6
|
"description": "Incubator for Fountain-UI React components.",
|
|
@@ -15,20 +15,21 @@
|
|
|
15
15
|
"prepare": "bob build"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@emotion/react": "^11.
|
|
19
|
-
"@emotion/styled": "^11.
|
|
20
|
-
"@fountain-ui/icons": "^2.0.0-beta.
|
|
18
|
+
"@emotion/react": "^11.10.0",
|
|
19
|
+
"@emotion/styled": "^11.10.0",
|
|
20
|
+
"@fountain-ui/icons": "^2.0.0-beta.6",
|
|
21
21
|
"@fountain-ui/utils": "^2.0.0-beta.3",
|
|
22
22
|
"react-native-calendars": "1.1267.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@fountain-ui/core": "^2.0.0-beta.3",
|
|
26
26
|
"@gorhom/bottom-sheet": "^4.1.3",
|
|
27
|
-
"@react-native-community/viewpager": "> 4.2.x",
|
|
28
27
|
"date-fns": "^2.0.0",
|
|
29
28
|
"react": "^16.8.0 || ^17.0.0",
|
|
30
29
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
31
30
|
"react-native": "^0.63.0",
|
|
31
|
+
"react-native-gesture-handler": "^2.0.0",
|
|
32
|
+
"react-native-pager-view": "^5.0.0",
|
|
32
33
|
"react-native-snap-carousel": "^3.9.0",
|
|
33
34
|
"react-slick": "^0.25.0"
|
|
34
35
|
},
|
|
@@ -36,9 +37,6 @@
|
|
|
36
37
|
"@gorhom/bottom-sheet": {
|
|
37
38
|
"optional": true
|
|
38
39
|
},
|
|
39
|
-
"@react-native-community/viewpager": {
|
|
40
|
-
"optional": true
|
|
41
|
-
},
|
|
42
40
|
"react-dom": {
|
|
43
41
|
"optional": true
|
|
44
42
|
},
|
|
@@ -48,16 +46,19 @@
|
|
|
48
46
|
"react-slick": {
|
|
49
47
|
"optional": true
|
|
50
48
|
},
|
|
49
|
+
"react-native-pager-view": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
51
52
|
"react-native-snap-carousel": {
|
|
52
53
|
"optional": true
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@gorhom/bottom-sheet": "4.1.3",
|
|
57
|
-
"@react-native-community/viewpager": "^4.2.2",
|
|
58
58
|
"@types/react-native-snap-carousel": "^3.8.4",
|
|
59
59
|
"@types/react-slick": "^0.23.5",
|
|
60
60
|
"date-fns": "^2.23.0",
|
|
61
|
+
"react-native-pager-view": "^5.4.25",
|
|
61
62
|
"react-native-safe-area-context": "^3.3.2",
|
|
62
63
|
"react-native-snap-carousel": "^3.9.1",
|
|
63
64
|
"react-slick": "^0.28.1"
|
|
@@ -84,5 +85,5 @@
|
|
|
84
85
|
"publishConfig": {
|
|
85
86
|
"access": "public"
|
|
86
87
|
},
|
|
87
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "3de48896d62f1ba687558ea11b5f527cb91b5da6"
|
|
88
89
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import Animated, { Easing } from 'react-native-reanimated';
|
|
2
|
+
import Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
3
3
|
import type AnimatedYProps from './AnimatedYProps';
|
|
4
4
|
|
|
5
5
|
export default function AnimatedY(props: AnimatedYProps) {
|
|
@@ -9,14 +9,14 @@ export default function AnimatedY(props: AnimatedYProps) {
|
|
|
9
9
|
style,
|
|
10
10
|
} = props;
|
|
11
11
|
|
|
12
|
-
const animatedY =
|
|
13
|
-
const animatedStyle =
|
|
12
|
+
const animatedY = useSharedValue(translateY);
|
|
13
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
14
14
|
transform: [{ translateY: animatedY.value }],
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
17
|
React.useEffect(() => {
|
|
18
18
|
if (translateY >= 0) {
|
|
19
|
-
animatedY.value =
|
|
19
|
+
animatedY.value = withTiming(translateY, {
|
|
20
20
|
duration: 150,
|
|
21
21
|
easing: Easing.out(Easing.exp),
|
|
22
22
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import { StyleSheet, View } from 'react-native';
|
|
3
|
-
import Animated from 'react-native-reanimated';
|
|
3
|
+
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
4
4
|
import type FlipCardProps from './FlipCardProps';
|
|
5
5
|
|
|
6
6
|
const styles = StyleSheet.create({
|
|
@@ -27,9 +27,9 @@ export default function FlipCard(props: FlipCardProps) {
|
|
|
27
27
|
style,
|
|
28
28
|
} = props;
|
|
29
29
|
|
|
30
|
-
const sharedAngle =
|
|
30
|
+
const sharedAngle = useSharedValue(0);
|
|
31
31
|
|
|
32
|
-
const animatedFrontCardStyle =
|
|
32
|
+
const animatedFrontCardStyle = useAnimatedStyle(() => {
|
|
33
33
|
return {
|
|
34
34
|
zIndex: sharedAngle.value < Z_INDEX_CHANGE_ANGLE ? 2 : 1,
|
|
35
35
|
transform: [
|
|
@@ -39,7 +39,7 @@ export default function FlipCard(props: FlipCardProps) {
|
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
const animatedBackCardStyle =
|
|
42
|
+
const animatedBackCardStyle = useAnimatedStyle(() => {
|
|
43
43
|
return {
|
|
44
44
|
zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,
|
|
45
45
|
transform: [
|
|
@@ -51,7 +51,7 @@ export default function FlipCard(props: FlipCardProps) {
|
|
|
51
51
|
|
|
52
52
|
useEffect(() => {
|
|
53
53
|
sharedAngle.value = 0;
|
|
54
|
-
sharedAngle.value =
|
|
54
|
+
sharedAngle.value = withTiming(180, { duration: 500 });
|
|
55
55
|
}, [reanimationKey]);
|
|
56
56
|
|
|
57
57
|
return (
|
|
@@ -65,4 +65,4 @@ export default function FlipCard(props: FlipCardProps) {
|
|
|
65
65
|
</Animated.View>
|
|
66
66
|
</View>
|
|
67
67
|
);
|
|
68
|
-
};
|
|
68
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import type { PagerViewOnPageSelectedEvent } from 'react-native-pager-view';
|
|
3
|
+
import RNPagerView from 'react-native-pager-view';
|
|
3
4
|
import type ViewPagerProps from './ViewPagerProps';
|
|
4
5
|
import {
|
|
5
6
|
defaultEnableNeighborPageRerender,
|
|
@@ -24,8 +25,8 @@ export default function ViewPager(props: ViewPagerProps) {
|
|
|
24
25
|
style,
|
|
25
26
|
} = props;
|
|
26
27
|
|
|
27
|
-
const indexRef =
|
|
28
|
-
const pagerRef =
|
|
28
|
+
const indexRef = useRef<number>(index);
|
|
29
|
+
const pagerRef = useRef<RNPagerView | null>(null);
|
|
29
30
|
|
|
30
31
|
const renderer = usePageRenderer({
|
|
31
32
|
enableVisibleHint,
|
|
@@ -36,7 +37,7 @@ export default function ViewPager(props: ViewPagerProps) {
|
|
|
36
37
|
enableNeighborPageRerender,
|
|
37
38
|
});
|
|
38
39
|
|
|
39
|
-
const handlePageSelected =
|
|
40
|
+
const handlePageSelected = useCallback((e: PagerViewOnPageSelectedEvent) => {
|
|
40
41
|
indexRef.current = e.nativeEvent.position;
|
|
41
42
|
|
|
42
43
|
if (onChange) {
|
|
@@ -44,14 +45,20 @@ export default function ViewPager(props: ViewPagerProps) {
|
|
|
44
45
|
}
|
|
45
46
|
}, [onChange]);
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
pagerRef.current?.setPage(index)
|
|
50
|
-
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const handleNumber = index !== indexRef.current
|
|
50
|
+
? requestAnimationFrame(() => pagerRef.current?.setPage(index))
|
|
51
|
+
: undefined;
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
if (handleNumber) {
|
|
55
|
+
cancelAnimationFrame(handleNumber);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
51
58
|
}, [index]);
|
|
52
59
|
|
|
53
60
|
return (
|
|
54
|
-
<
|
|
61
|
+
<RNPagerView
|
|
55
62
|
initialPage={index}
|
|
56
63
|
keyboardDismissMode={keyboardDismissMode}
|
|
57
64
|
onPageSelected={handlePageSelected}
|
|
@@ -61,6 +68,6 @@ export default function ViewPager(props: ViewPagerProps) {
|
|
|
61
68
|
style={style}
|
|
62
69
|
>
|
|
63
70
|
{renderer(children)}
|
|
64
|
-
</
|
|
71
|
+
</RNPagerView>
|
|
65
72
|
);
|
|
66
73
|
};
|
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
1
|
import React, { 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
|
|
|
@@ -57,10 +62,7 @@ function useLargerValueOfLastTwoValues(value: number) {
|
|
|
57
62
|
|
|
58
63
|
|
|
59
64
|
export default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {
|
|
60
|
-
const {
|
|
61
|
-
translucent,
|
|
62
|
-
shouldTranslateYReset,
|
|
63
|
-
}: Required<Options> = {
|
|
65
|
+
const { shouldTranslateYReset }: Required<Options> = {
|
|
64
66
|
...defaultOptions,
|
|
65
67
|
...userOptions,
|
|
66
68
|
};
|
|
@@ -73,28 +75,39 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
73
75
|
const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);
|
|
74
76
|
const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();
|
|
75
77
|
|
|
76
|
-
const maxTranslateY =
|
|
78
|
+
const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight);
|
|
77
79
|
|
|
78
|
-
const translateY =
|
|
79
|
-
const lastTranslateY =
|
|
80
|
-
const lastOffsetY =
|
|
81
|
-
const prevOffsetY =
|
|
82
|
-
const overlapped =
|
|
83
|
-
const vectorY =
|
|
80
|
+
const translateY = useSharedValue<number>(0);
|
|
81
|
+
const lastTranslateY = useSharedValue<number>(0);
|
|
82
|
+
const lastOffsetY = useSharedValue<number>(0);
|
|
83
|
+
const prevOffsetY = useSharedValue<number>(0);
|
|
84
|
+
const overlapped = useSharedValue<boolean>(false);
|
|
85
|
+
const vectorY = useSharedValue<number>(0);
|
|
84
86
|
|
|
85
87
|
const elevationStyle = useElevationStyle(4);
|
|
86
|
-
const animatedStyle =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
89
|
+
if (Platform.OS === 'web') {
|
|
90
|
+
return {
|
|
91
|
+
transform: [{ translateY: translateY.value }],
|
|
92
|
+
boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (Platform.OS === 'android') {
|
|
96
|
+
return {
|
|
97
|
+
transform: [{ translateY: translateY.value }],
|
|
98
|
+
elevation: overlapped.value ? elevationStyle?.elevation : 0,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (Platform.OS === 'ios') {
|
|
102
|
+
return {
|
|
103
|
+
transform: [{ translateY: translateY.value }],
|
|
104
|
+
shadowColor: elevationStyle?.shadowColor,
|
|
105
|
+
shadowOffset: elevationStyle?.shadowOffset,
|
|
106
|
+
shadowRadius: elevationStyle?.shadowRadius,
|
|
107
|
+
shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {};
|
|
98
111
|
});
|
|
99
112
|
|
|
100
113
|
const indexRef = React.useRef<number>(0);
|
|
@@ -104,7 +117,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
104
117
|
const prevIndex = indexRef.current;
|
|
105
118
|
if (prevIndex === nextIndex) {
|
|
106
119
|
if (shouldTranslateYReset) {
|
|
107
|
-
translateY.value =
|
|
120
|
+
translateY.value = withTiming(0, {
|
|
108
121
|
duration: ANIMATION_DURATION_MILLIS,
|
|
109
122
|
});
|
|
110
123
|
|
|
@@ -128,7 +141,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
128
141
|
|
|
129
142
|
// If next ScrollView's offset is too short, expand app bar.
|
|
130
143
|
if (translateY.value < 0 && savedOffsetY < appBarHeight) {
|
|
131
|
-
translateY.value =
|
|
144
|
+
translateY.value = withTiming(0, {
|
|
132
145
|
duration: ANIMATION_DURATION_MILLIS,
|
|
133
146
|
});
|
|
134
147
|
|
|
@@ -136,7 +149,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
136
149
|
}
|
|
137
150
|
};
|
|
138
151
|
|
|
139
|
-
const scrollHandler =
|
|
152
|
+
const scrollHandler = useAnimatedScrollHandler({
|
|
140
153
|
onBeginDrag: () => {
|
|
141
154
|
lastTranslateY.value = translateY.value;
|
|
142
155
|
},
|
|
@@ -162,13 +175,13 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
162
175
|
} else {
|
|
163
176
|
if (offsetY > -maxTy) {
|
|
164
177
|
if (ty === 0) {
|
|
165
|
-
translateY.value =
|
|
178
|
+
translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {
|
|
166
179
|
duration: ANIMATION_DURATION_MILLIS,
|
|
167
180
|
});
|
|
168
181
|
}
|
|
169
182
|
} else {
|
|
170
183
|
if (ty === maxTy) {
|
|
171
|
-
translateY.value =
|
|
184
|
+
translateY.value = withTiming(0, {
|
|
172
185
|
duration: ANIMATION_DURATION_MILLIS,
|
|
173
186
|
});
|
|
174
187
|
}
|
|
@@ -201,7 +214,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
201
214
|
|
|
202
215
|
overlapped.value = offsetY + nextTranslateY > 0;
|
|
203
216
|
|
|
204
|
-
translateY.value =
|
|
217
|
+
translateY.value = withTiming(nextTranslateY, {
|
|
205
218
|
duration: ANIMATION_DURATION_MILLIS,
|
|
206
219
|
});
|
|
207
220
|
},
|
|
@@ -211,7 +224,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
|
|
|
211
224
|
|
|
212
225
|
const appBarStyle = [
|
|
213
226
|
animatedStyle,
|
|
214
|
-
|
|
227
|
+
{ paddingTop: safeAreaInsets.top },
|
|
215
228
|
hasCollapsible ? styles.floating : undefined,
|
|
216
229
|
];
|
|
217
230
|
|
|
@@ -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) {
|
|
@@ -18,7 +19,7 @@ export default function useAnimatedDisplayStyle(
|
|
|
18
19
|
},
|
|
19
20
|
);
|
|
20
21
|
|
|
21
|
-
return
|
|
22
|
+
return useAnimatedStyle(() => ({
|
|
22
23
|
display: display.value,
|
|
23
24
|
}));
|
|
24
25
|
};
|
|
@@ -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
|
-
}
|