Skip to content

Commit

Permalink
remove compose navigation
Browse files Browse the repository at this point in the history
Removed compose navigation dependency and related code. Replaced navigation with simple state change.
  • Loading branch information
SEAbdulbasit committed Jul 22, 2024
1 parent 0bdcccd commit cd97d31
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
3 changes: 2 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ kotlin {
implementation("io.coil-kt.coil3:coil-network-ktor:$coilVersion")

//compose navigation
implementation("org.jetbrains.androidx.navigation:navigation-compose:2.7.0-alpha07")
// implementation("org.jetbrains.androidx.navigation:navigation-compose:2.7.0-alpha07")

}
}
Expand Down Expand Up @@ -112,6 +112,7 @@ kotlin {
jsMain {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-io:0.1.16")
}
}
}
Expand Down
59 changes: 40 additions & 19 deletions shared/src/commonMain/kotlin/com/example/travelapp_kmp/MainView.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.example.travelapp_kmp

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.travelapp_kmp.details.DetailScreen
import com.example.travelapp_kmp.details.DetailScreenWeb
import com.example.travelapp_kmp.listing.ListScreenViewModel
Expand All @@ -18,35 +14,60 @@ import com.example.travelapp_kmp.listing.TouristPlace
@Composable
internal fun CommonView(isLargeScreen: Boolean = false) {
val viewMode = remember { ListScreenViewModel() }
val navController = rememberNavController()
// val navController = rememberNavController()
var selectedTouristPlace: TouristPlace? = null
val currentScreen = remember { mutableStateOf(AppScreen.List) }

MaterialTheme {

NavHost(
navController = navController,
startDestination = AppScreen.List.name,
modifier = Modifier.fillMaxSize()
) {
composable(AppScreen.List.name) {
when (currentScreen.value) {
AppScreen.List -> {
MainScreen(navigateToDetails = {
selectedTouristPlace = it
navController.navigate(AppScreen.Details.name)
currentScreen.value = AppScreen.Details
// navController.navigate(AppScreen.Details.name)
}, viewMode = viewMode)
}
composable(AppScreen.Details.name) {

AppScreen.Details -> {
if (isLargeScreen)
DetailScreenWeb(touristPlace = selectedTouristPlace!!,
navigateBack = { navController.popBackStack() })
navigateBack = {
currentScreen.value = AppScreen.List
// navController.popBackStack()
})
else
DetailScreen(touristPlace = selectedTouristPlace!!,
navigateBack = { navController.popBackStack() })
navigateBack = {
currentScreen.value = AppScreen.List
// navController.popBackStack()
})
}
}

// NavHost(
// navController = navController,
// startDestination = AppScreen.List.name,
// modifier = Modifier.fillMaxSize()
// ) {
// composable(AppScreen.List.name) {
// MainScreen(navigateToDetails = {
// selectedTouristPlace = it
// navController.navigate(AppScreen.Details.name)
// }, viewMode = viewMode)
// }
// composable(AppScreen.Details.name) {
// if (isLargeScreen)
// DetailScreenWeb(touristPlace = selectedTouristPlace!!,
// navigateBack = { navController.popBackStack() })
// else
// DetailScreen(touristPlace = selectedTouristPlace!!,
// navigateBack = { navController.popBackStack() })
// }
// }
}
}

enum class AppScreen(title: String) {
List(title = "ListScreen"), Details(title = "DetailsScreen"),
enum class AppScreen {
List, Details
}

9 changes: 4 additions & 5 deletions webApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
Expand Down Expand Up @@ -36,6 +37,8 @@ kotlin {
}
binaries.executable()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "webApp"
browser {
Expand Down Expand Up @@ -77,8 +80,4 @@ kotlin {
dependsOn(jsWasmMain)
}
}
}

compose.experimental {
web.application {}
}
}

0 comments on commit cd97d31

Please sign in to comment.