3

I currently have a loop that generates some Animated.Views on top of one another (like in a ZStack). With my code as is, all the views move together on a single swipe rather than one by one on separate swipes. I feel that it has to do with the loop itself but I'm not quite sure what the fix is. Any thoughts?

swipeMainPage.tsx:

{...} from '../../components/ui-components';
import { Swipe } from './swipe';
const SwipeMainPage = () => {
 const dummyData = [
 [...],
 [...],
 [...],
 ];
 
 return (
 const { onTouchStart, onTouchEnd, onTouchMove } = Swipe(
 onSwipeLeft,
 onSwipeRight,
 onSwipeUp
 );
 <Animated.ScrollView
 style={{...}}
 onTouchStart={onTouchStart}
 onTouchEnd={onTouchEnd}
 onTouchMove={onTouchMove}
 >
 {dummyData.map((data, index) => (
 <Animated.View
 key={index}
 style={{
 position: 'absolute',
 width: windowWidth,
 opacity: opacity,
 transform: [
 { translateX: translateX },
 { rotate: rotate },
 { translateY: translateY },
 ],
 }}
 >
 <SwipeCandidateBadge data={data} />
 </Animated.View>
 ))}
 </Animated.ScrollView>
</View>
);
};
export default SwipeMainPage;

swipe.tsx:

import { windowHeight, windowWidth } from '../../components/ui-components';
//reference: https://stackoverflow.com/questions/45854450/detect-swipe-left-in-react-native
export function Swipe(
 swipeLeft?: any,
 swipeRight?: any,
 swipeUp?: any,
 rangeOffset = 10
) {
 let firstTouch = 0;
 function onTouchStart(e: any) {
 firstTouch = e.nativeEvent.pageX;
 }
 function onTouchEnd(e: any) {
 const positionX = e.nativeEvent.pageX;
 const range = windowWidth / rangeOffset;
 if (positionX - firstTouch > range) {
 swipeRight && swipeRight();
 } else if (firstTouch - positionX > range) {
 swipeLeft && swipeLeft();
 }
 }
 function onTouchMove(e: any) {
 const positionY = e.nativeEvent.pageY;
 const range = windowHeight / 2;
 if (positionY - firstTouch < range) {
 swipeUp && swipeUp();
 }
 }
 return { onTouchStart, onTouchEnd, onTouchMove };
}
President James K. Polk
42.3k35 gold badges114 silver badges149 bronze badges
asked Dec 12, 2025 at 23:12
1
  • There is no corresponding tag for your closing </View> in your first file swipeMainPage.tsx. Commented Dec 27, 2025 at 10:06

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.