Skip to content

8주차 미션_담담 - #24

Open
sungs25 wants to merge 7 commits into
mainfrom
week8
Open

sungs25 wants to merge 7 commits into
mainfrom
week8

Conversation

@sungs25

@sungs25 sungs25 commented May 22, 2026

Copy link
Copy Markdown
Collaborator

📝 작업 내용

  • Home / Wishlist / Shop Fragment의 RecyclerView를 ComposeView로 교체
  • 아이템 레이아웃을 ProductCard / ShopProductCard Composable로 재작성
  • LazyVerticalGrid + items() + key 적용
  • Shop의 하트 토글에 State Hoisting 패턴 적용
  • 사용하지 않게 된 Adapter, item XML, 미사용 string 정리

📸 스크린샷

3주차 화면 그대로


🙏 리뷰 요구사항 (선택)

  • Shop 하트 토글에서 mutableStateListOf + product.copy()로 상태를 관리했는데, indexOf로 위치를 찾는 방식이 적절한지 궁금합니다. 더 나은 패턴이 있다면 피드백 부탁드립니다.
  • 현재 keyproduct.name으로 잡았는데, ProductData에 id 필드를 추가하는 게 정석일지 의견 듣고 싶습니다.

@kimdoyeon1234 kimdoyeon1234 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

수고하셨습니다!!

LazyVerticalGrid + items() DSL을 올바르게 사용하신 점, key를 명시적으로 지정해주신 점 좋았습니다! 다만 현재 key = { product -> product.name }으로 지정하고 계신데, name은 중복되거나 변경될 수 있어서 key의 조건인 고유(unique)하고 안정적(stable)을 만족하지 못할 수 있습니다! ProductData에 id 필드를 추가하고 key = { product -> product.id }로 사용하는 걸 추천드립니다!

그리고 HomeFragment, WishlistFragment는 아이템이 2개로 고정되어 있는데, 이런 경우엔 LazyVerticalGrid 대신 Column + Row 조합이 더 가볍습니다! Lazy 계열은 아이템 수가 많거나 동적으로 변하는 경우에 사용할 때 좋습니다!

id 필드만 추가해주시면 indexOf 문제와 key 문제가 한 번에 해결되니 꼭 적용해보세요! 수고하셨습니다!

Comment on lines +51 to +53
key = { product -> product.name }
) { product ->
ProductCard(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

현재 key = { product -> product.name }으로 지정하고 계신데, name은 중복되거나 변경될 수 있어서 key의 조건인 고유하고 안정적을 만족하지 못할 수 있습니다! ProductData에 id 필드를 추가하고 key = { product -> product.id }로 사용하는 걸 추천드립니다!

Comment on lines +66 to +70
onFavoriteClick = {
val idx = products.indexOf(product)
if (idx >= 0) {
products[idx] = product.copy(
isFavorite = !product.isFavorite

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

products.indexOf(product)는 동일한 name/price를 가진 아이템이 있을 경우 의도치 않은 인덱스가 반환될 수 있습니다! 1번 피드백처럼 id 필드 추가 후 products.indexOfFirst { it.id == product.id }로 변경하시면 더 안전합니다!

Comment on lines +46 to +74

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.composeWishlist.apply {
setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
)
setContent {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
contentPadding = PaddingValues(bottom = 16.dp)
) {
items(
items = wishList,
key = { product -> product.name }
) { product ->
ProductCard(
imageResId = product.imageResId,
category = product.category,
name = product.name,
price = product.price
)
}
}
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

아이템이 2개로 고정되어 있는 경우엔 LazyVerticalGrid 대신 Column + Row 조합이 더 가볍습니다! Lazy 계열은 아이템 수가 많거나 동적으로 변하는 경우에 사용할 때 더 좋습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants