1 /* <lambda>null2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.avatarpicker.ui 18 19 import com.android.avatarpicker.domain.applyReadBackOrder 20 import androidx.compose.foundation.layout.Arrangement 21 import androidx.compose.foundation.layout.Column 22 import androidx.compose.foundation.layout.PaddingValues 23 import androidx.compose.foundation.layout.Row 24 import androidx.compose.foundation.layout.fillMaxHeight 25 import androidx.compose.foundation.layout.padding 26 import androidx.compose.foundation.layout.statusBarsPadding 27 import androidx.compose.foundation.lazy.grid.GridCells 28 import androidx.compose.foundation.lazy.grid.GridItemSpan 29 import androidx.compose.foundation.lazy.grid.LazyGridScope 30 import androidx.compose.foundation.lazy.grid.LazyVerticalGrid 31 import androidx.compose.material.Divider 32 import androidx.compose.material3.BottomAppBar 33 import androidx.compose.material3.ExperimentalMaterial3Api 34 import androidx.compose.material3.MaterialTheme 35 import androidx.compose.material3.Scaffold 36 import androidx.compose.runtime.Composable 37 import androidx.compose.ui.Modifier 38 import androidx.compose.ui.unit.dp 39 40 @ExperimentalMaterial3Api 41 @Composable 42 fun AdaptivePane( 43 showOnePane: Boolean, 44 columns: Int, 45 startPane: @Composable () -> Unit, 46 endPane: (scope: LazyGridScope) -> Unit, 47 bottom: @Composable () -> Unit 48 ) { 49 Scaffold( 50 containerColor = MaterialTheme.colorScheme.surfaceContainer, 51 bottomBar = { 52 if (showOnePane) { 53 BottomAppBar(containerColor = MaterialTheme.colorScheme.surfaceContainer) { 54 bottom() 55 } 56 } else { 57 Column(modifier = Modifier.padding(start = 24.dp, end = 24.dp)) { 58 BottomAppBar(containerColor = MaterialTheme.colorScheme.surfaceContainer) { 59 bottom() 60 } 61 } 62 } 63 }) { innerPadding -> 64 Column( 65 modifier = Modifier.statusBarsPadding().padding(innerPadding) 66 ) { 67 if (showOnePane) { 68 LazyVerticalGrid( 69 modifier = Modifier.padding(start = 24.dp, end = 24.dp, top = 8.dp), 70 columns = GridCells.Fixed(columns), 71 horizontalArrangement = Arrangement.spacedBy(24.dp), 72 verticalArrangement = Arrangement.spacedBy(24.dp), 73 contentPadding = PaddingValues(bottom = 24.dp) 74 ) { 75 item(span = { GridItemSpan(maxLineSpan) }) { 76 Column { 77 startPane() 78 } 79 } 80 endPane(this) 81 } 82 } else { 83 Row( 84 modifier = Modifier.statusBarsPadding() 85 .padding(start = 24.dp, end = 24.dp, top = 24.dp), 86 horizontalArrangement = Arrangement.spacedBy(24.dp) 87 ) { 88 Column(modifier = Modifier.weight(1f) 89 .padding(start = 24.dp, end = 24.dp, top = 8.dp) 90 .applyReadBackOrder()) { startPane() } 91 92 LazyVerticalGrid( 93 modifier = Modifier.weight(1f) 94 .padding(top = 104.dp, start = 24.dp, end = 24.dp) 95 .fillMaxHeight(), 96 columns = GridCells.Fixed(columns), 97 horizontalArrangement = Arrangement.spacedBy(24.dp), 98 verticalArrangement = Arrangement.spacedBy(24.dp), 99 contentPadding = PaddingValues(bottom = 24.dp), 100 ) { 101 endPane(this) 102 } 103 104 } 105 Divider(color = MaterialTheme.colorScheme.primary, thickness = 1.dp) 106 } 107 } 108 } 109 }