Glenn Martin
01/10/2021, 1:36 PM@ExperimentalLayout
@Composable
fun mainLayout(view: @Composable () -> Unit) {
Row(Modifier.fillMaxSize()) {
Box(modifier = Modifier.fillMaxWidth(0.2f), contentAlignment = Alignment.Center) {
sideBarItems()
}
view()
}
}
this works on first load, but when i call this from an onClick() event on those sidebar items I get an error about calling composable from an onclick()Dominaezzz
01/10/2021, 1:39 PMonClick
?Dominaezzz
01/10/2021, 1:40 PMArkadii Ivanov
01/10/2021, 3:27 PMsealed class Screen {
object Container : Screen()
object Jobs : Screen()
}
Then you need a state:
var screen by remember { mutableStateOf(Screen.Container) }
Then you need to change the state to whatever screen in onClick.
To draw current screen:
when (screen) {
is Container -> ContainerView()
is Jobs -> JobsView ()
}
xetra11
01/10/2021, 5:21 PMArkadii Ivanov
01/10/2021, 8:36 PMxetra11
01/10/2021, 9:40 PMGlenn Martin
01/10/2021, 11:33 PMonClick()
are on a sidebar text button, the UI is one row with a sidebar and bodyGlenn Martin
01/10/2021, 11:38 PMviewPageWithState
takes a pagestate which is an enum and in that class I have a switch statement which matches the pagestate with a particular view, but for me I can't get it to workGlenn Martin
01/10/2021, 11:38 PMGlenn Martin
01/10/2021, 11:46 PMArkadii Ivanov
01/11/2021, 1:08 AMScreen
is like a description of what is the current screen and what are parameters
2. You should replace your view()
with the switch
. It just selects/renders the current screen defined by the state.
3. Your sideBarItems
should accept callbacks, e.g. onContainerClicked
, onJobsClicked
, etc.. Each callback should change the state:
sideBarItems(
onContainerClicked = { screen = Screen.Container },
onJobsClicked = { screen = <http://Screen.Jobs|Screen.Jobs> }
)
Glenn Martin
01/11/2021, 2:05 AMGlenn Martin
01/17/2021, 7:32 AMGlenn Martin
01/17/2021, 7:32 AMxetra11
01/17/2021, 8:58 AMwhere
clause for it. You only need to create a sealed class and it's available right aways since you just need to say MyInterface.view()
(example) instead of MemberView.view()
xetra11
01/17/2021, 8:58 AMxetra11
01/17/2021, 8:58 AMGlenn Martin
01/17/2021, 2:16 PMGlenn Martin
01/17/2021, 2:16 PMGlenn Martin
01/17/2021, 2:17 PMGlenn Martin
01/17/2021, 2:18 PMxetra11
01/17/2021, 5:42 PMxetra11
01/17/2021, 5:42 PMGlenn Martin
01/24/2021, 2:43 AM