Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material 3 Adaptive Support Pane #456

Merged
merged 16 commits into from
Feb 19, 2024
Merged
16 changes: 8 additions & 8 deletions CanonicalLayouts/supporting-pane-compose/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ plugins {

android {
namespace 'com.example.supportingpanecompose'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.example.supportingpanecompose"
minSdk 21
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -65,15 +65,15 @@ android {
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2022.10.00')
implementation(composeBom)

implementation "com.google.accompanist:accompanist-adaptive:0.27.0"
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation "androidx.window:window:1.1.0-alpha03"
implementation "androidx.window:window:1.2.0"
implementation 'androidx.compose.material3:material3'
implementation("androidx.compose.material3:material3-adaptive:1.0.0-alpha04")
implementation "androidx.compose.material3:material3-window-size-class"
testImplementation 'junit:junit:4.13.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ package com.example.supportingpanecompose
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import com.example.supportingpanecompose.ui.SupportingPaneSample
import com.example.supportingpanecompose.ui.theme.SupportingPaneCompose
import com.google.accompanist.adaptive.calculateDisplayFeatures

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SupportingPaneCompose {
SupportingPaneSample(
windowSizeClass = calculateWindowSizeClass(this),
displayFeatures = calculateDisplayFeatures(this)
)
SupportingPaneSample()
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.example.supportingpanecompose.ui

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -24,18 +26,23 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.adaptive.AnimatedPane
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.SupportingPaneScaffold
import androidx.compose.material3.adaptive.SupportingPaneScaffoldRole
import androidx.compose.material3.adaptive.rememberSupportingPaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.window.layout.DisplayFeature

// Create some simple sample data
private val data = mapOf(
Expand All @@ -47,53 +54,82 @@ private val data = mapOf(
"flutter" to listOf("android", "desktop")
)

@ExperimentalMaterial3AdaptiveApi
@Composable
fun SupportingPaneSample(
windowSizeClass: WindowSizeClass,
displayFeatures: List<DisplayFeature>
) {
fun SupportingPaneSample() {
var selectedTopic: String by rememberSaveable { mutableStateOf(data.keys.first()) }
val navigator = rememberSupportingPaneScaffoldNavigator()

SupportingPane(
main = {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
SupportingPaneScaffold(
supportingPane = {
AnimatedPane(
modifier = Modifier
.background(
color = Color.LightGray.copy(alpha = .3f),
shape = RoundedCornerShape(16.dp)
)
.padding(all = 16.dp)
) {
Text("Main Content", style = MaterialTheme.typography.titleLarge)
Text(selectedTopic)
}
},
supporting = {
Column(
modifier = Modifier.fillMaxSize()
) {
Text("Related Content", style = MaterialTheme.typography.titleLarge)
Column {
Text(
"Related Content",
alexvanyo marked this conversation as resolved.
Show resolved Hide resolved
modifier = Modifier.padding(vertical = 16.dp),
style = MaterialTheme.typography.titleLarge
)

LazyColumn {
items(
data.getValue(selectedTopic),
key = { it }
) { relatedTopic ->
Box(
Modifier
.fillMaxWidth()
.clickable {
selectedTopic = relatedTopic
}
) {
Text(
text = relatedTopic,
modifier = Modifier
.padding(16.dp)

)
LazyColumn {
items(
data.getValue(selectedTopic),
key = { it }
) { relatedTopic ->
Box(
Modifier
.fillMaxWidth()
.padding(all = 4.dp)
.clickable {
selectedTopic = relatedTopic
if (navigator.canNavigateBack()) {
navigator.navigateBack()
IanGClifton marked this conversation as resolved.
Show resolved Hide resolved
}
}
) {
Text(
text = relatedTopic,
modifier = Modifier
)
}
}
}
}

BackHandler(enabled = navigator.canNavigateBack()) {
alexvanyo marked this conversation as resolved.
Show resolved Hide resolved
navigator.navigateBack()
}
}
},
windowSizeClass = windowSizeClass,
displayFeatures = displayFeatures
)
scaffoldState = navigator.scaffoldState
tiwiz marked this conversation as resolved.
Show resolved Hide resolved
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
Text("Main Content", style = MaterialTheme.typography.titleLarge)

Box(
Modifier
.fillMaxWidth()
.padding(all = 8.dp)
.clickable {
navigator.navigateTo(SupportingPaneScaffoldRole.Supporting)
},
contentAlignment = Alignment.Center
) {
Text(
text = selectedTopic,
modifier = Modifier
.padding(16.dp)
)
}
}
}
}
4 changes: 2 additions & 2 deletions CanonicalLayouts/supporting-pane-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'com.android.application' version '8.2.1' apply false
id 'com.android.library' version '8.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
4 changes: 3 additions & 1 deletion CanonicalLayouts/supporting-pane-compose/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed May 25 14:11:15 UTC 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME