Afzal Najam
08/30/2022, 4:45 PMStylianos Gakis
08/30/2022, 8:12 PMAfzal Najam
08/30/2022, 11:00 PMcalculateWindowSizeClass
but actually I’m just asking for knowledge. I know, for that, you can just calculate it and pass that down but I wanna know for doing a code review, what exactly is the reason.Stylianos Gakis
08/30/2022, 11:31 PMAfzal Najam
08/30/2022, 11:33 PMPersonally I’d request this to be changed if I saw an Activity being passed into a composableRight, and I agree, but with what reason?
Stylianos Gakis
08/31/2022, 7:45 AMWindowSizeClass
instead there’s a much bigger chance you’re gonna have that available to you to call this composable from various other places.Filip Wiesner
08/31/2022, 11:41 AMsetContent {
// Calculate the window size class for the activity's current window. If the window
// size changes, for example when the device is rotated, the value returned by
// calculateSizeClass will also change.
val windowSizeClass = calculateWindowSizeClass(this)
// Perform logic on the window size class to decide whether to use a nav rail.
val useNavRail = windowSizeClass.widthSizeClass > WindowWidthSizeClass.Compact
// MyScreen knows nothing about window size classes, and performs logic based on a
// Boolean flag.
MyScreen(useNavRail = useNavRail)
}
Especially the last comment:
MyScreen knows nothing about window size classes, and performs logic based on a Boolean flag.Your Composable does not have to have any dependency on Activity or any other class. You can just tell it how it should behave and not on what data it should behave. The resulting Composable will be more reusable and more maintainable.
Afzal Najam
08/31/2022, 9:49 PM