fix crash when navigation graph is null (#706)

This commit is contained in:
IndusAryan 2023-10-23 21:41:05 +05:30 committed by GitHub
parent c9bffef7cb
commit eb58cb1184
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View file

@ -51,7 +51,7 @@ android {
}
// https://developer.android.com/about/versions/14/behavior-changes-14#safer-dynamic-code-loading
compileSdk = 33 // android 14 is fucked
compileSdk = 34 // android 14 is fucked
buildToolsVersion = "34.0.0"
defaultConfig {
@ -157,7 +157,7 @@ dependencies {
implementation("androidx.test.ext:junit-ktx:1.1.5")
testImplementation("org.json:json:20230618")
implementation("androidx.core:core-ktx:1.10.1") // need 34 for higher
implementation("androidx.core:core-ktx:1.12.0") // need 34 for higher
implementation("androidx.appcompat:appcompat:1.6.1") // need target 32 for 1.5.0
// dont change this to 1.6.0 it looks ugly af
@ -165,10 +165,10 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
// need 34 for higher
implementation("androidx.navigation:navigation-fragment-ktx:2.6.0")
implementation("androidx.navigation:navigation-ui-ktx:2.6.0")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.4")
implementation("androidx.navigation:navigation-ui-ktx:2.7.4")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")

View file

@ -178,9 +178,10 @@ object UIHelper {
fun Activity?.navigate(@IdRes navigation: Int, arguments: Bundle? = null) {
try {
if (this is FragmentActivity) {
(supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment?)?.navController?.navigate(
navigation, arguments
)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment?
navHostFragment?.navController?.let {
it.navigate(navigation, arguments)
}
}
} catch (t: Throwable) {
logError(t)