In Kotlin Multi Platform und Jetpack komponieren, warum und wie wird Navhost importiert, das aus derselben Datei mit 9 VAndroid

Forum für diejenigen, die für Android programmieren
Guest
 In Kotlin Multi Platform und Jetpack komponieren, warum und wie wird Navhost importiert, das aus derselben Datei mit 9 V

Post by Guest »

Hintergrund < /h2>
Hi, < /p>
Ich bin neu bei Kotlin, Kotlin Multi -Plattform und Jetpack komponieren, aber kein Noob für das Programmieren. Ich habe eine Verwendung für ein KMP -Projekt gefunden und habe daran gearbeitet, einen Naviggraph und einen NavhostController zu erstellen, damit ich verschiedene Seiten erstellen kann, basierend auf der Übertragung des Stands. Es funktioniert gut, keine Fehler: < /p>

Code: Select all

import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost

@Composable
fun MyFun(){
// ...
NavHost(/* navController, startDestination, modifier */)
// ...
}
< /code>
NavHost
stammt offensichtlich aus dem Import, und es ist in Navhost.kt ... Als ich es importiert habe, bemerkte ich, dass es in derselben Datei viele Versionen davon gab. 9 In der Tat und jeder nimmt unterschiedliche Argumente auf, aber haben denselben Namen, und aus irgendeinem Grund funktioniert jede Version immer noch. < /P>
Hier sind 3 davon. Beachten Sie, wie 2 nicht eine @deprecated Annotation haben:

Code: Select all

@Deprecated(
message = "Deprecated in favor of NavHost that supports AnimatedContent",
level = DeprecationLevel.HIDDEN
)

@Composable
public fun NavHost(
navController: NavHostController,
startDestination: String,
modifier: Modifier = Modifier,
route: String? = null,
builder: NavGraphBuilder.() -> Unit
)

@Composable
public fun NavHost(
navController: NavHostController,
startDestination: String,
modifier: Modifier = Modifier,
contentAlignment: Alignment = Alignment.TopStart,
route: String? = null,
enterTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> EnterTransition) =
DefaultNavTransitions.enterTransition,
exitTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> ExitTransition) =
DefaultNavTransitions.exitTransition,
popEnterTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> EnterTransition) =
enterTransition,
popExitTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> ExitTransition) =
exitTransition,
sizeTransform:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> SizeTransform?)? =
DefaultNavTransitions.sizeTransform,
builder: NavGraphBuilder.() -> Unit
)

@Composable
public fun NavHost(
navController: NavHostController,
startDestination: KClass,
modifier: Modifier = Modifier,
contentAlignment: Alignment = Alignment.TopStart,
route: KClass? = null,
typeMap: Map = emptyMap(),
enterTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> EnterTransition) =
DefaultNavTransitions.enterTransition,
exitTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> ExitTransition) =
DefaultNavTransitions.exitTransition,
popEnterTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> EnterTransition) =
enterTransition,
popExitTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> ExitTransition) =
exitTransition,
sizeTransform:
(@JvmSuppressWildcards
AnimatedContentTransitionScope.() -> SizeTransform?)? =
DefaultNavTransitions.sizeTransform,
builder: NavGraphBuilder.() -> Unit
)
< /code>
[b]But if I were do this (keep in mind that public
ist die Standard -Sichtbarkeit) : [/b]

Code: Select all

fun ABC(){
println("ABC")
}

fun ABC(){
println("DEF")
}

fun ABC(){
println("GHI")
}
// +6 more

fun main() {
ABC()
}
< /code>
[b]Then I get these errors:[/b]
Conflicting overloads: fun ABC(): Unit fun ABC(): Unit
Conflicting overloads: fun ABC(): Unit fun ABC(): Unit
Conflicting overloads: fun ABC(): Unit fun ABC(): Unit
Overload resolution ambiguity between candidates: fun ABC(): Unit fun ABC(): Unit fun ABC(): Unit
< /code>
I've only ever done Python and JavaScript, and in those, anytime you rewrite the same variable name, function declaration, etc. below the original for any type of object: it rewrites it. So you don't do that in the same code block / file, unless you want that to happen.
QUESTIONS

[*]Is the NavHost.kt
aus Android -Datei umschreiben Navhost ?
[*] Wie/warum funktioniert das ??? Auch hier gibt ABC () Fehler an, es sei denn, ich kommentiere die letzteren.
Also, was passiert also? Wie funktioniert Navhost ohne Fehler zu werfen? Warum bekomme ich Fehler mit ABC () , aber Navhost ist nicht?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post