Skip to content

Commit

Permalink
Throw error if local inspection mode is true and user attempts to acc…
Browse files Browse the repository at this point in the history
…ess navigationContext
  • Loading branch information
isaac-udy committed Nov 22, 2023
1 parent 858c7d3 commit 2e5efc3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions enro-core/src/main/java/dev/enro/core/NavigationContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.LocalView
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
Expand All @@ -24,7 +24,6 @@ import dev.enro.core.compose.destination.activity
import dev.enro.core.container.NavigationContainer
import dev.enro.core.container.NavigationContainerManager
import dev.enro.core.controller.NavigationController
import dev.enro.core.controller.navigationController
import dev.enro.core.internal.handle.getNavigationHandleViewModel

public class NavigationContext<ContextType : Any> internal constructor(
Expand Down Expand Up @@ -150,6 +149,8 @@ internal val <T : ComposableDestination> T.navigationContext: NavigationContext<
public val navigationContext: NavigationContext<*>
@Composable
get() {
if (LocalInspectionMode.current) error("Not able to access navigationContext when LocalInspectionMode.current is 'true'")

val viewModelStoreOwner = requireNotNull(LocalViewModelStoreOwner.current) {
"Failed to get navigationContext in Composable: LocalViewModelStoreOwner was null"
}
Expand Down

0 comments on commit 2e5efc3

Please sign in to comment.