-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31601 from Expensify/amy-revert-21298
Revert #21298
- Loading branch information
Showing
13 changed files
with
26 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,4 @@ | ||
import React, {useEffect, useRef} from 'react'; | ||
import {View} from 'react-native'; | ||
import DomUtils from '@libs/DomUtils'; | ||
import SwipeableViewProps from './types'; | ||
|
||
// Min delta y in px to trigger swipe | ||
const MIN_DELTA_Y = 25; | ||
|
||
function SwipeableView({onSwipeUp, onSwipeDown, style, children}: SwipeableViewProps) { | ||
const ref = useRef<View | null>(null); | ||
const scrollableChildRef = useRef<HTMLElement | null>(null); | ||
const startY = useRef(0); | ||
const isScrolling = useRef(false); | ||
|
||
useEffect(() => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
const element = ref.current as unknown as HTMLElement; | ||
|
||
const handleTouchStart = (event: TouchEvent) => { | ||
startY.current = event.touches[0].clientY; | ||
}; | ||
|
||
const handleTouchEnd = (event: TouchEvent) => { | ||
const deltaY = event.changedTouches[0].clientY - startY.current; | ||
const isSelecting = DomUtils.isActiveTextSelection(); | ||
let canSwipeDown = true; | ||
let canSwipeUp = true; | ||
if (scrollableChildRef.current) { | ||
canSwipeUp = scrollableChildRef.current.scrollHeight - scrollableChildRef.current.scrollTop === scrollableChildRef.current.clientHeight; | ||
canSwipeDown = scrollableChildRef.current.scrollTop === 0; | ||
} | ||
|
||
if (deltaY > MIN_DELTA_Y && onSwipeDown && !isSelecting && canSwipeDown && !isScrolling.current) { | ||
onSwipeDown(); | ||
} | ||
|
||
if (deltaY < -MIN_DELTA_Y && onSwipeUp && !isSelecting && canSwipeUp && !isScrolling.current) { | ||
onSwipeUp(); | ||
} | ||
isScrolling.current = false; | ||
}; | ||
|
||
const handleScroll = (event: Event) => { | ||
isScrolling.current = true; | ||
if (!event.target || scrollableChildRef.current) { | ||
return; | ||
} | ||
scrollableChildRef.current = event.target as HTMLElement; | ||
}; | ||
|
||
element.addEventListener('touchstart', handleTouchStart); | ||
element.addEventListener('touchend', handleTouchEnd); | ||
element.addEventListener('scroll', handleScroll, true); | ||
|
||
return () => { | ||
element.removeEventListener('touchstart', handleTouchStart); | ||
element.removeEventListener('touchend', handleTouchEnd); | ||
element.removeEventListener('scroll', handleScroll); | ||
}; | ||
}, [onSwipeDown, onSwipeUp]); | ||
|
||
return ( | ||
<View | ||
ref={ref} | ||
style={style} | ||
> | ||
{children} | ||
</View> | ||
); | ||
} | ||
|
||
SwipeableView.displayName = 'SwipeableView'; | ||
|
||
export default SwipeableView; | ||
// Swipeable View is available just on Android/iOS for now. | ||
export default ({children}: SwipeableViewProps) => children; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
import {ReactNode} from 'react'; | ||
import {StyleProp, ViewStyle} from 'react-native'; | ||
|
||
type SwipeableViewProps = { | ||
/** The content to be rendered within the SwipeableView */ | ||
children: ReactNode; | ||
|
||
/** Callback to fire when the user swipes down on the child content */ | ||
onSwipeDown?: () => void; | ||
|
||
/** Callback to fire when the user swipes up on the child content */ | ||
onSwipeUp?: () => void; | ||
|
||
/** Style for the wrapper View, applied only for the web version. Not used by the native version, as it brakes the layout. */ | ||
style?: StyleProp<ViewStyle>; | ||
onSwipeDown: () => void; | ||
}; | ||
|
||
export default SwipeableViewProps; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.