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
Fixes #13331: Make toggle button update lifecycle-aware #13339
base: main
Are you sure you want to change the base?
Fixes #13331: Make toggle button update lifecycle-aware #13339
Conversation
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to inactivity. |
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class ToggleUpdateViewModel : ViewModel() { |
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.
Can you add some documentation to this class describing what it's for? It's fairly unclear just looking. And I think perhaps ToggleUpdate* isn't the best name. Feels like it should have a better descriptor there (though admittedly, I realize this was probably just pulled from the original method name)
|
||
lifecycleScope.launch { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
toggleUpdateViewModel.state.collect { |
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.
My knowledge of the Flow apis is quite limited, my understanding is that this will be subscribed between onStart / onStop and the subscription is managed automatically?
val state = _state.asSharedFlow() | ||
|
||
fun update() = viewModelScope.launch { | ||
_state.emit(Unit) |
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's not really any state here... is this just a pulse? How is this different from just calling toggle update fn from the appropriate lifecycle method in the fragment? (I've yet to have coffee this morning so appologies if I missed something obvious.)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Contributor checklist
Fixes #1234
syntaxIssue
Fixes: #13331
Description
Update UI state following the Android lifecycle.
Videos
✅
Redmi.Note.10.Pro.-.OK.mov
Tested
Device info