Inject Clock into CalendarViewModel for testability, add kotlinx-coroutines-test dependency, replace placeholder test with real coverage for ISO week numbers, month day grids, page mapping, and utility functions. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3.9 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
YaYa is a calendar app built with Kotlin Multiplatform (KMP) + Compose Multiplatform, targeting Android and iOS. The shared UI is written entirely in Compose Multiplatform with Material 3.
Build Commands
# Build Android debug APK
./gradlew :androidApp:assembleDebug
# Run shared module tests
./gradlew :shared:testAndroidHostTest
# Run a single test class
./gradlew :shared:testAndroidHostTest --tests "plus.rua.project.ui.CalendarUtilsTest"
# Build iOS app — open iosApp/ in Xcode and run from there
Gradle configuration cache and build cache are enabled by default (gradle.properties).
Architecture
Two-module structure:
:shared— all Compose UI, ViewModel, and business logic (KMP library):androidApp— thin Android shell (MainActivity→App())
iOS entry point is MainViewController.kt in shared/src/iosMain/, consumed by the Xcode project in iosApp/.
Shared source sets:
commonMain— all Compose UI and ViewModel codecommonTest— shared tests (run via:shared:allTestsor:shared:androidHostTest)androidMain— Android-specific platform impl + preview toolingiosMain—ComposeUIViewControllerfactory
Calendar UI composition (all in plus.rua.project.ui):
CalendarMonthView ← top-level screen (MonthHeader + WeekdayHeader + pager + BottomCard)
├── MonthHeader ← year/month label + ISO week number
├── WeekdayHeader ← fixed "一二三四五六日" row
├── CalendarPager ← HorizontalPager with Int.MAX_VALUE pages (month view)
│ └── CalendarMonthPage ← 6×7 grid of DayCell with collapse animation
│ └── DayCell ← single day circle with selection/today states
├── WeekPager ← HorizontalPager for single-week view (collapsed state)
│ └── DayCell
└── BottomCard ← drag handle card, drives collapse/expand gestures
Collapse/expand animation: CalendarMonthView supports month↔week transition via CalendarViewModel.collapseProgress (0f=month, 1f=week). BottomCard captures vertical drag gestures and calls viewModel.onDrag()/onExpandDrag(). When progress crosses 50% on release, a spring animation snaps to the nearest state. CalendarMonthPage compresses non-selected weeks toward zero height during collapse. When fully collapsed, WeekPager replaces CalendarPager for efficient single-week paging.
Pager page mapping: Both CalendarPager and WeekPager use Int.MAX_VALUE pages centered at Int.MAX_VALUE / 2. Page-to-date conversion is arithmetic — no index-based list. CalendarPager maps pages to yearMonth; WeekPager maps pages to week-Monday dates. Both skip the initial snapshotFlow emission (.drop(1)) to preserve the "today" selection on first render.
CalendarViewModel holds selectedDate and isCollapsed state, computes month day grids (6×7=42 cells) and ISO week numbers. Week starts on Monday (ISO 8601).
Key Dependencies
- Kotlin 2.3.21, Compose Multiplatform 1.10.3, Material 3 1.10.0-alpha05
kotlinx-datetime0.8.0 for all date logic (no java.util.Calendar)- AGP 9.2.1, compileSdk/targetSdk 36, minSdk 24
- JVM target: 17
Conventions
- Package:
plus.rua.project(shared),plus.rua.project.ui(UI composables) - Version catalog at
gradle/libs.versions.toml— all dependency versions declared there @Suppress("DEPRECATION")used formonthNumberaccess onkotlinx.datetime.LocalDate— must include inline comment explaining reason- UI text is in Chinese (weekday labels, month header format "2026年5月")
- Public
@Composablefunctions require KDoc perCOMMENTS.md Modifierparameter always last in composable signatures- Callback parameters use
onprefix (onDateClick,onMonthChanged)