@@ -13,18 +13,15 @@ import androidx.compose.material.*
13
13
import androidx.compose.runtime.getValue
14
14
import androidx.compose.runtime.mutableStateOf
15
15
import androidx.compose.runtime.remember
16
- import androidx.compose.runtime.saveable.rememberSaveable
17
16
import androidx.compose.runtime.setValue
18
17
import androidx.compose.ui.Modifier
19
18
import androidx.compose.ui.graphics.luminance
20
19
import androidx.compose.ui.unit.dp
20
+ import com.holix.android.bottomsheetdialog.compose.BottomSheetBehaviorProperties
21
21
import com.holix.android.bottomsheetdialog.compose.BottomSheetDialog
22
22
import com.holix.android.bottomsheetdialog.compose.BottomSheetDialogProperties
23
23
import com.holix.android.bottomsheetdialog.compose.NavigationBarProperties
24
- import com.holix.android.bottomsheetdialogcomposedemo.preferences.BooleanPreference
25
- import com.holix.android.bottomsheetdialogcomposedemo.preferences.ColorPreference
26
- import com.holix.android.bottomsheetdialogcomposedemo.preferences.PreferenceCategory
27
- import com.holix.android.bottomsheetdialogcomposedemo.preferences.SingleChoicePreference
24
+ import com.holix.android.bottomsheetdialogcomposedemo.preferences.*
28
25
29
26
class MainActivity : AppCompatActivity () {
30
27
override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -37,30 +34,64 @@ class MainActivity : AppCompatActivity() {
37
34
lightColors()
38
35
}
39
36
) {
40
- var showBottomSheetDialog by rememberSaveable {
37
+ var showBottomSheetDialog by remember {
41
38
mutableStateOf(false )
42
39
}
43
40
// BottomSheetProperties
44
- var dismissOnBackPress by rememberSaveable {
41
+ var dismissOnBackPress by remember {
45
42
mutableStateOf(true )
46
43
}
47
- var dismissOnClickOutside by rememberSaveable {
44
+ var dismissOnClickOutside by remember {
48
45
mutableStateOf(true )
49
46
}
50
- var dismissWithAnimation by rememberSaveable {
47
+ var dismissWithAnimation by remember {
51
48
mutableStateOf(false )
52
49
}
53
50
// NavigationBarProperties
54
51
val surfaceColor = MaterialTheme .colors.surface
55
52
var navigationBarColor by remember(surfaceColor) {
56
53
mutableStateOf(surfaceColor)
57
54
}
58
- var darkIcons by rememberSaveable {
55
+ var darkIcons by remember {
59
56
mutableStateOf(DarkIconsValue .Default )
60
57
}
61
- var navigationBarContrastEnforced by rememberSaveable {
58
+ var navigationBarContrastEnforced by remember {
62
59
mutableStateOf(true )
63
60
}
61
+ // BottomSheetBehaviorProperties
62
+ var state by remember {
63
+ mutableStateOf(BottomSheetBehaviorProperties .State .Collapsed )
64
+ }
65
+ var maxWidth by remember {
66
+ mutableStateOf(BottomSheetBehaviorProperties .Size .NotSet )
67
+ }
68
+ var maxHeight by remember {
69
+ mutableStateOf(BottomSheetBehaviorProperties .Size .NotSet )
70
+ }
71
+ var isDraggable by remember {
72
+ mutableStateOf(true )
73
+ }
74
+ var expandedOffset by remember {
75
+ mutableStateOf(0 )
76
+ }
77
+ var halfExpandedRatio by remember {
78
+ mutableStateOf(0.5F )
79
+ }
80
+ var isHideable by remember {
81
+ mutableStateOf(true )
82
+ }
83
+ var peekHeight by remember {
84
+ mutableStateOf(BottomSheetBehaviorProperties .PeekHeight .Auto )
85
+ }
86
+ var isFitToContents by remember {
87
+ mutableStateOf(true )
88
+ }
89
+ var skipCollapsed by remember {
90
+ mutableStateOf(false )
91
+ }
92
+ var isGestureInsetBottomIgnored by remember {
93
+ mutableStateOf(false )
94
+ }
64
95
if (showBottomSheetDialog) {
65
96
BottomSheetDialog (
66
97
onDismissRequest = {
@@ -79,6 +110,19 @@ class MainActivity : AppCompatActivity() {
79
110
DarkIconsValue .False -> false
80
111
},
81
112
navigationBarContrastEnforced = navigationBarContrastEnforced
113
+ ),
114
+ behaviorProperties = BottomSheetBehaviorProperties (
115
+ state = state,
116
+ maxWidth = maxWidth,
117
+ maxHeight = maxHeight,
118
+ isDraggable = isDraggable,
119
+ expandedOffset = expandedOffset,
120
+ halfExpandedRatio = halfExpandedRatio,
121
+ isHideable = isHideable,
122
+ peekHeight = peekHeight,
123
+ isFitToContents = isFitToContents,
124
+ skipCollapsed = skipCollapsed,
125
+ isGestureInsetBottomIgnored = isGestureInsetBottomIgnored
82
126
)
83
127
)
84
128
) {
@@ -93,7 +137,7 @@ class MainActivity : AppCompatActivity() {
93
137
verticalArrangement = Arrangement .spacedBy(16 .dp)
94
138
) {
95
139
Text (text = " Title" , style = MaterialTheme .typography.h5)
96
- repeat(5 ) { index ->
140
+ repeat(30 ) { index ->
97
141
Text (
98
142
text = " Item $index " ,
99
143
style = MaterialTheme .typography.body1
@@ -154,8 +198,7 @@ class MainActivity : AppCompatActivity() {
154
198
value.name,
155
199
when (value) {
156
200
DarkIconsValue .Default ->
157
- " Default (color.luminance() > 0.5F) = " +
158
- " ${navigationBarColor.luminance() > 0.5F } "
201
+ " Default (color.luminance() > 0.5F)"
159
202
else -> value.name
160
203
}
161
204
)
@@ -168,6 +211,134 @@ class MainActivity : AppCompatActivity() {
168
211
},
169
212
label = " navigationBarContrastEnforced"
170
213
)
214
+ PreferenceCategory (" BottomSheetBehaviorProperties" )
215
+ SingleChoicePreference (
216
+ value = state.name,
217
+ onValueChange = {
218
+ state = BottomSheetBehaviorProperties .State .valueOf(it)
219
+ },
220
+ label = " state" ,
221
+ options = BottomSheetBehaviorProperties .State .values().map { value ->
222
+ Pair (value.name, value.name)
223
+ }
224
+ )
225
+ IntPreference (
226
+ value = maxWidth.value,
227
+ onValueChange = {
228
+ maxWidth = BottomSheetBehaviorProperties .Size (it)
229
+ },
230
+ label = " maxWidth (px)" ,
231
+ helpText = " Default: not set (-1)" ,
232
+ description = { maxWidth ->
233
+ if (maxWidth == - 1 ) {
234
+ " not set (-1)"
235
+ } else {
236
+ " ${maxWidth} px"
237
+ }
238
+ },
239
+ validate = { maxWidth -> maxWidth == - 1 || maxWidth > 0 }
240
+ )
241
+ IntPreference (
242
+ value = maxHeight.value,
243
+ onValueChange = {
244
+ maxHeight = BottomSheetBehaviorProperties .Size (it)
245
+ },
246
+ label = " maxHeight (px)" ,
247
+ helpText = " Default: not set (-1)" ,
248
+ description = { maxHeight ->
249
+ if (maxHeight == - 1 ) {
250
+ " not set (-1)"
251
+ } else {
252
+ " ${maxHeight} px"
253
+ }
254
+ },
255
+ validate = { maxHeight -> maxHeight == - 1 || maxHeight > 0 }
256
+ )
257
+ BooleanPreference (
258
+ value = isDraggable,
259
+ onValueChange = {
260
+ isDraggable = it
261
+ },
262
+ label = " isDraggable"
263
+ )
264
+ IntPreference (
265
+ value = expandedOffset,
266
+ onValueChange = {
267
+ expandedOffset = it
268
+ },
269
+ label = " expandedOffset (px)" ,
270
+ helpText = " expandedOffset >= 0" ,
271
+ description = { expandedOffset ->
272
+ if (expandedOffset == 0 ) {
273
+ " Default (0)"
274
+ } else {
275
+ " ${expandedOffset} px"
276
+ }
277
+ },
278
+ validate = { expandedOffset -> expandedOffset >= 0 }
279
+ )
280
+ FloatPreference (
281
+ value = halfExpandedRatio,
282
+ onValueChange = {
283
+ halfExpandedRatio = it
284
+ },
285
+ label = " halfExpandedRatio" ,
286
+ helpText = " 0 < halfExpandedRatio < 1" ,
287
+ description = { halfExpandedRatio ->
288
+ if (halfExpandedRatio == 0.5F ) {
289
+ " Default (0.5)"
290
+ } else {
291
+ " $halfExpandedRatio "
292
+ }
293
+ },
294
+ validate = { halfExpandedRatio ->
295
+ 0 < halfExpandedRatio && halfExpandedRatio < 1
296
+ }
297
+ )
298
+ BooleanPreference (
299
+ value = isHideable,
300
+ onValueChange = {
301
+ isHideable = it
302
+ },
303
+ label = " isHideable"
304
+ )
305
+ IntPreference (
306
+ value = peekHeight.value,
307
+ onValueChange = {
308
+ peekHeight = BottomSheetBehaviorProperties .PeekHeight (it)
309
+ },
310
+ label = " peekHeight (px)" ,
311
+ helpText = " peekHeight > 0" ,
312
+ description = { peekHeight ->
313
+ if (peekHeight == - 1 ) {
314
+ " Auto (-1)"
315
+ } else {
316
+ " ${peekHeight} px"
317
+ }
318
+ },
319
+ validate = { peekHeight -> peekHeight == - 1 || peekHeight > 0 }
320
+ )
321
+ BooleanPreference (
322
+ value = isFitToContents,
323
+ onValueChange = {
324
+ isFitToContents = it
325
+ },
326
+ label = " isFitToContents"
327
+ )
328
+ BooleanPreference (
329
+ value = skipCollapsed,
330
+ onValueChange = {
331
+ skipCollapsed = it
332
+ },
333
+ label = " skipCollapsed"
334
+ )
335
+ BooleanPreference (
336
+ value = isGestureInsetBottomIgnored,
337
+ onValueChange = {
338
+ isGestureInsetBottomIgnored = it
339
+ },
340
+ label = " isGestureInsetBottomIgnored"
341
+ )
171
342
}
172
343
Button (
173
344
modifier = Modifier
0 commit comments