Skip to content

Instantly share code, notes, and snippets.

@piotrsedlak
Created May 6, 2021 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotrsedlak/9de5319f1748762b1ed2990fa07d858f to your computer and use it in GitHub Desktop.
Save piotrsedlak/9de5319f1748762b1ed2990fa07d858f to your computer and use it in GitHub Desktop.
SpacedBy issue
package com.example.myapplicationterset
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Color.Companion.Red
import androidx.compose.ui.graphics.Color.Companion.White
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.example.myapplicationterset.ui.theme.MyApplicationTersetTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTersetTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
DialogTest()
}
}
}
}
}
@Composable
fun DialogTest() {
Dialog(onDismissRequest = {}) {
Surface(
shape = RoundedCornerShape(8.dp),
color = White,
modifier = Modifier
.width(300.dp)
.height(200.dp)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Row(
horizontalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier
.padding(horizontal = 12.dp)
) {
DialogButton(
backgroundColor = Red,
modifier = Modifier
.fillMaxWidth()
.height(44.dp)
.weight(1f),
text = "button1",
)
DialogButton(
backgroundColor = Red,
modifier = Modifier
.fillMaxWidth()
.height(44.dp)
.weight(1f),
text = "button2",
)
}
}
}
}
}
@Composable
fun DialogButton(
backgroundColor: Color,
modifier: Modifier,
text: String,
border: BorderStroke? = null,
state: Boolean = true
) {
Button(
onClick = { },
border = border,
enabled = state,
shape = MaterialTheme.shapes.medium,
colors = ButtonDefaults.buttonColors(backgroundColor = backgroundColor),
modifier = modifier
) {
Text(text = text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment