raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.14k stars 129 forks source link

No NavGraphs in V2 #625

Closed whitescent closed 2 months ago

whitescent commented 2 months ago

My project is Single Module, and this is my NavGraphs looks like in V1

image

There are also some destinations that don't belong to any NavGraph of these(LoginNavGraph, AppNavGraph) two

but my NavGraphs in V2 is:

image

If I'm not mistaken, I have changed all the code in v1 from


@RootNavGraph(start = true)
@NavGraph
annotation class LoginNavGraph(
  val start: Boolean = false
)

@RootNavGraph
@NavGraph
annotation class AppNavGraph(
  val start: Boolean = false
)

@AppNavGraph
@Destination
@Composable()

to

@NavGraph<RootGraph>(start = true)
annotation class LoginNavGraph

@NavGraph<RootGraph>
annotation class AppNavGraph

@Destination<AppNavGraph>
@Composable

but the generated NavGraphs still seem to have this error 🤔.

whitescent commented 2 months ago

Just created a new project to test it, but still encountering this issue

image
raamcosta commented 2 months ago

Is this sample on GitHub? Can I get the link?

whitescent commented 2 months ago

Is this sample on GitHub? Can I get the link?

ok i will create

whitescent commented 2 months ago

this is a new project to test v2 https://github.com/whitescent/compose-destination-issue @raamcosta

https://github.com/whitescent/Mastify This is a project I am planning to migrate to v2

raamcosta commented 2 months ago

Can you try adding , start = true) to one of your graphs? Login for example?

raamcosta commented 2 months ago

Looking at the sample from a glance, this seems missing, but obviously there should be a helpful error message rather than just not generating anything 😜

so if this is indeed the issue, I’ll need to improve it 👍

whitescent commented 2 months ago

Can you try adding , start = true) to one of your graphs? Login for example?

image

yes, still missing

raamcosta commented 2 months ago

Ok let me run it locally

raamcosta commented 2 months ago

Found it 🐞

For now, please add this:

@NavHostGraph
annotation class MainGraph

And use MainGraph instead of RootGraph. Also on Activity, NavGraphs.main.

Later when I release a new version, you can go back to using RootGraph 😄

Thank you for reporting 🙏

whitescent commented 2 months ago

So I can start by writing code like this:

@NavHostGraph
annotation class MainNavGraph

@NavGraph<MainNavGraph>
annotation class LoginNavGraph

@NavGraph<MainNavGraph>
annotation class AppNavGraph

@Destination<AppNavGraph>
@Composable

right?

Later when I release a new version, you can go back to using RootGraph 😄

Thank you for all your hard work 😄👍

raamcosta commented 2 months ago

Don't forget that each nav graph needs a start. So probably missing start = true on some of those :)

whitescent commented 2 months ago

@raamcosta i just test the SharedElement Transition in last v2 version(2.1.0-beta02), But AnimatedVisibilityScope it is not automatically provided.

image

code:

SharedTransitionLayout {
  DestinationsNavHost(
    navGraph = NavGraphs.main,
    dependenciesContainerBuilder = {
      dependency(this@SharedTransitionLayout)
    }
  )
}

@OptIn(ExperimentalSharedTransitionApi::class)
@Destination<HomeNavGraph>(start = true)
@Composable
fun SharedTransitionScope.Home(
  navigator: DestinationsNavigator,
  animatedVisibilityScope: AnimatedVisibilityScope
) {
  Column {
    Text(
      text = "home Screen",
      modifier = Modifier.sharedElement(
        state = rememberSharedContentState(key = "text"),
        animatedVisibilityScope = animatedVisibilityScope
      )
    )
    Button(
      onClick = { /*TODO*/ }
    ) {
    }
  }
}

@OptIn(ExperimentalSharedTransitionApi::class)
@Destination<LoginNavGraph>(start = true)
@Composable
fun SharedTransitionScope.Login(
  navigator: DestinationsNavigator,
  animatedVisibilityScope: AnimatedVisibilityScope
) {
  Box(
    modifier = Modifier.fillMaxSize(),
    contentAlignment = Alignment.Center
  ) {
    Column {
      Text(
        text = "Login Screen",
        modifier = Modifier.sharedElement(
          state = rememberSharedContentState(key = "text"),
          animatedVisibilityScope = animatedVisibilityScope
        )
      )
      Button(
        onClick = {}
      ) {
      }
    }
  }
}

could you please check this issue? 🤓

raamcosta commented 2 months ago

ahh, I missed the import. The example I had was already importing it for some other reason 😛

Will fix this, thank you!

raamcosta commented 2 months ago

Try 2.1.0-beta03 coming up within 30min or so.