-
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
Open
wjsdncl
wants to merge
7
commits into
main
Choose a base branch
from
feat/scroll-to-top
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−17
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f83953
feat: 해당하는 페이지에서 하단 탭 터치시 스크롤 최상단으로 이동
wjsdncl e8ce96a
feat: 친구 탭 하위 탭에서 하단 탭 터치 시 스크롤 최상단으로 이동
wjsdncl e485afd
fix: 하단 탭바 터치 시 스크롤 수정
wjsdncl 2cde09f
fix: 스크롤 코드 수정
wjsdncl bbdae4c
fix: 스크롤 수정
wjsdncl 180b228
fix: 친구창 스크롤 수정
wjsdncl f76eaf0
fix: 유저 페이지 이동시 오류 수정
wjsdncl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import colors from "@/constants/colors"; | ||
import useScrollToTop from "@/hooks/useScrollToTop"; | ||
import type { UserProfile } from "@/types/User.interface"; | ||
import { useState } from "react"; | ||
import { useRef, useState } from "react"; | ||
import { | ||
ActivityIndicator, | ||
FlatList, | ||
|
@@ -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,18 @@ export function SearchLayout<T>({ | |
emptyComponent, | ||
}: SearchLayoutProps) { | ||
const [keyword, setKeyword] = useState(""); | ||
const flatListRef = useRef<FlatList>(null); | ||
|
||
useScrollToTop({ | ||
refetch: refetch ?? (() => {}), | ||
flatListRef, | ||
eventName: "SCROLL_FRIEND_TO_TOP", | ||
}); | ||
|
||
return ( | ||
<SafeAreaView edges={[]} className="flex-1 bg-white"> | ||
<FlatList | ||
ref={flatListRef} | ||
className="w-full grow px-6" | ||
data={data} | ||
keyExtractor={(elem) => elem.id} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect } from "react"; | ||
import { DeviceEventEmitter, type FlatList } from "react-native"; | ||
|
||
const useScrollToTop = ({ | ||
flatListRef, | ||
refetch, | ||
eventName, | ||
}: { | ||
flatListRef: React.RefObject<FlatList>; | ||
refetch: () => void; | ||
eventName: string; | ||
}) => { | ||
useEffect(() => { | ||
const subscription = DeviceEventEmitter.addListener(eventName, () => { | ||
flatListRef.current?.scrollToOffset({ offset: 0, animated: true }); | ||
refetch(); | ||
}); | ||
|
||
return () => subscription.remove(); | ||
}, [flatListRef, refetch, eventName]); | ||
}; | ||
|
||
export default useScrollToTop; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
상단탭까지 손가락이 올라가는 것보다는 하단탭 두드리는 게 나을 것 같아요!!