Repository: android/compose-samples
File: JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt (Kotlin)

Code before:
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import kotlinx.coroutines.launch

@Composable
fun JetnewsApp(
    appContainer: AppContainer
) {
    JetnewsTheme {
        ProvideWindowInsets {
            val systemUiController = rememberSystemUiController()
            val darkIcons = MaterialTheme.colors.isLight
            SideEffect {
                systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = darkIcons)
            }

            val navController = rememberNavController()
            val navigationActions = remember(navController) { JetnewsNavigationActions(navController) }

            val coroutineScope = rememberCoroutineScope()
            // This top level composable contains the app drawer, which needs to be accessible
            // from multiple screens. An event to open the drawer is passed down to each
            // screen that needs it.
            val drawerState = rememberDrawerState(DrawerValue.Closed)

            val navBackStackEntry by navController.currentBackStackEntryAsState()
            val currentRoute = navBackStackEntry?.destination?.route ?: JetnewsDestinations.HOME_ROUTE

            BoxWithConstraints {
                val windowSize = getWindowSize(maxWidth)

                val allowDrawerToBeShown = windowSize == WindowSize.Compact

                // Determine the drawer state to pass to the modal drawer.
                val sizeAwareDrawerState = if (allowDrawerToBeShown) {
                    // If we want to allow showing the drawer, we use the real, remembered drawer
                    // state defined above
                    drawerState
                } else {
                    // If we don't want to allow the drawer to be shown, we provide a drawer state
                    // that is locked closed. This is intentionally not remembered, because we
                    // don't want to keep track of any changes and always keep it closed
                    DrawerState(DrawerValue.Closed)
                }

                ModalDrawer(
                    drawerContent = {
                        AppDrawer(
                            currentRoute = currentRoute,
                            navigateToHome = navigationActions.navigateToHome,
                            navigateToInterests = navigationActions.navigateToInterests,
                            closeDrawer = { coroutineScope.launch { drawerState.close() } }

Review comment (suggestion):
```suggestion
                val allowDrawerToBeShown = remember(windowSize) {
                    windowSize == WindowSize.Compact
                }
```

I'd probably remember this as this composable can be recomposed a lot of times due to `BoxWithConstraints`

Code after:
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import kotlinx.coroutines.launch

@Composable
fun JetnewsApp(
    appContainer: AppContainer
) {
    JetnewsTheme {
        ProvideWindowInsets {
            val systemUiController = rememberSystemUiController()
            val darkIcons = MaterialTheme.colors.isLight
            SideEffect {
                systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = darkIcons)
            }

            val navController = rememberNavController()
            val navigationActions = remember(navController) { JetnewsNavigationActions(navController) }

            val coroutineScope = rememberCoroutineScope()

            val navBackStackEntry by navController.currentBackStackEntryAsState()
            val currentRoute = navBackStackEntry?.destination?.route ?: JetnewsDestinations.HOME_ROUTE

            BoxWithConstraints {
                val windowSize = getWindowSize(maxWidth)
                val allowDrawerToBeShown = windowSize == WindowSize.Compact
                val sizeAwareDrawerState = rememberSizeAwareDrawerState(allowDrawerToBeShown)

                ModalDrawer(
                    drawerContent = {
                        AppDrawer(
                            currentRoute = currentRoute,
                            navigateToHome = navigationActions.navigateToHome,
                            navigateToInterests = navigationActions.navigateToInterests,
                            closeDrawer = { coroutineScope.launch { sizeAwareDrawerState.close() } }
                        )
                    },
                    drawerState = sizeAwareDrawerState,
                    // Only enable opening the drawer via gestures if we allow showing it
                    gesturesEnabled = allowDrawerToBeShown
                ) {
                    JetnewsNavGraph(
                        appContainer = appContainer,
                        // Either allow showing the drawer, or show the nav rail
                        showNavRail = !allowDrawerToBeShown,
                        navController = navController,
                        openDrawer = { coroutineScope.launch { sizeAwareDrawerState.open() } },
                        navigationActions = navigationActions,
                    )
                }
            }