The second midterm exam will be held in class on Wednesday, Nov. 4. The exam will cover the material I have posted on the course web site in the "Jetpack Compose" section.
The exam will mostly focus on key concepts in Jetpack Compose applications, including
Text(), TextField(), and Button()I will ask two types of questions. In the first type of question I will show you a chunk of code and ask you to explain what the code is doing. In the second type of question I will ask you to explain how you would accomplish a particular task: for this type of question you can answer with a mix of written explanation and a few relevant snippets of code.
Here are some sample questions:
1. What does this code do?
@Composable
fun CalculatorScreen(code : String, toOptions: () -> Unit,modifier: Modifier) {
Scaffold(topBar = {
TopAppBar(
title = {
Text(
"Travel Money",
)
},
actions = {
IconButton(onClick = toOptions) {
Icon(
imageVector = Icons.Default.Settings,
contentDescription = "Settings"
)
}
},
)
},
modifier = Modifier.fillMaxSize())
{ innerPadding ->
Calculator(code,modifier.padding(innerPadding))
}
}
2. What does this code do?
@Composable
fun WeatherApp(modifier : Modifier) {
val vm : WeatherModel = viewModel()
vm.getForecast()
val navController = rememberNavController()
NavHost(navController,startDestination="forecast") {
composable(route="forecast") {
WeatherScreen(vm,toOptions = { navController.navigate("location")}, modifier = modifier)
}
composable(route="location") {
LocationScreen(vm,back = { navController.navigate("forecast")}, modifier = modifier)
}
}
}
3. To implement navigation we use a NavController with a NavHost. The NavHost consists of a list of routes implemented via composable(), and each route contains a component for the view that that route displays. Suppose we made an app with two views, viewA() and viewB(). Suppose further that we wanted to add a Close button in viewB() that would take us back to viewA(). How would you implenent something like this?