BottomButtonBox.kt (3269B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2024 Taler Systems S.A. 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 package net.taler.wallet.compose 18 19 import androidx.compose.foundation.background 20 import androidx.compose.foundation.layout.Box 21 import androidx.compose.foundation.layout.Column 22 import androidx.compose.foundation.layout.ColumnScope 23 import androidx.compose.foundation.layout.Row 24 import androidx.compose.foundation.layout.Spacer 25 import androidx.compose.foundation.layout.fillMaxWidth 26 import androidx.compose.foundation.layout.height 27 import androidx.compose.foundation.layout.padding 28 import androidx.compose.material3.Button 29 import androidx.compose.material3.MaterialTheme 30 import androidx.compose.material3.Text 31 import androidx.compose.runtime.Composable 32 import androidx.compose.ui.Alignment 33 import androidx.compose.ui.Modifier 34 import androidx.compose.ui.tooling.preview.Preview 35 import androidx.compose.ui.unit.dp 36 37 @Composable 38 fun BottomButtonBox( 39 modifier: Modifier = Modifier, 40 heading: (@Composable ColumnScope.() -> Unit)? = null, 41 leading: (@Composable () -> Unit)? = null, 42 trailing: (@Composable () -> Unit)? = null, 43 ) { 44 Column(modifier = modifier 45 .background(MaterialTheme.colorScheme.surfaceContainerHigh) 46 .padding(12.dp), 47 horizontalAlignment = Alignment.End, 48 ) { 49 if (heading != null) { 50 Column( 51 modifier = Modifier.padding(bottom = 6.dp), 52 horizontalAlignment = Alignment.End, 53 content = heading, 54 ) 55 } 56 57 Row(verticalAlignment = Alignment.Bottom) { 58 leading?.let { 59 Box( 60 modifier = Modifier.weight(1f), 61 contentAlignment = Alignment.CenterStart, 62 ) { it() } 63 } 64 65 trailing?.let { 66 Box( 67 modifier = Modifier.weight(1f), 68 contentAlignment = Alignment.CenterEnd, 69 ) { it() } 70 } 71 } 72 } 73 } 74 75 @Preview 76 @Composable 77 fun BottomButtonBoxPreview() { 78 TalerSurface { 79 Column { 80 Spacer(Modifier.height(100.dp)) 81 82 BottomButtonBox( 83 modifier = Modifier.fillMaxWidth(), 84 heading = { 85 Text("Something, something") 86 }, 87 leading = { 88 Button(onClick = {}) { 89 Text("Back") 90 } 91 }, 92 trailing = { 93 Button(onClick = {}) { 94 Text("Continue") 95 } 96 } 97 ) 98 } 99 } 100 }