Skip to content

Commit

Permalink
Merge pull request #68 from AlexGladkov/bugfix/LaunchFlag-with-modal
Browse files Browse the repository at this point in the history
flag SingleNewTask doesn't close modals
  • Loading branch information
AlexGladkov authored Dec 29, 2022
2 parents 17cceea + 7e58c2d commit 109422c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowCircleUp
import androidx.compose.material.icons.filled.ArrowDownward
import androidx.compose.material.icons.filled.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand All @@ -16,6 +15,10 @@ import ru.alexgladkov.odyssey.compose.extensions.present
import ru.alexgladkov.odyssey.compose.local.LocalRootController
import ru.alexgladkov.odyssey.compose.navigation.modal_navigation.ModalSheetConfiguration
import kotlin.random.Random
import ru.alexgladkov.common.compose.NavigationTree
import ru.alexgladkov.odyssey.core.LaunchFlag
import ru.alexgladkov.odyssey.compose.extensions.present
import ru.alexgladkov.odyssey.compose.extensions.push


@Composable
Expand Down Expand Up @@ -63,5 +66,21 @@ fun ModalSheetScreen(onCloseClick: () -> Unit) {
}
}
}

ActionCell("Start New Chain", icon = Icons.Filled.OpenInNew) {
rootController.present(
screen = NavigationTree.Present.name,
launchFlag = LaunchFlag.SingleNewTask
)
}

ActionCell(text = "Clear Previous Screen", icon = Icons.Filled.Clear) {
rootController.push(
screen = NavigationTree.Push.name,
launchFlag = LaunchFlag.ClearPrevious,
params = 0
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,18 @@ open class RootController(rootControllerType: RootControllerType): CoreRootContr

private fun handleLaunchFlag(screenKey: String, launchFlag: LaunchFlag?) {
when (launchFlag) {
LaunchFlag.SingleNewTask -> _backstack.clear()
LaunchFlag.SingleInstance -> _backstack.removeAll { it.realKey == screenKey }
LaunchFlag.ClearPrevious -> _backstack.removeLastOrNull()
LaunchFlag.SingleNewTask -> {
_modalController?.clearBackStack()
_backstack.clear()
}
LaunchFlag.SingleInstance -> {
_modalController?.clearBackStack()
_backstack.removeAll { it.realKey == screenKey }
}
LaunchFlag.ClearPrevious -> {
_modalController?.clearBackStack()
_backstack.removeLastOrNull()
}
null -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ open class ModalController {

fun clearBackStack() {
_backStack.clear()
redrawStack()
}

fun isEmpty() = _backStack.none { it.dialogState !is ModalDialogState.Close }
Expand Down

0 comments on commit 109422c

Please sign in to comment.