diff --git a/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/IosNodeHost.kt b/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/IosNodeHost.kt index f35d33cf3..6a03191ef 100644 --- a/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/IosNodeHost.kt +++ b/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/IosNodeHost.kt @@ -25,7 +25,7 @@ import platform.UIKit.UIScreen fun IosNodeHost( onBackPressedEvents: Flow, modifier: Modifier = Modifier, - integrationPoint: IntegrationPoint = remember { MainIntegrationPoint() }, + integrationPoint: IntegrationPoint, customisations: NodeCustomisationDirectory = remember { NodeCustomisationDirectoryImpl() }, factory: NodeFactory, ) { diff --git a/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/MainIntegrationPoint.kt b/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/MainIntegrationPoint.kt index 77ae8facf..7488b14aa 100644 --- a/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/MainIntegrationPoint.kt +++ b/appyx-navigation/common/src/iosMain/kotlin/com/bumble/appyx/navigation/integration/MainIntegrationPoint.kt @@ -1,14 +1,24 @@ package com.bumble.appyx.navigation.integration import com.bumble.appyx.navigation.integrationpoint.IntegrationPoint +import platform.UIKit.UIViewController +import platform.UIKit.navigationController + +class MainIntegrationPoint: IntegrationPoint() { + private lateinit var viewController: UIViewController -class MainIntegrationPoint : IntegrationPoint() { override val isChangingConfigurations: Boolean get() = false - @Suppress("EmptyFunctionBlock") - override fun onRootFinished() {} + fun setViewController(viewController: UIViewController) { + this.viewController = viewController + } + + override fun onRootFinished() { + viewController.dismissModalViewControllerAnimated(false) + } - @Suppress("EmptyFunctionBlock") - override fun handleUpNavigation() {} + override fun handleUpNavigation() { + viewController.navigationController?.popViewControllerAnimated(false) + } } diff --git a/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt b/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt index 712a9fa4d..e590099d5 100644 --- a/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt +++ b/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt @@ -8,6 +8,7 @@ import androidx.compose.material.Scaffold import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -15,6 +16,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.ComposeUIViewController import androidx.compose.ui.zIndex import com.bumble.appyx.navigation.integration.IosNodeHost +import com.bumble.appyx.navigation.integration.MainIntegrationPoint import com.bumble.appyx.navigation.node.container.ContainerNode import com.bumble.appyx.navigation.ui.AppyxSampleAppTheme import kotlinx.coroutines.CoroutineScope @@ -24,8 +26,11 @@ import kotlinx.coroutines.launch val backEvents: Channel = Channel() +private val integrationPoint = MainIntegrationPoint() + @Suppress("FunctionNaming") fun MainViewController() = ComposeUIViewController { + AppyxSampleAppTheme { val coroutineScope = rememberCoroutineScope() Scaffold( @@ -39,7 +44,8 @@ fun MainViewController() = ComposeUIViewController { Box(modifier = Modifier.fillMaxSize()) { IosNodeHost( modifier = Modifier, - onBackPressedEvents = backEvents.receiveAsFlow() + onBackPressedEvents = backEvents.receiveAsFlow(), + integrationPoint = remember { integrationPoint } ) { buildContext -> ContainerNode( buildContext = buildContext, @@ -49,6 +55,8 @@ fun MainViewController() = ComposeUIViewController { } } } +}.also { uiViewController -> + integrationPoint.setViewController(uiViewController) } @Composable