You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users are asking questions about how one can extend ComponentContext with additional app-wide things. I came up with a solution. Would be nice do add this as a suggestion to the docs. If somebody thinks this can be improved, please let me know.
interfaceAppComponentContext : ComponentContext {
// Custom things here
}
classDefaultAppComponentContext(
componentContext:ComponentContext,
// Additional dependencies here
) : AppComponentContext, ComponentContext by componentContext {
// Custom things implementation here
}
fun <C:Parcelable, T:Any> AppComponentContext.appRouter(
initialConfiguration: () ->C,
initialBackStack: () ->List<C> = ::emptyList,
configurationClass:KClass<outC>,
key:String = "DefaultRouter",
handleBackButton:Boolean = false,
componentFactory: (configuration: C, AppComponentContext) ->T
): Router<C, T> =
router(
initialConfiguration = initialConfiguration,
initialBackStack = initialBackStack,
configurationClass = configurationClass,
key = key,
handleBackButton = handleBackButton
) { configuration, componentContext ->
componentFactory(
configuration,
DefaultAppComponentContext(
componentContext = componentContext
)
)
}
classMyComponent(componentContext:AppComponentContext): AppComponentContext by componentContext {
// Use AppComponentContext here
}
The text was updated successfully, but these errors were encountered:
I think I understand your solution to creating a custom component context and put up a PR to add that. I'm not sure I fully understand the need for having a custom component context, but let me know if any changes are needed to make the new documentation more clear 😄
I also don't fully understand why this might be used. But it was asked multiple times, hence the solution. Probably some global things that are needed in (almost) every component. So you don't need to explicitly pass it through all components.
Users are asking questions about how one can extend
ComponentContext
with additional app-wide things. I came up with a solution. Would be nice do add this as a suggestion to the docs. If somebody thinks this can be improved, please let me know.The text was updated successfully, but these errors were encountered: