Skip to content

feat: 8주차 미션_제로#58

Open
jeongkyueun wants to merge 7 commits into
mainfrom
zero-m8
Open

feat: 8주차 미션_제로#58
jeongkyueun wants to merge 7 commits into
mainfrom
zero-m8

Conversation

@jeongkyueun
Copy link
Copy Markdown
Collaborator

@jeongkyueun jeongkyueun commented May 20, 2026

📌 feat: 8주차 미션_제로

기존 XML 기반의 RecyclerView와 Adapter 구조를 Jetpack Compose의 LazyColumn으로 마이그레이션하여 UI 선언형 구조로 개선하고 코드 복잡도를 줄였습니다.

🔗 관련 이슈

Closes #이슈번호

✨ 변경 사항

기존 RecyclerView + Adapter 코드를 LazyColumn으로 교체
items() 함수를 사용하여 리스트 데이터 표시
아이템 레이아웃을 ProductItem Composable 함수로 새로 작성
각 아이템에 고유한 key를 지정하여 상태 안정성 확보

  1. 신규 Composable 컴포넌트 생성 (ProductCompose.kt)
  • ProductItem: 기존 item_product.xml을 대체. 이미지, 상품 정보, 위시리스트 버튼을 포함하는 컴포저블 구현.
  • ProductList: LazyColumn을 사용하여 리스트를 렌더링하며, key 값으로 product.id를 설정하여 리스트 업데이트 효율을 높였습니다.
  1. Fragment 마이그레이션
  • HomeFragment:

    • 전체 레이아웃을 LazyColumn 하나로 통합했습니다.
    • 기존 NestedScrollView 내부에 LazyColumn이 위치할 때 발생하던 무한 높이 크래시(IllegalStateException) 문제를 해결하기 위해, 상단 배너와 텍스트 섹션을 item { ... }으로 통합 관리하도록 개선했습니다.
  • WishlistFragment & PurchaseFragment:

    • XML 레이아웃의 RecyclerView를 ComposeView로 교체하고, 마이그레이션한 ProductList를 연결했습니다.
  1. 상태 관리 (State Management)
  • mutableStateListOf와 remember를 사용하여 위시리스트 클릭 시 해당 아이템의 상태가 즉시 UI에 반영되도록 구현했습니다.
  1. 코드 및 리소스 최적화
  • 파일 삭제: 사용하지 않는 ProductAdapter.kt, item_product.xml, fragment_home.xml 제거
  • Navigation 수정: nav_graph.xml에서 삭제된 레이아웃 참조(tools:layout)를 제거하여 빌드 경고를 해결했습니다.

참고 사항: HomeFragment는 XML 레이아웃을 사용하지 않고 onCreateView에서 ComposeView를 생성하여 반환하는 방식으로 전환되어 결합도를 낮췄습니다.

🔍 테스트

  • 테스트 완료
  • 에러 없음

📸 스크린샷 (선택)

구매하기 위시리스트 장바구니 프로필
image image image image image

🚨 추가 이슈

@jeongkyueun jeongkyueun self-assigned this May 20, 2026
Comment on lines +40 to +52
@Composable
fun HomeScreen() {
val dummyProducts = remember {
mutableStateListOf(
Product(1, "Air Jordan XXXVI", "Basketball Shoes", "US$185", R.drawable.img_air_jordan_xxxvi, category = "Basketball Shoes"),
Product(2, "Nike Air Force 1 '07", "Men's Shoes", "US$115", R.drawable.img_nike_air_force, category = "Men's Shoes"),
Product(3, "Nike Everyday Plus Cushioned", "Training Socks", "US$20", R.drawable.img_nike_everyday_plus_cushioned, category = "Training Socks")
)
}

LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 16.dp)
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.

lazyColumn 좋아요ㅎㅎ


private fun setupComposeView() {
// Dummy wishlist data
val dummyWishlist = listOf(
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.

더미를 페이지마다 만들지 말고 하나의 리스트로 통합하는 것도 좋을 것 같아요!

Copy link
Copy Markdown
Collaborator

@kimdoyeon1234 kimdoyeon1234 left a comment

Choose a reason for hiding this comment

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

LazyVerticalGrid + items() DSL과 key를 올바르게 사용하신 점, ProductGrid, ProductList, ProductItem을 별도 파일로 분리해서 재사용성을 높이신 점 좋았습니다!

다만 HomeScreen Composable 함수가 HomeFragment 클래스 내부에 정의되어 있는데, Composable 함수는 Fragment 밖으로 분리하는 게 좋습니다! 별도의 HomeScreen.kt 파일로 분리해주세요!

그리고 Product 데이터 클래스의 isWishlisted 필드가 var로 선언되어 있는데, val로 선언하고 copy()로 새 객체를 만들어서 상태를 업데이트하는 패턴을 사용해주세요! Compose에서는 var 필드를 직접 변경해도 Recomposition이 트리거되지 않습니다!
더미 데이터도 각 Fragment마다 따로 선언되어 있는데, ViewModel로 통합 관리하시면 화면 간 상태 공유도 자연스럽게 해결됩니다!

아쉽게도 이번 미션의 핵심인 Compose 기반 Navigation으로의 전환이 아직 적용되지 않았습니다!

Fragment + XML 기반 Navigation 대신 NavController + NavHost + Type-safe Navigation으로 전환해주시면 완성도가 훨씬 올라갑니다! 화이팅

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.

HomeScreen() Composable 함수가 HomeFragment 클래스 내부에 정의되어 있는데, Composable 함수는 Fragment 밖으로 분리하는 게 좋습니다! 별도의 HomeScreen.kt 파일로 분리해주시면 가독성과 재사용성이 훨씬 좋아집니다!

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.

LazyColumn의 item { } 블록 안에 LazyRow를 중첩하고 있는데, 스크롤 방향이 달라서 크래시는 발생하지 않지만 LazyRow의 높이 측정이 제대로 되지 않아 레이아웃이 깨질 수 있습니다! LazyRow 대신 일반 Row로 구성하거나, LazyColumn 밖에서 높이를 명시적으로 지정해주세요!

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.

isWishlisted 필드가 var로 선언되어 있는데, Compose에서는 데이터 클래스의 필드를 직접 변경하면 Recomposition이 트리거되지 않습니다! val로 선언하고 copy()로 새 객체를 만들어서 상태를 업데이트하는 패턴을 사용해주세요!

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.

4 participants