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

Code before:
        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() } }
                        )
                    },
                    drawerState = sizeAwareDrawerState,
                    // Only enable opening the drawer via gestures if we allow showing it
                    gesturesEnabled = allowDrawerToBeShown
                ) {
                    JetnewsNavGraph(
                        appContainer = appContainer,

Review comment (refactor):
This looks like an implementation detail I might not want to see when looking at `JetnewsApp`. Should we move this logic to a separate private composable function that decides which drawer state to return?

```
@Composable
private fun rememberSizeAwareDrawerState(allowDrawerToBeShown: Boolean) {
    val drawerState = rememberDrawerState(DrawerValue.Closed)
    return if (allowDrawerToBeShown) ...
}
```

Code after:
        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,
                    )
                }
            }
        }
    }
}

/**
 * Determine the drawer state to pass to the modal drawer.
 */
@Composable