NativeScrollEvent
code:react-native/Libraries/Components/ScrollView/ScrollView.d.ts
export interface NativeScrollEvent {
contentInset: NativeScrollRectangle;
contentOffset: NativeScrollPoint;
contentSize: NativeScrollSize;
layoutMeasurement: NativeScrollSize;
velocity?: NativeScrollVelocity | undefined;
zoomScale: number;
/**
* @platform ios
*/
targetContentOffset?: NativeScrollPoint | undefined;
}
https://gyazo.com/91addc92125f6a0ff5ee5d9858ce002e https://stackoverflow.com/a/53035034
イメージ
code:ts
const handleScroll = (e: NativeScrollEvent) => {
if (isCloseToRight(e)(offset)) {...}
if (isCloseToLeft(e)(offset)) {...}
};
const isCloseToRight =
({ layoutMeasurement, contentOffset, contentSize }: NativeScrollEvent) =>
(threshold: number) => {
return (
layoutMeasurement.width + contentOffset.x >=
contentSize.width - threshold
);
};
const isCloseToLeft =
({ contentOffset }: NativeScrollEvent) =>
(threshold: number) => {
return contentOffset.x <= threshold;
};