-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for injecting dependencies into Composables #224
Conversation
|
||
private fun TopLevelFunctionReference.parameterTypes(): List<ComposableParameter> { | ||
return parameters | ||
.filter { it.name != null && it.name != "state" && it.name != "sendAction" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state
and sendAction
are specific to our codebase. Not sure how this could be prevented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, for a first step. A better long term solution would be to see how we can get the type parameters of the state machine class and then match based on those. E.g. FooStateMachine which we have extends StateMachine<FooState, FooAction>
so we can extract those 2 to use them here.
|
||
private fun TopLevelFunctionReference.parameterTypes(): List<ComposableParameter> { | ||
return parameters | ||
.filter { it.name != null && it.name != "state" && it.name != "sendAction" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, for a first step. A better long term solution would be to see how we can get the type parameters of the state machine class and then match based on those. E.g. FooStateMachine which we have extends StateMachine<FooState, FooAction>
so we can extract those 2 to use them here.
This adds new functionality to inject classes into Composables, which have the
ComposeFragment
orComposeScreen
annotation applied.Before this change users could provide UI specific dependencies via Composes'
LocalCompositionProvider
. This got removed in favour of injecting directly into the Composable.Example:
We want to use an instance of
MyDependency
in the UI, which is provided through Dagger.