feat: 앱을 웹과 맞춤 — 좋아요 하트·토스트, 별똥별, 단풍잎, 고운바탕, 안내 높이 유지, 시트 배경 페이드

This commit is contained in:
minaChoi committed 2026-10-14 15:35:49 +09:00
1 parent 865c521ab8
commit b5d9adf396
19 files changed
+247 -52

No files matched your search

+44 -20
View File
@@ -1,6 +1,7 @@
import { subscribeAuth } from '@nalssigak/shared/api/auth';
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
import { KeyboardAvoidingView, Modal, Platform, Pressable, Text, View } from 'react-native';
import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { SheetContext, useSheet, type SheetState } from '@/lib/sheet';
@@ -31,8 +32,29 @@ export function SheetProvider({ children }: { children: ReactNode }) {
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', comments: '댓글', login: '로그인', me: '내 정보', region: '지역 바꾸기' } as const;
/** 아래에서 올라오는 창. 바깥을 누르거나 뒤로 가기(안드로이드)로 닫는다 */
function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void }) {
/** 판만 아래에서 올라온다 (웹 b-sheet: 0.26초, 40px 아래·흐릿하게에서) */
function Rise({ children }: { children: ReactNode }) {
const reduce = useReducedMotion();
const p = useSharedValue(reduce ? 1 : 0);
useEffect(() => {
p.value = withTiming(1, { duration: 260, easing: Easing.bezier(0.2, 0.9, 0.3, 1) });
}, [p]);
const anim = useAnimatedStyle(() => ({ opacity: 0.4 + 0.6 * p.value, transform: [{ translateY: 40 * (1 - p.value) }] }));
return <Animated.View style={[{ width: '100%', maxHeight: '86%', alignItems: 'center' }, anim]}>{children}</Animated.View>;
}
/** 아래에서 올라오는 창. 배경은 제자리에서 서서히. 바깥을 누르거나 뒤로 가기(안드로이드)로 닫는다 */
function SheetHost({ state: next, onClose }: { state: SheetState; onClose: () => void }) {
// 닫는 동안(배경이 사라지는 동안)에도 마지막 내용을 그대로 보여 준다. 열 때마다 판을 새로 올린다
const [last, setLast] = useState<SheetState>(next);
const [isOpen, setIsOpen] = useState(next != null);
const [opens, setOpens] = useState(0);
if (next && next !== last) setLast(next);
if ((next != null) !== isOpen) {
setIsOpen(next != null);
if (next) setOpens((n) => n + 1);
}
const state = next ?? last;
const { open } = useSheet();
const { bottom } = useSafeAreaInsets();
const [gakTitle, setGakTitle] = useState('');
@@ -42,28 +64,30 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
const title = !state ? '' : state.type === 'gak' ? gakTitle : state.type === 'article' ? articleTitle || TITLES.article : TITLES[state.type];
return (
<Modal visible={state != null} transparent animationType="slide" onRequestClose={onClose} statusBarTranslucent>
<Modal visible={next != null} transparent animationType="fade" onRequestClose={onClose} statusBarTranslucent>
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} className="flex-1 justify-end">
<Pressable onPress={onClose} accessibilityLabel="닫기" className="absolute inset-0 bg-[rgb(20_26_45/0.45)]" />
{state && (
<View accessibilityViewIsModal accessibilityLabel={title} className="max-h-[86%] w-full max-w-[440px] self-center rounded-t-[22px] bg-card" style={{ paddingBottom: bottom }}>
<View className="border-b border-line px-4 pt-2 pb-2.5">
<View className="mb-2.5 h-1 w-10 self-center rounded-full bg-line" />
<Text numberOfLines={1} className="px-10 text-center text-[15px] font-extrabold text-ink">
{title}
</Text>
<Pressable onPress={onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel="닫기" className="absolute right-3 bottom-2 size-[30px] items-center justify-center">
<Text className="text-xl text-ink2">×</Text>
</Pressable>
<Rise key={opens}>
<View accessibilityViewIsModal accessibilityLabel={title} className="w-full max-w-[440px] rounded-t-[22px] bg-card" style={{ paddingBottom: bottom }}>
<View className="border-b border-line px-4 pt-2 pb-2.5">
<View className="mb-2.5 h-1 w-10 self-center rounded-full bg-line" />
<Text numberOfLines={1} className="px-10 text-center text-[15px] font-extrabold text-ink">
{title}
</Text>
<Pressable onPress={onClose} hitSlop={10} accessibilityRole="button" accessibilityLabel="닫기" className="absolute right-3 bottom-2 size-[30px] items-center justify-center">
<Text className="text-xl text-ink2">×</Text>
</Pressable>
</View>
{state.type === 'gak' && <GakSheet indexId={state.indexId} onTitle={setGakTitle} />}
{state.type === 'article' && <ArticleSheet articleId={state.articleId} onTitle={setArticleTitle} />}
{state.type === 'seasonWeek' && <SeasonWeekSheet />}
{state.type === 'comments' && <CommentsSheet postId={state.postId} draft={state.draft} />}
{state.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
{state.type === 'me' && <MeSheet onDone={onClose} />}
{state.type === 'region' && <RegionSheet onDone={onClose} />}
</View>
{state.type === 'gak' && <GakSheet indexId={state.indexId} onTitle={setGakTitle} />}
{state.type === 'article' && <ArticleSheet articleId={state.articleId} onTitle={setArticleTitle} />}
{state.type === 'seasonWeek' && <SeasonWeekSheet />}
{state.type === 'comments' && <CommentsSheet postId={state.postId} draft={state.draft} />}
{state.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
{state.type === 'me' && <MeSheet onDone={onClose} />}
{state.type === 'region' && <RegionSheet onDone={onClose} />}
</View>
</Rise>
)}
</KeyboardAvoidingView>
</Modal>