Skip to content

Commit

Permalink
Passing viewController to iOS integration point and popping/dismissing
Browse files Browse the repository at this point in the history
  • Loading branch information
aashay-gaikwad committed Sep 27, 2023
1 parent 60bda2d commit 7ee043b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import platform.UIKit.UIScreen
fun <N : Node> IosNodeHost(
onBackPressedEvents: Flow<Unit>,
modifier: Modifier = Modifier,
integrationPoint: IntegrationPoint = remember { MainIntegrationPoint() },
integrationPoint: IntegrationPoint,
customisations: NodeCustomisationDirectory = remember { NodeCustomisationDirectoryImpl() },
factory: NodeFactory<N>,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
10 changes: 9 additions & 1 deletion demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ 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
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
Expand All @@ -24,8 +26,11 @@ import kotlinx.coroutines.launch

val backEvents: Channel<Unit> = Channel()

private val integrationPoint = MainIntegrationPoint()

@Suppress("FunctionNaming")
fun MainViewController() = ComposeUIViewController {

AppyxSampleAppTheme {
val coroutineScope = rememberCoroutineScope()
Scaffold(
Expand All @@ -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,
Expand All @@ -49,6 +55,8 @@ fun MainViewController() = ComposeUIViewController {
}
}
}
}.also { uiViewController ->
integrationPoint.setViewController(uiViewController)
}

@Composable
Expand Down

0 comments on commit 7ee043b

Please sign in to comment.