Skip to content

Commit

Permalink
fix: 체크리스트 슬라이드
Browse files Browse the repository at this point in the history
로직 수정
#70
  • Loading branch information
11t518s committed Mar 31, 2022
1 parent 8d7a3c0 commit d533e3e
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions components/CheckListComponent/CheckListComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Dispatch, SetStateAction, useEffect } from 'react';
import { View } from 'react-native';
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { Pressable, View } from 'react-native';
import { checkListTypes } from '../../types/checkListTypes';
import styles from './styles';
import ButtonsOfTypeA from './ButtonsOfTypeA';
Expand Down Expand Up @@ -30,6 +30,9 @@ interface IProps {
setCheckLists: Dispatch<SetStateAction<checkListTypes[]>>;
onBoarding: boolean;
}
type ContextType = {
translateX: number;
};

function CheckListComponent({
modal,
Expand All @@ -43,13 +46,16 @@ function CheckListComponent({
onBoarding,
}: IProps) {
const translateX = useSharedValue(0);
const [isDelete, setIsDelete] = useState(false);

const panGesture = useAnimatedGestureHandler<PanGestureHandlerGestureEvent>({
onActive: (event) => {
translateX.value = event.translationX;
console.log(event.translationX);
if (event.translationX > 0) {
return;
const panGesture = useAnimatedGestureHandler<PanGestureHandlerGestureEvent, ContextType>({
onStart: (event, context) => {
context.translateX = translateX.value;
},
onActive: (event, context) => {
translateX.value = event.translationX + context.translateX;
if (event.translationX + context.translateX > 0) {
translateX.value = 0;
}
},
onEnd: () => {
Expand All @@ -71,18 +77,24 @@ function CheckListComponent({
}));

useEffect(() => {
translateX.value = 0;
}, [isEdit]);
translateX.value = withTiming(0);
}, [isEdit, isDelete]);

return (
<View style={styles.checkListWrapper}>
<PanGestureHandler
enabled={!onBoarding && isEdit}
onGestureEvent={panGesture}
activeOffsetX={[-0, 100]}
failOffsetX={[-10, 0]}
>
<Animated.View style={[rStyle]}>
<View style={styles.whiteCard} key={checkList.questionId}>
<Pressable
onTouchMove={() => {
setIsDelete(!isDelete);
}}
style={styles.whiteCard}
key={checkList.questionId}
>
<DefaultText style={styles.checkListMainTitle}>{checkList.question}</DefaultText>
<View style={styles.subTitles}>
{checkList.rule ? (
Expand Down Expand Up @@ -137,7 +149,7 @@ function CheckListComponent({
/>
) : null}
</View>
</View>
</Pressable>
</Animated.View>
</PanGestureHandler>
<ButtonOfGoToTrash
Expand Down

0 comments on commit d533e3e

Please sign in to comment.