1import { createContext, use, type ComponentProps } from "react";
2import { Platform, ScrollView } from "react-native";
3import { ScrollViewMarker } from "react-native-screens";
4import { nativeHeaderScrollEdgeEffects } from "./scrollEdgeEffects";
5
6type ScrollEdgeEffects = ComponentProps<typeof ScrollViewMarker>["scrollEdgeEffects"];
7
8const DEFAULT_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
9
10export const NativeScrollEdgeEffectsContext = createContext<ScrollEdgeEffects>(undefined);
11
12/** Register the content scroll view and apply its route's native edge settings. */
13export function NativeScrollViewMarker(props: ComponentProps<typeof ScrollViewMarker>) {
14 const effects = use(NativeScrollEdgeEffectsContext);
15 return (
16 <ScrollViewMarker
17 {...props}
18 scrollEdgeEffects={props.scrollEdgeEffects ?? effects ?? DEFAULT_SCROLL_EDGE_EFFECTS}
19 />
20 );
21}
22
23/** Primary screen scrolling; Android keeps its existing native view hierarchy. */
24export function NativeScrollView(props: ComponentProps<typeof ScrollView>) {
25 const scrollView = <ScrollView {...props} />;
26 return Platform.OS === "ios" ? (
27 <NativeScrollViewMarker style={{ flex: 1 }}>{scrollView}</NativeScrollViewMarker>
28 ) : (
29 scrollView
30 );
31}