11package com.huanshankeji.compose.material.demo
22
3- import androidx.compose.runtime.*
4- import androidx.compose.ui.unit.dp
3+ import androidx.compose.runtime.Composable
4+ import androidx.compose.runtime.remember
55import com.huanshankeji.compose.foundation.VerticalScrollBox
6- import com.huanshankeji.compose.foundation.background
7- import com.huanshankeji.compose.foundation.layout.*
8- import com.huanshankeji.compose.foundation.layout.ext.outerPadding
9- import com.huanshankeji.compose.foundation.text.KeyboardActions
10- import com.huanshankeji.compose.foundation.text.KeyboardOptions
11- import com.huanshankeji.compose.foundation.text.input.ImeAction
12- import com.huanshankeji.compose.foundation.text.input.KeyboardCapitalization
13- import com.huanshankeji.compose.foundation.text.input.KeyboardType
146import com.huanshankeji.compose.material.icons.Icons
15- import com.huanshankeji.compose.material.icons.filled.Add
167import com.huanshankeji.compose.material.icons.filled.Done
178import com.huanshankeji.compose.material.icons.filled.Menu
189import com.huanshankeji.compose.material.icons.filled.Search
19- import com.huanshankeji.compose.material2.*
20- import com.huanshankeji.compose.material2.ext.*
21- import com.huanshankeji.compose.material2.lazy.ext.List
22- import com.huanshankeji.compose.material2.lazy.ext.ListItemComponents
23- import com.huanshankeji.compose.material2.lazy.ext.conventionalItem
24- import com.huanshankeji.compose.material2.lazy.ext.conventionalItems
25- import com.huanshankeji.compose.ui.Modifier
26- import com.huanshankeji.compose.ui.graphics.Color
27- import kotlinx.coroutines.launch
28- import com.huanshankeji.compose.material2.ext.Button as ExtButton
10+ import com.huanshankeji.compose.material2.SnackbarHost
11+ import com.huanshankeji.compose.material2.SnackbarHostState
12+ import com.huanshankeji.compose.material2.Text
13+ import com.huanshankeji.compose.material2.ext.TopAppBarScaffold
14+ import com.huanshankeji.compose.material3.ext.TaglessText
2915
3016@Composable
3117fun Material2 (/* modifier: Modifier = Modifier*/ ) {
@@ -46,110 +32,7 @@ fun Material2(/*modifier: Modifier = Modifier*/) {
4632 Text (" FAB" ) // The Material 2 FAB is not added so this is a placeholder.
4733 }) {
4834 VerticalScrollBox {
49- Card (contentPaddingModifier) {
50- Column (contentPaddingModifier.background(Color (0xF8 , 0xF8 , 0xF8 , 0xFF )), Arrangement .spacedBy(16 .dp)) {
51- Text (" Material text" )
52-
53- var count by remember { mutableStateOf(0 ) }
54- val coroutineScope = rememberCoroutineScope()
55- val onClick: () -> Unit = {
56- count++
57- val count = count
58- coroutineScope.launch {
59- snackbarHostState.showSnackbar(" Count incremented to $count " , " action" )
60- }
61- }
62- val buttonContent: @Composable () -> Unit = {
63- TaglessText (count.toString())
64- }
65- val rowScopeButtonContent: @Composable RowScope .() -> Unit = { buttonContent() }
66-
67- Row {
68- Button (onClick, content = rowScopeButtonContent)
69- OutlinedButton (onClick, content = rowScopeButtonContent)
70- TextButton (onClick, content = rowScopeButtonContent)
71- ExtButton (onClick) {
72- Label (count.toString())
73- }
74- IconButton (onClick, icon = Icons .Default .Add , contentDescription = " increment count" )
75- }
76-
77- val listModifier = Modifier .outerPadding(16 .dp).height(listSize)
78- List (listModifier) {
79- item {
80- Text (" Ungrouped item" )
81- }
82- items(count) {
83- Text (" Ungrouped item $it /$count " )
84- }
85- group(headerContent = {
86- Text (" Group title" )
87- }) {
88- item {
89- Text (" Grouped item" )
90- }
91- items(count) {
92- Text (" Grouped item $it /$count " )
93- }
94- }
95- }
96- Divider ()
97- val secondaryText = " Secondary text"
98- List (listModifier) {
99- conventionalItem(content = ListItemComponents (" Ungrouped item" , secondaryText))
100- conventionalItems(count) {
101- ListItemComponents (" Ungrouped item $it /$count " , secondaryText)
102- }
103- group(headerContent = {
104- Text (" Group title" )
105- }) {
106- conventionalItem(content = ListItemComponents (" Grouped item" , secondaryText))
107- conventionalItems(count) {
108- ListItemComponents (" Grouped item $it /$count " , secondaryText)
109- }
110- }
111- }
112-
113- var text by remember { mutableStateOf(" " ) }
114- TextFieldWithMaterialIcons (
115- text, { text = it },
116- label = " Demo text field" ,
117- leadingIcon = Icons .Default .Add ,
118- trailingIcon = Icons .Default .Menu ,
119- keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .Number ),
120- singleLine = true
121- )
122- OutlinedTextFieldWithMaterialIcons (
123- text, { text = it },
124- label = " Demo text field" ,
125- leadingIcon = Icons .Default .Add ,
126- trailingIcon = Icons .Default .Menu ,
127- keyboardOptions = KeyboardOptions (
128- KeyboardCapitalization .Words , true , imeAction = ImeAction .Search
129- ),
130- keyboardActions = KeyboardActions {
131- println (" keyboard actions with: $text " )
132- },
133- singleLine = true
134- )
135- TextArea (text, { text = it }, label = " Demo text field" , lines = 3 )
136-
137- var selected by remember { mutableStateOf(Selection .A ) }
138- RadioGroupRow {
139- @Composable
140- fun RadioButtonRow (state : Selection ) =
141- RadioRow (selected == state, state.toString(), { selected = state })
142- Selection .entries.forEach { RadioButtonRow (it) }
143- }
144-
145- Row {
146- var checked by remember { mutableStateOf(false ) }
147- Checkbox (checked, { checked = it })
148- Switch (checked, { checked = it })
149- SwitchWithLabel (checked, { checked = it }, " Switch" )
150- }
151- }
152- }
35+ TaglessText (" Content" )
15336 }
15437 }
15538}
0 commit comments