-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve Image Viewer toolbar auto-hide (#521)
Cancel the auto-hide behavior in case the toolbar menu items are interacted with. Improves #505, #507 --------- Co-authored-by: Nik Clayton <[email protected]>
- Loading branch information
1 parent
d9fc664
commit 5be93ac
Showing
5 changed files
with
98 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package app.pachli | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.channels.BufferOverflow | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.updateAndGet | ||
|
||
class ViewMediaViewModel : ViewModel() { | ||
private val _toolbarVisibility = MutableStateFlow(true) | ||
|
||
/** Emits Toolbar visibility changes */ | ||
val toolbarVisibility: StateFlow<Boolean> get() = _toolbarVisibility.asStateFlow() | ||
|
||
private val _toolbarMenuInteraction = MutableSharedFlow<Unit>( | ||
extraBufferCapacity = 1, | ||
onBufferOverflow = BufferOverflow.DROP_OLDEST, | ||
) | ||
|
||
/** | ||
* Emits whenever a Toolbar menu interaction happens (ex: open overflow menu, item action) | ||
* Fragments use this to determine whether the toolbar can be hidden after a delay. | ||
*/ | ||
val toolbarMenuInteraction: SharedFlow<Unit> get() = _toolbarMenuInteraction.asSharedFlow() | ||
|
||
/** Convenience getter for the current Toolbar visibility */ | ||
val isToolbarVisible: Boolean | ||
get() = toolbarVisibility.value | ||
|
||
/** | ||
* Toggle the current state of the toolbar's visibility. | ||
* | ||
* @return The new visibility | ||
*/ | ||
fun toggleToolbarVisibility() = _toolbarVisibility.updateAndGet { !it } | ||
|
||
fun onToolbarMenuInteraction() { | ||
_toolbarMenuInteraction.tryEmit(Unit) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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