Kazemihabib1996
03/12/2020, 4:57 PM@Composable
private fun HomeScreenTopSection(post: Post) {
ProvideEmphasis(emphasis = EmphasisLevels().high) {
Text(
modifier = LayoutPadding(start = 16.dp, top = 16.dp, end = 16.dp, bottom = 0.dp),
text = "Top stories for you",
style = MaterialTheme.typography().subtitle1
)
}
Ripple(bounded = true) {
Clickable(onClick = {
navigateTo(Screen.Article(post.id))
}) {
PostCardTop(post = post)
}
}
HomeScreenDivider()
}
As you see it's an incomplete composable function because we are calling 3 other functions without a Row or Column, and HomeScreenTopSection
can draw correctly just because the parent has called it inside a column:
https://github.com/android/compose-samples/blob/master/JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt#L88
Column(modifier = modifier) {
HomeScreenTopSection(post = postTop)
HomeScreenSimpleSection(posts = postsSimple)
HomeScreenPopularSection(posts = postsPopular)
HomeScreenHistorySection(posts = postsHistory)
}
So if I call HomeScreenTopSection
outside a column or row, there are multiple possible solutions:
1) the compose framework can decide to put it inside a Row for example
2) Keep the first one and throw away others and seems that compose follows this approach at the moment.
3) Threw error
I think first and second solutions are not appropriate solutions and seems that throwing compile time error is not possible and just remains run time error.
Our functions return Unit, if they return something the HomeScreenTopSection
should return a list and the problem is solved we can throw compile time errors.
but with returning functions we loose lots of its benefits so that's not an option here,
but what about adding annotations like ThisShouldBeCalledInsideRowOrColumn
(I know it's a worst naming you ever seen 😬) ?Leland Richardson [G]
03/12/2020, 5:31 PMRow
vs putting it inside of a Column
Kazemihabib1996
03/12/2020, 5:40 PMLeland Richardson [G]
03/12/2020, 5:40 PMColumn {
Node()
Node()
Node()
}
and
Column {
Nodes()
}
Where
@Composable fun Nodes() {
Node()
Node()
Node()
}
Kazemihabib1996
03/12/2020, 8:06 PM