-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 해당하는 페이지에서 하단 탭 터치시 스크롤 최상단으로 이동 #162
base: main
Are you sure you want to change the base?
Changes from 4 commits
1f83953
e8ce96a
e485afd
2cde09f
bbdae4c
180b228
f76eaf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,10 @@ import useRefresh from "@/hooks/useRefresh"; | |
import { getPostLikes, getPosts } from "@/utils/supabase"; | ||
import { useRouter } from "expo-router"; | ||
import * as SecureStore from "expo-secure-store"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
import { | ||
ActivityIndicator, | ||
DeviceEventEmitter, | ||
Dimensions, | ||
FlatList, | ||
Image, | ||
|
@@ -33,6 +34,7 @@ export default function Home() { | |
const [selectedPostId, setSelectedPostId] = useState<number | null>(null); | ||
const [selectedAuthorId, setSelectedAuthorId] = useState<string | null>(null); | ||
const [isLikedModalVisible, setIsLikedModalVisible] = useState(false); | ||
const flatListRef = useRef<FlatList>(null); | ||
const { openModal } = useModal(); | ||
|
||
const router = useRouter(); | ||
|
@@ -91,9 +93,24 @@ export default function Home() { | |
handleLoadId(); | ||
}, []); | ||
|
||
const handleScrollToTop = useCallback(() => { | ||
flatListRef.current?.scrollToOffset({ offset: 0, animated: true }); | ||
refetch(); | ||
}, [refetch]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이벤트 리스너 콜백 함수 구현에 오류가 있습니다. 이벤트 리스너에서 다음과 같이 수정해주세요: useEffect(() => {
const subscription = DeviceEventEmitter.addListener(
"SCROLL_HOME_TO_TOP",
- () => handleScrollToTop,
+ handleScrollToTop,
);
return () => subscription.remove();
}, [handleScrollToTop]); Also applies to: 101-108 |
||
|
||
useEffect(() => { | ||
const subscription = DeviceEventEmitter.addListener( | ||
"SCROLL_HOME_TO_TOP", | ||
() => handleScrollToTop, | ||
); | ||
|
||
return () => subscription.remove(); | ||
}, [handleScrollToTop]); | ||
|
||
return ( | ||
<SafeAreaView edges={[]} className="flex-1 items-center justify-center"> | ||
<FlatList | ||
ref={flatListRef} | ||
data={data?.pages.flatMap((page) => page.data) ?? []} | ||
keyExtractor={(item) => item.id.toString()} | ||
contentContainerStyle={{ gap: 10 }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import colors from "@/constants/colors"; | ||
import type { UserProfile } from "@/types/User.interface"; | ||
import { useState } from "react"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
import { | ||
ActivityIndicator, | ||
DeviceEventEmitter, | ||
FlatList, | ||
type ListRenderItemInfo, | ||
View, | ||
|
@@ -11,6 +12,7 @@ import { SafeAreaView } from "react-native-safe-area-context"; | |
import SearchBar from "./SearchBar"; | ||
|
||
interface SearchLayoutProps { | ||
refetch?: () => void; | ||
data: UserProfile[]; // 추후 검색 사용 범위 넓어지면 변경 가능 | ||
isFetchingNextPage?: boolean; | ||
onChangeKeyword: (newKeyword: string) => void; | ||
|
@@ -20,6 +22,7 @@ interface SearchLayoutProps { | |
} | ||
|
||
export function SearchLayout<T>({ | ||
refetch, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 제네릭 타입 T가 사용되지 않고 있습니다. 컴포넌트에 제네릭 타입 다음과 같이 개선하는 것을 제안드립니다: - export function SearchLayout<T>({
+ export function SearchLayout<T extends { id: string }>({
refetch,
- data: UserProfile[],
+ data: T[],
...
- renderItem: (itemInfo: ListRenderItemInfo<UserProfile>) => React.ReactElement;
+ renderItem: (itemInfo: ListRenderItemInfo<T>) => React.ReactElement;
|
||
data, | ||
isFetchingNextPage, | ||
onChangeKeyword, | ||
|
@@ -28,10 +31,26 @@ export function SearchLayout<T>({ | |
emptyComponent, | ||
}: SearchLayoutProps) { | ||
const [keyword, setKeyword] = useState(""); | ||
const flatListRef = useRef<FlatList>(null); | ||
|
||
const handleScrollToTop = useCallback(() => { | ||
flatListRef.current?.scrollToOffset({ offset: 0, animated: true }); | ||
refetch?.(); | ||
}, [refetch]); | ||
|
||
useEffect(() => { | ||
const subscription = DeviceEventEmitter.addListener( | ||
"SCROLL_FRIEND_TO_TOP", | ||
() => handleScrollToTop, | ||
); | ||
|
||
return () => subscription.remove(); | ||
}, [handleScrollToTop]); | ||
|
||
return ( | ||
<SafeAreaView edges={[]} className="flex-1 bg-white"> | ||
<FlatList | ||
ref={flatListRef} | ||
className="w-full grow px-6" | ||
data={data} | ||
keyExtractor={(elem) => elem.id} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 게 되네요!!👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상단탭까지 손가락이 올라가는 것보다는 하단탭 두드리는 게 나을 것 같아요!!