macosMain.dev.programadorthi.routing.darwin.UIKitUINavigationController.ios.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of uikit Show documentation
Show all versions of uikit Show documentation
An extensible and multiplatform routing system powered by Ktor
The newest version!
package dev.programadorthi.routing.darwin
import platform.AppKit.NSViewController
import platform.Foundation.NSCoder
// All credits to: https://stackoverflow.com/a/50191172
public actual class UIKitUINavigationController actual constructor(coder: NSCoder) : NSViewController(coder) {
private val controllers = mutableListOf()
private val topController: NSViewController?
get() = controllers.lastOrNull()
public actual fun viewControllers(): List = controllers.toList()
public actual fun popViewControllerAnimated(animated: Boolean): UIKitUIViewController? = controllers.removeLastOrNull()
public actual fun popToViewController(
viewController: UIKitUIViewController,
animated: Boolean,
): List? {
controllers.removeAll { it == viewController }
return controllers
}
public actual fun pushViewController(
viewController: UIKitUIViewController,
animated: Boolean,
) {
controllers += viewController
}
public actual fun setViewControllers(
viewControllers: List,
animated: Boolean,
) {
controllers.clear()
controllers += viewControllers
}
}