-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dba5686
commit b18689a
Showing
8 changed files
with
211 additions
and
171 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
39 changes: 39 additions & 0 deletions
39
circuit-foundation/src/commonMain/kotlin/com/slack/circuit/foundation/PauseablePresenter.kt
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,39 @@ | ||
// Copyright (C) 2024 Slack Technologies, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package com.slack.circuit.foundation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import com.slack.circuit.runtime.CircuitUiState | ||
import com.slack.circuit.runtime.presenter.Presenter | ||
|
||
public abstract class PauseablePresenter<UiState : CircuitUiState>() : Presenter<UiState> { | ||
|
||
private var lastState by mutableStateOf<UiState?>(null) | ||
|
||
@Composable | ||
override fun present(): UiState { | ||
val isPaused = LocalLifecycle.current.isPaused | ||
|
||
if (!isPaused || lastState == null) { | ||
lastState = _present() | ||
} | ||
|
||
println("PauseablePresenter. isPaused: $isPaused. state: $lastState") | ||
|
||
return lastState!! | ||
} | ||
|
||
@Composable protected abstract fun _present(): UiState | ||
} | ||
|
||
public fun <UiState : CircuitUiState> Presenter<UiState>.toPauseablePresenter(): | ||
PauseablePresenter<UiState> { | ||
if (this is PauseablePresenter<UiState>) return this | ||
// Else we wrap the presenter | ||
return object : PauseablePresenter<UiState>() { | ||
@Composable override fun _present(): UiState = this@toPauseablePresenter.present() | ||
} | ||
} |
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
129 changes: 0 additions & 129 deletions
129
...nitTest/kotlin/com/slack/circuitx/gesturenavigation/GestureNavigationSaveableStateTest.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.