@@ -3,27 +3,29 @@ package io.syslogic.colorpicker.compose
3
3
import androidx.compose.foundation.clickable
4
4
import androidx.compose.foundation.layout.*
5
5
import androidx.compose.foundation.shape.RoundedCornerShape
6
-
7
6
import androidx.compose.material.*
8
7
import androidx.compose.material.icons.Icons
9
8
import androidx.compose.material.icons.filled.Close
10
-
11
9
import androidx.compose.runtime.*
12
-
13
10
import androidx.compose.ui.Alignment
14
11
import androidx.compose.ui.Modifier
15
12
import androidx.compose.ui.graphics.Color
13
+ import androidx.compose.ui.layout.layoutId
16
14
import androidx.compose.ui.platform.LocalContext
17
15
import androidx.compose.ui.platform.LocalDensity
16
+ import androidx.compose.ui.platform.testTag
17
+ import androidx.compose.ui.res.colorResource
18
18
import androidx.compose.ui.res.dimensionResource
19
19
import androidx.compose.ui.text.TextStyle
20
20
import androidx.compose.ui.text.font.FontFamily
21
21
import androidx.compose.ui.text.font.FontWeight
22
22
import androidx.compose.ui.unit.Dp
23
23
import androidx.compose.ui.window.Dialog
24
+ import androidx.compose.ui.window.DialogProperties
24
25
25
26
import io.syslogic.colorpicker.OnColorChangedListener
26
27
import io.syslogic.colorpicker.R
28
+ import io.syslogic.colorpicker.compose.LayoutId.*
27
29
28
30
/* *
29
31
* Jetpack Compose Color-Picker Dialog
@@ -45,54 +47,64 @@ fun ColorPickerDialog(
45
47
/* The value is being initialized by the `initialColor`. */
46
48
val currentColor: Int by remember { mutableStateOf(initialColor.hashCode()) }
47
49
48
- Dialog (onDismissRequest = { showDialog(false ) }) {
50
+ Dialog (
51
+ onDismissRequest = {
52
+ showDialog(false )
53
+ },
54
+ properties = DialogProperties ()
55
+ ) {
49
56
Surface (
50
57
shape = RoundedCornerShape (dimensionResource(R .dimen.compose_dialog_border_radius)),
51
- color = Color .White
58
+ color = colorResource(id = R .color.cardview_light_background),
59
+ modifier = Modifier
60
+ .layoutId(DialogSurface )
61
+ .testTag(" surface" )
52
62
) {
53
- Box (
54
- contentAlignment = Alignment .Center
63
+ Column (
64
+ modifier = Modifier
65
+ .padding(dimensionResource(R .dimen.compose_dialog_column_padding))
55
66
) {
56
- Column (
57
- modifier = Modifier
58
- .padding(dimensionResource(R .dimen.compose_dialog_column_padding))
59
- ) {
60
67
61
- Row (
62
- modifier = Modifier .fillMaxWidth(),
63
- horizontalArrangement = Arrangement .SpaceBetween ,
64
- verticalAlignment = Alignment .CenterVertically
65
- ) {
66
- Text (
67
- text = dialogTitle,
68
- style = TextStyle (
69
- fontSize = toSp(dp = dimensionResource(R .dimen.compose_dialog_title_font_size)),
70
- fontFamily = FontFamily .Default ,
71
- fontWeight = FontWeight .Bold
72
- )
73
- )
74
- Icon (
75
- imageVector = Icons .Filled .Close ,
76
- contentDescription = " " ,
77
- tint = Color .DarkGray ,
78
- modifier = Modifier
79
- .width(dimensionResource(R .dimen.compose_dialog_close_icon_size))
80
- .height(dimensionResource(R .dimen.compose_dialog_close_icon_size))
81
- .clickable { showDialog(false ) }
68
+ Row (
69
+ horizontalArrangement = Arrangement .SpaceBetween ,
70
+ verticalAlignment = Alignment .CenterVertically ,
71
+ modifier = Modifier .fillMaxWidth()
72
+ ) {
73
+ Text (
74
+ text = dialogTitle,
75
+ style = TextStyle (
76
+ fontSize = toSp(dp = dimensionResource(R .dimen.compose_dialog_title_font_size)),
77
+ fontFamily = FontFamily .Default ,
78
+ fontWeight = FontWeight .Bold
82
79
)
83
- }
84
-
85
- Spacer (
86
- modifier = Modifier .height(dimensionResource(R .dimen.compose_dialog_spacer_height))
87
80
)
81
+ Icon (
82
+ imageVector = Icons .Filled .Close ,
83
+ contentDescription = " " ,
84
+ tint = Color .DarkGray ,
85
+ modifier = Modifier
86
+ .width(dimensionResource(R .dimen.compose_dialog_close_icon_size))
87
+ .height(dimensionResource(R .dimen.compose_dialog_close_icon_size))
88
+ .clickable { showDialog(false ) }
89
+ )
90
+ }
88
91
92
+ Spacer (
93
+ modifier = Modifier .height(dimensionResource(R .dimen.compose_dialog_spacer_height))
94
+ )
95
+
96
+ Box (
97
+ modifier = Modifier
98
+ .wrapContentHeight()
99
+ .wrapContentWidth()
100
+ ) {
89
101
ColorPickerComponent (
90
102
initialColor = Color (currentColor),
91
103
onColorChanged = onColorChanged,
92
104
showAlpha = showAlpha,
93
- showARGB = showARGB ,
105
+ showHex = showHex ,
94
106
showHSV = showHSV,
95
- showHex = showHex
107
+ showARGB = showARGB
96
108
)
97
109
}
98
110
}
0 commit comments