| 1 | import { createContext, use, type ComponentProps } from "react"; |
| 2 | import { Platform, ScrollView } from "react-native"; |
| 3 | import { ScrollViewMarker } from "react-native-screens"; |
| 4 | import { nativeHeaderScrollEdgeEffects } from "./scrollEdgeEffects"; |
| 5 | |
| 6 | type ScrollEdgeEffects = ComponentProps<typeof ScrollViewMarker>["scrollEdgeEffects"]; |
| 7 | |
| 8 | const DEFAULT_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version); |
| 9 | |
| 10 | export const NativeScrollEdgeEffectsContext = createContext<ScrollEdgeEffects>(undefined); |
| 11 | |
| 12 | /** Register the content scroll view and apply its route's native edge settings. */ |
| 13 | export 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. */ |
| 24 | export 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 | } |