Skip to content

Commit

Permalink
Replace custom WindowSizeClasses with material3-window-size-class (#729)
Browse files Browse the repository at this point in the history
Co-authored-by: Rebecca Franks <[email protected]>
  • Loading branch information
alexvanyo and riggaroo authored May 11, 2022
1 parent c38afb5 commit b2a640b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 141 deletions.
3 changes: 1 addition & 2 deletions JetNews/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ dependencies {
implementation "androidx.compose.foundation:foundation-layout:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
implementation "androidx.compose.material3:material3-window-size-class:1.0.0-alpha10"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.animation:animation:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
Expand Down Expand Up @@ -140,8 +141,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
allWarningsAsErrors = project.hasProperty("warningsAsErrors") ? project.warningsAsErrors : false

freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn'
// Enable experimental coroutines APIs, including Flow
freeCompilerArgs += '-opt-in=kotlin.Experimental'

// Set JVM target to 1.8
jvmTarget = "1.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.material.DrawerValue
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalDrawer
import androidx.compose.material.rememberDrawerState
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
Expand All @@ -47,14 +48,13 @@ import androidx.navigation.compose.rememberNavController
import com.example.jetnews.data.AppContainer
import com.example.jetnews.ui.components.AppNavRail
import com.example.jetnews.ui.theme.JetnewsTheme
import com.example.jetnews.utils.WindowSize
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import kotlinx.coroutines.launch

@Composable
fun JetnewsApp(
appContainer: AppContainer,
windowSize: WindowSize
widthSizeClass: WindowWidthSizeClass
) {
JetnewsTheme {
val systemUiController = rememberSystemUiController()
Expand All @@ -74,7 +74,7 @@ fun JetnewsApp(
val currentRoute =
navBackStackEntry?.destination?.route ?: JetnewsDestinations.HOME_ROUTE

val isExpandedScreen = windowSize == WindowSize.Expanded
val isExpandedScreen = widthSizeClass == WindowWidthSizeClass.Expanded
val sizeAwareDrawerState = rememberSizeAwareDrawerState(isExpandedScreen)

ModalDrawer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ package com.example.jetnews.ui
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.view.WindowCompat
import com.example.jetnews.JetnewsApplication
import com.example.jetnews.utils.rememberWindowSizeClass

class MainActivity : AppCompatActivity() {

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)

val appContainer = (application as JetnewsApplication).container
setContent {
val windowSizeClass = rememberWindowSizeClass()
JetnewsApp(appContainer, windowSizeClass)
val widthSizeClass = calculateWindowSizeClass(this).widthSizeClass
JetnewsApp(appContainer, widthSizeClass)
}
}
}
81 changes: 0 additions & 81 deletions JetNews/app/src/main/java/com/example/jetnews/utils/WindowSize.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.example.jetnews

import android.content.Context
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import com.example.jetnews.ui.JetnewsApp
import com.example.jetnews.utils.WindowSize

/**
* Launches the app from a test context
Expand All @@ -28,7 +28,7 @@ fun ComposeContentTestRule.launchJetNewsApp(context: Context) {
setContent {
JetnewsApp(
appContainer = TestAppContainer(context),
windowSize = WindowSize.Compact
widthSizeClass = WindowWidthSizeClass.Compact
)
}
}

This file was deleted.

0 comments on commit b2a640b

Please sign in to comment.