@artsy/palette-mobile 17.26.0 → 17.27.0
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/dist/elements/Screen/ScreenScrollContext.d.ts +0 -2
- package/dist/elements/Screen/ScreenScrollContext.js +0 -7
- package/dist/elements/Screen/hooks/useListenForScreenScroll.js +1 -7
- package/dist/elements/Screen/hooks/useShowLargeTitle.js +2 -2
- package/dist/elements/Tabs/hooks/useListenForTabContentScroll.js +4 -9
- package/package.json +1 -1
- package/dist/elements/Screen/hooks/useAnimatedHeaderScrolling.d.ts +0 -2
- package/dist/elements/Screen/hooks/useAnimatedHeaderScrolling.js +0 -38
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
import { SharedValue } from "react-native-reanimated";
|
|
3
3
|
export interface ScreenScrollContextProps {
|
|
4
4
|
currentScrollYAnimated: SharedValue<number>;
|
|
5
|
-
currentScrollY: number;
|
|
6
|
-
updateCurrentScrollY: (scrollY: number) => void;
|
|
7
5
|
scrollYOffset?: number;
|
|
8
6
|
scrollViewDimensionsAnimated: SharedValue<number>;
|
|
9
7
|
updateScrollYOffset: (offset: number) => void;
|
|
@@ -4,26 +4,19 @@ import { useSharedValue } from "react-native-reanimated";
|
|
|
4
4
|
const ScreenScrollContext = createContext({
|
|
5
5
|
// Casting this value as ShareValue because we set it to useSharedValue(0) on Mount
|
|
6
6
|
currentScrollYAnimated: null,
|
|
7
|
-
currentScrollY: 0,
|
|
8
|
-
updateCurrentScrollY: () => { },
|
|
9
7
|
scrollYOffset: undefined,
|
|
10
8
|
// Casting this value as ShareValue because we set it to useSharedValue(0) on Mount
|
|
11
9
|
scrollViewDimensionsAnimated: null,
|
|
12
10
|
updateScrollYOffset: () => { },
|
|
13
11
|
});
|
|
14
12
|
export const ScreenScrollContextProvider = ({ children, }) => {
|
|
15
|
-
const [currentScrollY, setCurrentScrollY] = useState(0);
|
|
16
13
|
const [scrollYOffset, setScrollYOffset] = useState(undefined);
|
|
17
14
|
const currentScrollYAnimated = useSharedValue(0);
|
|
18
15
|
const scrollViewDimensionsAnimated = useSharedValue(0);
|
|
19
16
|
const providerValue = {
|
|
20
17
|
currentScrollYAnimated,
|
|
21
|
-
currentScrollY,
|
|
22
18
|
scrollYOffset,
|
|
23
19
|
scrollViewDimensionsAnimated,
|
|
24
|
-
updateCurrentScrollY: (scrollY) => {
|
|
25
|
-
setCurrentScrollY(scrollY);
|
|
26
|
-
},
|
|
27
20
|
updateScrollYOffset: (yOffset) => {
|
|
28
21
|
setScrollYOffset(yOffset);
|
|
29
22
|
},
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
1
|
import { useAnimatedScrollHandler } from "react-native-reanimated";
|
|
3
|
-
import { useAnimatedHeaderScrolling } from "./useAnimatedHeaderScrolling";
|
|
4
2
|
import { useScreenScrollContext } from "../ScreenScrollContext";
|
|
5
3
|
export const useListenForScreenScroll = () => {
|
|
6
|
-
const {
|
|
7
|
-
const scrollY = useAnimatedHeaderScrolling(currentScrollYAnimated, scrollYOffset);
|
|
4
|
+
const { currentScrollYAnimated, scrollViewDimensionsAnimated } = useScreenScrollContext();
|
|
8
5
|
const scrollHandler = useAnimatedScrollHandler({
|
|
9
6
|
onScroll: (event) => {
|
|
10
7
|
currentScrollYAnimated.set(() => event.contentOffset.y);
|
|
11
8
|
scrollViewDimensionsAnimated.set(() => event.contentSize.height);
|
|
12
9
|
},
|
|
13
10
|
});
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
updateCurrentScrollY(scrollY);
|
|
16
|
-
}, [scrollY, updateCurrentScrollY]);
|
|
17
11
|
return {
|
|
18
12
|
scrollHandler,
|
|
19
13
|
};
|
|
@@ -4,7 +4,7 @@ import { useScreenScrollContext } from "../ScreenScrollContext";
|
|
|
4
4
|
import { BOTTOM_TABS_HEIGHT, STICKY_BAR_HEIGHT } from "../StickySubHeader";
|
|
5
5
|
import { NAVBAR_HEIGHT } from "../constants";
|
|
6
6
|
export const useShowLargeTitle = ({ stickyBarHeight }) => {
|
|
7
|
-
const {
|
|
7
|
+
const { scrollYOffset = 0, currentScrollYAnimated, scrollViewDimensionsAnimated, } = useScreenScrollContext();
|
|
8
8
|
const { height: screenHeight } = Dimensions.get("window");
|
|
9
9
|
const scrollViewContentHeight = screenHeight - NAVBAR_HEIGHT - STICKY_BAR_HEIGHT - BOTTOM_TABS_HEIGHT;
|
|
10
10
|
const visible = useDerivedValue(() => {
|
|
@@ -22,7 +22,7 @@ export const useShowLargeTitle = ({ stickyBarHeight }) => {
|
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
return currentScrollYAnimated.value < NAVBAR_HEIGHT + scrollYOffset;
|
|
25
|
-
}, [
|
|
25
|
+
}, [scrollYOffset, stickyBarHeight, currentScrollYAnimated]);
|
|
26
26
|
return {
|
|
27
27
|
visible,
|
|
28
28
|
};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
1
|
import { useCurrentTabScrollY } from "react-native-collapsible-tab-view";
|
|
3
2
|
import { useAnimatedReaction } from "react-native-reanimated";
|
|
4
3
|
import { useScreenScrollContext } from "../../Screen/ScreenScrollContext";
|
|
5
|
-
import { useAnimatedHeaderScrolling } from "../../Screen/hooks/useAnimatedHeaderScrolling";
|
|
6
4
|
export const useListenForTabContentScroll = () => {
|
|
7
|
-
|
|
8
|
-
const { updateCurrentScrollY, scrollYOffset, currentScrollYAnimated } = useScreenScrollContext();
|
|
5
|
+
const { currentScrollYAnimated } = useScreenScrollContext();
|
|
9
6
|
const currentTabScrollY = useCurrentTabScrollY();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, [scrollY, updateCurrentScrollY]);
|
|
14
|
-
useAnimatedReaction(() => currentTabScrollY.value, (current) => {
|
|
7
|
+
useAnimatedReaction(() => currentTabScrollY.value,
|
|
8
|
+
// TODO: improve the conditions here
|
|
9
|
+
(current) => {
|
|
15
10
|
currentScrollYAnimated?.set(current);
|
|
16
11
|
});
|
|
17
12
|
};
|
package/package.json
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { runOnJS, useAnimatedReaction, useSharedValue } from "react-native-reanimated";
|
|
3
|
-
import { NAVBAR_HEIGHT } from "../constants";
|
|
4
|
-
export const useAnimatedHeaderScrolling = (scrollY, scrollYOffset = 0) => {
|
|
5
|
-
const listenForScroll = useSharedValue(true);
|
|
6
|
-
const [currScrollY, setCurrScrollY] = useState(scrollY.value);
|
|
7
|
-
const HEADER_HEIGHT = useMemo(() => NAVBAR_HEIGHT + scrollYOffset, [scrollYOffset]);
|
|
8
|
-
// Needed to run on JS thread
|
|
9
|
-
const update = (y) => {
|
|
10
|
-
setCurrScrollY(y);
|
|
11
|
-
};
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const timer = setTimeout(() => {
|
|
14
|
-
listenForScroll.set(() => false);
|
|
15
|
-
}, 1000);
|
|
16
|
-
return () => {
|
|
17
|
-
clearTimeout(timer);
|
|
18
|
-
};
|
|
19
|
-
}, [listenForScroll.get()]);
|
|
20
|
-
useAnimatedReaction(() => {
|
|
21
|
-
return [scrollY.value, listenForScroll.get()];
|
|
22
|
-
}, ([animatedScrollY, isListeningForScroll], previousScroll) => {
|
|
23
|
-
const [prevScrollY] = previousScroll ?? [0, false];
|
|
24
|
-
// Hacky way to avoid some weird header behavior.
|
|
25
|
-
// look at HACKS.md for more info.
|
|
26
|
-
const suddenlyScrolled = Math.abs(animatedScrollY - prevScrollY) > HEADER_HEIGHT;
|
|
27
|
-
if (isListeningForScroll && suddenlyScrolled) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const prevTitleShown = prevScrollY >= HEADER_HEIGHT;
|
|
31
|
-
const currTitleShown = animatedScrollY >= HEADER_HEIGHT;
|
|
32
|
-
if (prevTitleShown === currTitleShown) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
runOnJS(update)(Math.floor(animatedScrollY));
|
|
36
|
-
}, [scrollY, HEADER_HEIGHT]);
|
|
37
|
-
return currScrollY;
|
|
38
|
-
};
|