Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/components/common/ConfirmModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { View, Text, StyleSheet, Modal, Pressable } from 'react-native';
import colors from '../../style/colors';
import typography from '../../style/typography';

const ConfirmModal = ({
isVisible,
onClose,
onConfirm,
title,
description,
confirmText = '확인',
cancelText = '취소',
}) => {
return (
<Modal
visible={isVisible}
transparent={true}
animationType="fade"
onRequestClose={onClose}
>
<Pressable style={styles.overlay} onPress={onClose}>
<Pressable style={styles.card} onPress={() => {}}>
<Text style={styles.title}>{title}</Text>
{description ? (
<Text style={styles.description}>{description}</Text>
) : null}
<Pressable style={styles.confirmButton} onPress={onConfirm}>
<Text style={styles.confirmText}>{confirmText}</Text>
</Pressable>
<Pressable style={styles.cancelButton} onPress={onClose}>
<Text style={styles.cancelText}>{cancelText}</Text>
</Pressable>
</Pressable>
</Pressable>
</Modal>
);
};

const styles = StyleSheet.create({
overlay: {
flex: 1,
backgroundColor: 'rgba(0, 0, 0, 0.4)',
justifyContent: 'center',
alignItems: 'center',
},
card: {
width: 300,
backgroundColor: colors.common.white,
borderRadius: 20,
paddingTop: 32,
paddingBottom: 24,
paddingHorizontal: 24,
alignItems: 'center',
},
title: {
...typography.heading5,
color: colors.gray[850],
textAlign: 'center',
marginBottom: 8,
},
description: {
...typography.body3Regular,
color: colors.gray[500],
textAlign: 'center',
marginBottom: 24,
},
confirmButton: {
width: '100%',
paddingVertical: 14,
borderRadius: 12,
backgroundColor: colors.blue[400],
alignItems: 'center',
marginBottom: 12,
},
confirmText: {
...typography.heading6,
color: colors.common.white,
},
cancelButton: {
paddingVertical: 4,
alignItems: 'center',
},
cancelText: {
...typography.body3Regular,
color: colors.gray[500],
},
});

export default ConfirmModal;
94 changes: 94 additions & 0 deletions src/components/common/Toast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import typography from '@/style/typography';
import React, { useEffect, useRef } from 'react';
import { Text, StyleSheet, Animated, useWindowDimensions } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

const TAB_BAR_HEIGHT = 49;

const Toast = ({
message,
visible,
duration = 2000,
onHide,
hasNavBar = true,
tabBarHeight = TAB_BAR_HEIGHT,
}) => {
const opacity = useRef(new Animated.Value(0)).current;
const translateY = useRef(new Animated.Value(20)).current;
const { height: screenHeight } = useWindowDimensions();
const insets = useSafeAreaInsets();

const bottomPosition = hasNavBar
? insets.bottom + tabBarHeight + 22
: screenHeight - 736;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD: 상수보다는 여기도 뭔가 동적으로 계산할 수 있으면 좋을 거 같아요.


useEffect(() => {
if (visible) {
Animated.parallel([
Animated.timing(opacity, {
toValue: 1,
duration: 250,
useNativeDriver: true,
}),
Animated.timing(translateY, {
toValue: 0,
duration: 250,
useNativeDriver: true,
}),
]).start();

const timer = setTimeout(() => {
hideToast();
}, duration);

return () => clearTimeout(timer);
}
}, [visible]);

const hideToast = () => {
Animated.parallel([
Animated.timing(opacity, {
toValue: 0,
duration: 200,
useNativeDriver: true,
}),
Animated.timing(translateY, {
toValue: 20,
duration: 200,
useNativeDriver: true,
}),
]).start(() => {
onHide && onHide();
});
};

if (!visible) return null;

return (
<Animated.View
style={[
styles.container,
{ opacity, transform: [{ translateY }], bottom: bottomPosition },
]}
>
<Text style={styles.text}>{message}</Text>
</Animated.View>
);
};

const styles = StyleSheet.create({
container: {
position: 'absolute',
alignSelf: 'center',
backgroundColor: '#595F63CC',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD: colors.gray[700]에 투명도 80%가 더 좋아 보입니다!

paddingHorizontal: 20,
paddingVertical: 12,
borderRadius: 50,
},
text: {
color: 'white',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD: 이 부분도 colors.common.white 가 맞아 보여요!

...typography.body4Regular,
},
});

export default Toast;
15 changes: 10 additions & 5 deletions src/screens/Affiliation/AffiliationDetailScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { AFFILIATION_RECOMMEND_DATA } from '../../constants/DummyData';
import PlaceHolderRepresentativeImage from '../../../assets/placeHolderImage.svg';
import BadgeIcon from '../../../assets/badgeIcon.svg';
import CouponIcon from '../../../assets/couponIcon.svg';
import Toast from '../../components/common/Toast';
import {
getStudentAffiliateDetail,
getStudentAffiliateRecommendList,
Expand All @@ -46,6 +47,8 @@ const AffiliationDetailScreen = ({ navigation, route }) => {
const [isEmpty, setIsEmpty] = useState(true);
const [recommendData, setRecommendData] = useState([]);
const [imagesLoaded, setImagesLoaded] = useState({}); // 각 이미지의 로딩 상태 추적
const [toastVisible, setToastVisible] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD: 이 부분이 계속 여기저기 반복되는 거 같은데, 커스텀 훅이나 중간에서 관리하는 방법이 있으면 좋을 거 같습니다..!

const [toastMessage, setToastMessage] = useState('');
const [isFirstImageLoaded, setIsFirstImageLoaded] = useState(false); // 첫 번째 이미지 로딩 상태
const shimmerAnim = useRef(new Animated.Value(0)).current;

Expand Down Expand Up @@ -276,6 +279,8 @@ const AffiliationDetailScreen = ({ navigation, route }) => {
if (detailData) {
setDetailData({ ...detailData, liked: newLikedState });
}
setToastMessage(newLikedState ? '관심 목록에 추가되었어요!' : '관심 목록에서 삭제되었어요.');
setToastVisible(true);
} catch (error) {
// 실패 시 롤백
setIsLiked(!newLikedState);
Expand Down Expand Up @@ -389,6 +394,11 @@ const AffiliationDetailScreen = ({ navigation, route }) => {
</View>
)}
</ScrollView>
<Toast
message={toastMessage}
visible={toastVisible}
onHide={() => setToastVisible(false)}
/>
</SafeAreaView>
);
};
Expand Down Expand Up @@ -553,10 +563,6 @@ const styles = StyleSheet.create({
alignItems: 'flex-start',
justifyContent: 'flex-start',
},
recommendTitle: {
...typography.body4Bold,
color: colors.gray[850],
},
placeType: {
...typography.caption2Regular,
color: colors.gray[700],
Expand All @@ -573,7 +579,6 @@ const styles = StyleSheet.create({
flexDirection: 'row',
alignItems: 'center',
marginLeft: -2,
alignItems: 'flex-start',
},
detailDistanceWrapper: {
flexDirection: 'row',
Expand Down
10 changes: 10 additions & 0 deletions src/screens/Affiliation/AffiliationLikedScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { AFFILIATION_RECOMMEND_DATA } from '../../constants/DummyData';
import PlaceHolderRepresentativeImage from '../../../assets/placeHolderImage.svg';
import BadgeIcon from '../../../assets/badgeIcon.svg';
import CouponIcon from '../../../assets/couponIcon.svg';
import Toast from '../../components/common/Toast';
import {
getStudentAffiliateDetail,
getStudentAffiliateRecommendList,
Expand All @@ -46,6 +47,8 @@ const AffiliationLikedScreen = ({ navigation, route }) => {
const [isEmpty, setIsEmpty] = useState(true);
const [recommendData, setRecommendData] = useState([]);
const [imagesLoaded, setImagesLoaded] = useState({}); // 각 이미지의 로딩 상태 추적
const [toastVisible, setToastVisible] = useState(false);
const [toastMessage, setToastMessage] = useState('');
const [isFirstImageLoaded, setIsFirstImageLoaded] = useState(false); // 첫 번째 이미지 로딩 상태
const shimmerAnim = useRef(new Animated.Value(0)).current;

Expand Down Expand Up @@ -276,6 +279,8 @@ const AffiliationLikedScreen = ({ navigation, route }) => {
if (detailData) {
setDetailData({ ...detailData, liked: newLikedState });
}
setToastMessage(newLikedState ? '관심 목록에 추가되었어요!' : '관심 목록에서 삭제되었어요.');
setToastVisible(true);
} catch (error) {
// 실패 시 롤백
setIsLiked(!newLikedState);
Expand Down Expand Up @@ -389,6 +394,11 @@ const AffiliationLikedScreen = ({ navigation, route }) => {
</View>
)}
</ScrollView>
<Toast
message={toastMessage}
visible={toastVisible}
onHide={() => setToastVisible(false)}
/>
</SafeAreaView>
);
};
Expand Down
Loading