(null);
+
+const NO_CONTENT_DRAG: ContentDrag = { attach: undefined, setActive: () => {} };
+
+export function useContentDrag(): ContentDrag {
+ return useContext(ContentDragContext) ?? NO_CONTENT_DRAG;
+}
+
+function useNoAttach(): AttachSheetContentDrag | undefined {
+ return undefined;
+}
+
+/**
+ * Makes a scroll view host content drags: it stops scrolling while a child drag is active. Without
+ * it, a vertical drag in a row of a scrolling page is taken by the page scroll once the finger
+ * moves past the touch slop, before the row's drag gesture can activate. A sheet's scroll view
+ * passes `useAttach` so its children can also register their gesture with the sheet.
+ *
+ * The context wraps the scroll view rather than its content, so the scroll view receives its
+ * children as given: `stickyHeaderIndices` counts them.
+ */
+export function withContentDrag(
+ Scroll: ComponentType
}>,
+ useAttach: () => AttachSheetContentDrag | undefined = useNoAttach,
+) {
+ return forwardRef(function ContentDragScrollView(props, ref) {
+ const attach = useAttach();
+ const [dragging, setDragging] = useState(false);
+ const contentDrag = useMemo(() => ({ attach, setActive: setDragging }), [attach]);
+ // Overriding one prop of `P` keeps it a `P`; TypeScript cannot prove that for a generic.
+ const scrollProps = {
+ ...props,
+ scrollEnabled: !dragging && props.scrollEnabled !== false,
+ } as P;
+ return (
+
+
+
+ );
+ });
+}
diff --git a/packages/app/src/components/ui/scroll-view.tsx b/packages/app/src/components/ui/scroll-view.tsx
index 9cba9551fe..cc18b207b6 100644
--- a/packages/app/src/components/ui/scroll-view.tsx
+++ b/packages/app/src/components/ui/scroll-view.tsx
@@ -1,4 +1,4 @@
-import { createContext, forwardRef, useContext, useMemo, useState, type Ref } from "react";
+import { forwardRef, type Ref } from "react";
import {
ScrollView as NativeScrollView,
FlatList as NativeFlatList,
@@ -12,15 +12,13 @@ import {
type NativeViewGestureHandlerProps,
} from "react-native-gesture-handler";
import { isNative } from "@/constants/platform";
-import {
- useAttachSheetContentDrag,
- useIsInsideBottomSheet,
- type AttachSheetContentDrag,
-} from "./bottom-sheet-scope";
+import { useAttachSheetContentDrag, useIsInsideBottomSheet } from "./bottom-sheet-scope";
+import { withContentDrag } from "./content-drag";
-// Both libraries forward to the RN FlatList instance. Their published ref types
+// Both libraries forward to the RN FlatList and ScrollView instances. Their published ref types
// disagree about getScrollResponder (Gorhom) and include the component function
// in the instance intersection (RNGH); keep that type discrepancy at this boundary.
+const SheetScroll = BottomSheetScrollView as unknown as typeof NativeScrollView;
const SheetFlatList = BottomSheetFlatList as unknown as typeof NativeFlatList;
const HorizontalFlatList = GestureFlatList as unknown as - (
props: FlatListProps
- & NativeViewGestureHandlerProps & { ref?: Ref> },
@@ -30,7 +28,7 @@ const HorizontalFlatList = GestureFlatList as unknown as
- (
export const ScrollView = forwardRef(
function ScrollView(props, ref) {
const inSheet = useIsInsideBottomSheet();
- if (!inSheet) return ;
+ if (!inSheet) return ;
if (props.horizontal) {
return isNative ? (
@@ -42,42 +40,11 @@ export const ScrollView = forwardRef(
},
);
-/**
- * What a child that drags inside a sheet needs to keep the touch: it registers its drag gesture
- * through `attach` so the sheet's pan waits for it, and `setActive(true)` stops the sheet's
- * scroll until the drag ends. Outside a sheet scroll there is no `attach` and `setActive` does
- * nothing.
- */
-export interface ContentDrag {
- attach: AttachSheetContentDrag | undefined;
- setActive: (active: boolean) => void;
-}
+const PageScrollView = withContentDrag(NativeScrollView);
-const ContentDragContext = createContext(null);
-
-const NO_CONTENT_DRAG: ContentDrag = { attach: undefined, setActive: () => {} };
-
-export function useContentDrag(): ContentDrag {
- return useContext(ContentDragContext) ?? NO_CONTENT_DRAG;
-}
-
-const SheetScrollView = forwardRef(
- function SheetScrollView(props, ref) {
- const attach = useAttachSheetContentDrag();
- const [dragging, setDragging] = useState(false);
- const contentDrag = useMemo(() => ({ attach, setActive: setDragging }), [attach]);
- return (
-
-
- {props.children}
-
-
- );
- },
+const SheetScrollView = withContentDrag(
+ SheetScroll,
+ useAttachSheetContentDrag,
);
function SheetAwareFlatList
- (props: FlatListProps
- , ref: Ref>) {