[Refactor/#1] PickerState to index-based generic state with reliable onValueChange#2
Merged
DongChyeon merged 6 commits intomainfrom Jul 2, 2025
Merged
Conversation
…avoid skipped updates
There was a problem hiding this comment.
Pull Request Overview
Refactors the picker components to use an index-based, generic state model and fixes skipped value-change callbacks by calculating adjusted indices before deduplication.
- Converts
PickerStateto a generic, index-driven design withStateFlow<Int> - Updates
PickerItemto computeadjustedIndexbeforedistinctUntilChangedand safely formats items - Adapts
TimePickerto supply item lists as typedList<T>and useitemFormatterfor padding
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| timepicker/src/main/java/com/dongchyeon/timepicker/ui/PickerItem.kt | Made PickerItem generic, refactored scroll observer and onValueChange logic, added null-safe item formatting |
| timepicker/src/main/java/com/dongchyeon/timepicker/model/PickerState.kt | Changed PickerState to generic type T, replaced mutable item with index-based StateFlow |
| timepicker/src/main/java/com/dongchyeon/timepicker/TimePicker.kt | Switched hour/minute lists to typed lists, updated rememberPickerState calls, added itemFormatter |
Comments suppressed due to low confidence (1)
timepicker/src/main/java/com/dongchyeon/timepicker/model/PickerState.kt:10
- With the new generic and index-based implementation, consider adding unit tests for
PickerState<T>andgetItemForIndexto verify correct index-to-item mapping, boundary handling, and onValueChange behavior.
class PickerState<T>(
timepicker/src/main/java/com/dongchyeon/timepicker/ui/PickerItem.kt
Outdated
Show resolved
Hide resolved
…nfinite PickerItem
…initial scroll position
13 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🎯 Related Issue
📝 Description
What does this PR do?
🔄 Comparison
PickerStatestored mutableselectedItemdirectlyselectedIndex: StateFlow<Int>with derivedselectedItemgetter, enforcing unidirectional data flowStringitemsdistinctUntilChangedapplied tocenterIndex, mapping afterwardsadjustedIndexbeforedistinctUntilChanged, preventing skipped updatesgetItemForIndexusedtoString()directly, risking"null"display""safely when item is null✅ Changes
PickerStateto index-based unidirectional statePickerStategeneric for type safetyadjustedIndexbeforedistinctUntilChangedinPickerItemitemis null ingetItemForIndex🔍 Screenshots / Test Results (if applicable)
N/A
👤 Reviewer Checklist
N/A