Hardcoding scope parameter for a "typealias" of metro annotations #1123
-
|
Hi, entryProvider {
entry<Home> {
HomeScreen { backStack += Detail(it) }
}
entry<Detail> {
DetailScreen(it.id)
}
}This won't scale to a big team as you need to add the entry manually - so obvious choice is then multibinding. This is my prototype @Inject
@ContributesIntoSet(AppScope::class) <-----------------
class HomeScreenEntry : ScreenEntry {
override fun EntryProviderBuilder<NavKey>.registerEntry(backStack: NavBackStack<NavKey>) {
entry<Home> {
HomeScreen(
onGoToProduct = { backStack += Detail(it) }
)
}
}
}and note I'll have multiple semantic scopes ( I was thinking of having something like typealias annotation ContributesScreenEntry = dev.zacsweers.metro.ContributesIntoSet(AppScope::class)as means of "hardcoding" the scope so it's no longer an option which obviously doesn' work as it's a made up syntax, so I tried a bit harder @Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@dev.zacsweers.metro.ContributesIntoSet(AppScope::class)
annotation class ContributesScreenEntrywhich then fails to compile with `@ContributesIntoSet` is only applicable to constructor-injected classes, assisted factories, or objects. Ensure sk.ursus.metrodemo.home.ContributesScreenEntry is injectable or a bindable object.Is this a deadend? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
sidebar: please use syntax highlighting when writing larger code snippets for readability |
Beta Was this translation helpful? Give feedback.
-
|
Yeah the syntax you are writing is a dead-end. As you mentioned, it's a made-up syntax that Metro doesn't understand. You likely want to write some sort of code gen of your own that generates what metro needs, similar to how Circuit's code gen generates contributing factories for its presenters/uis. |
Beta Was this translation helpful? Give feedback.
Yeah the syntax you are writing is a dead-end. As you mentioned, it's a made-up syntax that Metro doesn't understand. You likely want to write some sort of code gen of your own that generates what metro needs, similar to how Circuit's code gen generates contributing factories for its presenters/uis.