Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifecycle #14

Merged
merged 28 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ jobs:
# ./gradlew :navigation-core:build --stacktrace
- name: Build
run: |
./gradlew :khonshu-navigation-core:compileKotlinJvm :khonshu-navigation-core:compileDebugKotlinAndroid :khonshu-navigation-core:compileKotlinIosX64 --stacktrace
./gradlew :navigation:compileKotlinJvm :navigation:compileDebugKotlinAndroid :navigation:compileKotlinIosX64 --stacktrace

# - name: Kover Xml Report
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
os: [ macos-12 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
if: ${{ false }}
steps:
- uses: actions/checkout@v3

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", versi
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
compose-rules-detekt = { module = "io.nlopez.compose.rules:detekt", version.ref = "compose-rules-detekt" }

androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version = "androidx-lifecycle" }
Expand Down
2 changes: 2 additions & 0 deletions khonshu-navigation-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ kotlin {
commonMain {
dependencies {
api(compose.runtime)
api(compose.ui)

api(projects.lifecycle)
api(libs.kmp.viewmodel.core)
api(libs.kmp.viewmodel.savedstate)
api(libs.kmp.viewmodel.compose)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import com.hoc081098.solivagant.navigation.internal.InternalNavigationApi

@InternalNavigationApi
@Stable
@Suppress("TopLevelPropertyNaming")
public const val EXTRA_ROUTE: String = "com.hoc081098.solivagant.navigation.ROUTE"
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public interface BackInterceptor {
* the correct events were emitted.
*/
@MainThread
@Suppress("TooManyFunctions")
public open class NavEventNavigator : Navigator, ResultNavigator, BackInterceptor {

private val _navEvents = Channel<NavEvent>(Channel.UNLIMITED)
Expand All @@ -131,8 +132,12 @@ public open class NavEventNavigator : Navigator, ResultNavigator, BackIntercepto
*
* Note: You must call this before [NavigationSetup] is called with this navigator."
*/
protected inline fun <reified T : BaseRoute, reified O : Parcelable> registerForNavigationResult(): NavigationResultRequest<O> {
return registerForNavigationResult(DestinationId(T::class), O::class.qualifiedName!!)
protected inline fun <
reified T : BaseRoute,
reified O : Parcelable,
> registerForNavigationResult(): NavigationResultRequest<O> {
// TODO(js): cannot use qualifiedName
return registerForNavigationResult(DestinationId(T::class), O::class.simpleName!!)
}

@PublishedApi
Expand All @@ -141,7 +146,8 @@ public open class NavEventNavigator : Navigator, ResultNavigator, BackIntercepto
resultType: String,
): NavigationResultRequest<O> {
checkAllowedToAddRequests()
val requestKey = "${id.route.qualifiedName!!}-$resultType"
// TODO(js): cannot use qualifiedName
val requestKey = "${id.route.simpleName!!}-$resultType"
val key = NavigationResultRequest.Key<O>(id, requestKey)
val request = NavigationResultRequest(key)
_navigationResultRequests.add(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import com.hoc081098.kmp.viewmodel.parcelable.Parcelable
import com.hoc081098.kmp.viewmodel.parcelable.Parcelize
import com.hoc081098.solivagant.lifecycle.Lifecycle
import com.hoc081098.solivagant.lifecycle.LifecycleOwner
import com.hoc081098.solivagant.lifecycle.LocalLifecycleOwner
import com.hoc081098.solivagant.lifecycle.repeatOnLifecycle
import com.hoc081098.solivagant.navigation.internal.InternalNavigationApi
import com.hoc081098.solivagant.navigation.internal.LifecycleOwner
import com.hoc081098.solivagant.navigation.internal.NavEvent
import com.hoc081098.solivagant.navigation.internal.NavigationExecutor
import com.hoc081098.solivagant.navigation.internal.VisibleForTesting
import com.hoc081098.solivagant.navigation.internal.currentBackPressedDispatcher
import com.hoc081098.solivagant.navigation.internal.currentLifecycleOwner
import com.hoc081098.solivagant.navigation.internal.repeatOnResumeLifecycle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand All @@ -41,7 +42,7 @@ public fun NavigationSetup(navigator: NavEventNavigator) {
}
}

val lifecycleOwner = currentLifecycleOwner()
val lifecycleOwner = LocalLifecycleOwner.current
LaunchedEffect(lifecycleOwner, executor, navigator) {
navigator.collectAndHandleNavEvents(lifecycleOwner, executor)
}
Expand All @@ -63,7 +64,7 @@ internal suspend fun NavEventNavigator.collectAndHandleNavEvents(
// whichever comes first. Basically, it has some certain delay compared to [Dispatchers.Main.immediate].
// So we must switch to [Dispatchers.Main.immediate] before collecting events.
withContext(Dispatchers.Main.immediate) {
lifecycleOwner.repeatOnResumeLifecycle {
lifecycleOwner.repeatOnLifecycle(state = Lifecycle.State.RESUMED) {
navEvents.collect { event ->
executor.navigateTo(event)
}
Expand Down Expand Up @@ -131,6 +132,7 @@ internal suspend fun <R : Parcelable> NavigationExecutor.collectAndHandleNavigat
@Parcelize
private object InitialValue : Parcelable

@Suppress("CompositionLocalAllowlist")
@InternalNavigationApi
public val LocalNavigationExecutor: ProvidableCompositionLocal<NavigationExecutor> = staticCompositionLocalOf {
throw IllegalStateException("Can't use NavEventNavigationHandler outside of a navigator NavHost")
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading