-
Hello! Now I'm creating the app using Decompose and I'd like to split the app into several feature-modules. I looked the "dynamic-features" example in this repo and noticed that Seems like there should be Is this the correct way for Decompose and are there any examples of such use case? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I've made some experiments and finished with creating separated In interface PostCommentsFeature {
interface IPostComments
fun createComponent(
componentContext: ComponentContext,
postId: Long,
onBackClicked: () -> Unit,
): IPostComments
}
interface PostCommentsContent {
@Composable
fun Content(postComments: PostCommentsFeature.IPostComments, modifier: Modifier)
} And in interface PostComments : PostCommentsFeature.IPostComments {
val state: StateFlow<PostCommentsState>
}
class PostCommentsFeatureImpl : PostCommentsFeature, KoinComponent {
override fun createComponent(
componentContext: ComponentContext,
postId: Long,
onBackClicked: () -> Unit,
): PostCommentsFeature.IPostComments = PostCommentsComponent(
componentContext = componentContext,
postId = postId,
onBackClicked = onBackClicked,
postsInteractor = get(),
)
}
class PostCommentsContentImpl : PostCommentsContent {
@Composable
override fun Content(postComments: PostCommentsFeature.IPostComments, modifier: Modifier) {
PostCommentsUi(
component = postComments as PostComments, // extra cast
modifier = modifier,
)
}
} May be there is better or recommended approach. |
Beta Was this translation helpful? Give feedback.
-
Hello. First of all, the main idea of the Regardless of the reasons, I still find the way how it is done in the sample is correct. Consider you want to move the But if you like the way how you are doing it, then go ahead with it. I don't have any reasonable objections, except maybe the cast. |
Beta Was this translation helpful? Give feedback.
Hello. First of all, the main idea of the
dynamic-features
sample is to demonstrate how Decompose can be integrated with Android Dynamic Features, where modules are loaded on demand. It is required for feature modules to depend on theapp
module, which completely the opposite way of how feature modules should be organized. This is the only reason why I split features for APIs and impls. In all other cases personally I don't recommend splitting for API and impls, as in most cases it is an over-engineering.Regardless of the reasons, I still find the way how it is done in the sample is correct. Consider you want to move the
Feature1Content
interface to anotherapi
modulefeature1UiApi
. In t…