rsktash
07/07/2021, 8:21 PM@Cooposable
fun RenderSomeUI(modifier: Modifier, content: @Composable () -> TextUnit){
}
rsktash
07/07/2021, 8:22 PMjim
07/07/2021, 8:32 PM@Composable @ContentType("Text") ()->Unit
or @Composable @TextType ()->Unit
as these are annotations and you can have your own annotation checkers to verify them. Nothing stops you from building this on top of Compose, hence it doesn't need to be a part of the Compose core.
However, more to the point, it isn't clear that such restrictions are beneficial. We believe that Compose should not take a privileged position, meaning that if we can implement a Text()
widget, you should just as easily be able to implement such a MyFancyText()
widget which is otherwise interchangable. If the content of Composables were restricted, that violates the fundamental philosophy of nothing we do being privileged, because now you must use our widgets if you want to be interoperable with other widgets.
If the container widget needs to make assumptions about properties of the content (like it being only text), you're better off just having your widget accept a string and directly control its children. That way, you don't need to worry about the endless permutations of things that a user could do to break your assumptions (a text widget with padding, or a crazy font size, or whatever else a user might try).rsktash
07/07/2021, 8:37 PMjim
07/07/2021, 8:45 PMAnton Popov
07/07/2021, 8:49 PMrsktash
07/07/2021, 8:59 PMjim
07/07/2021, 9:01 PMjim
07/07/2021, 9:02 PMrsktash
07/07/2021, 9:07 PMJavier
07/07/2021, 9:21 PMColton Idle
07/08/2021, 4:16 AM