@@ -5,6 +5,9 @@ import android.content.Context
5
5
import android.graphics.Outline
6
6
import android.os.Build
7
7
import android.view.*
8
+ import androidx.annotation.FloatRange
9
+ import androidx.annotation.IntRange
10
+ import androidx.annotation.Px
8
11
import androidx.compose.runtime.*
9
12
import androidx.compose.runtime.saveable.rememberSaveable
10
13
import androidx.compose.ui.Modifier
@@ -25,14 +28,13 @@ import androidx.lifecycle.ViewTreeLifecycleOwner
25
28
import androidx.lifecycle.ViewTreeViewModelStoreOwner
26
29
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
27
30
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
28
- import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
29
- import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN
31
+ import com.google.android.material.bottomsheet.BottomSheetBehavior.*
30
32
import com.google.android.material.bottomsheet.BottomSheetDialog
31
33
import java.util.*
32
34
33
35
34
36
/* *
35
- * Properties used to customize the behavior of a [BottomSheetDialog].
37
+ * Properties used to customize [BottomSheetDialog].
36
38
*
37
39
* @property dismissOnBackPress whether the dialog can be dismissed by pressing the back button.
38
40
* If true, pressing the back button will call onDismissRequest.
@@ -49,7 +51,8 @@ class BottomSheetDialogProperties constructor(
49
51
val dismissOnClickOutside : Boolean = true ,
50
52
val dismissWithAnimation : Boolean = false ,
51
53
val securePolicy : SecureFlagPolicy = SecureFlagPolicy .Inherit ,
52
- val navigationBarProperties : NavigationBarProperties = NavigationBarProperties ()
54
+ val navigationBarProperties : NavigationBarProperties = NavigationBarProperties (),
55
+ val behaviorProperties : BottomSheetBehaviorProperties = BottomSheetBehaviorProperties ()
53
56
) {
54
57
55
58
@Deprecated(" Use NavigationBarProperties(color = navigationBarColor) instead" )
@@ -76,6 +79,7 @@ class BottomSheetDialogProperties constructor(
76
79
if (dismissWithAnimation != other.dismissWithAnimation) return false
77
80
if (securePolicy != other.securePolicy) return false
78
81
if (navigationBarProperties != other.navigationBarProperties) return false
82
+ if (behaviorProperties != other.behaviorProperties) return false
79
83
80
84
return true
81
85
}
@@ -86,10 +90,99 @@ class BottomSheetDialogProperties constructor(
86
90
result = 31 * result + dismissWithAnimation.hashCode()
87
91
result = 31 * result + securePolicy.hashCode()
88
92
result = 31 * result + navigationBarProperties.hashCode()
93
+ result = 31 * result + behaviorProperties.hashCode()
89
94
return result
90
95
}
91
96
}
92
97
98
+ /* *
99
+ * Properties used to set [com.google.android.material.bottomsheet.BottomSheetBehavior].
100
+ *
101
+ * @see [com.google.android.material.bottomsheet.BottomSheetBehavior]
102
+ */
103
+ @Immutable
104
+ class BottomSheetBehaviorProperties (
105
+ val state : BottomSheetDialogState = BottomSheetDialogState .Collapsed ,
106
+ val maxWidth : Size = Size .NotSet ,
107
+ val maxHeight : Size = Size .NotSet ,
108
+ val isDraggable : Boolean = true ,
109
+ @IntRange(from = 0 )
110
+ val expandedOffset : Int = 0 ,
111
+ @FloatRange(from = 0.0 , to = 1.0 , fromInclusive = false , toInclusive = false )
112
+ val halfExpandedRatio : Float = 0.5F ,
113
+ val isHideable : Boolean = true ,
114
+ val peekHeight : PeekHeight = PeekHeight .Auto ,
115
+ val isFitToContents : Boolean = true ,
116
+ val skipCollapsed : Boolean = false ,
117
+ val isGestureInsetBottomIgnored : Boolean = false
118
+ ) {
119
+ override fun equals (other : Any? ): Boolean {
120
+ if (this == = other) return true
121
+ if (other !is BottomSheetBehaviorProperties ) return false
122
+
123
+ if (state != other.state) return false
124
+ if (maxWidth != other.maxWidth) return false
125
+ if (maxHeight != other.maxHeight) return false
126
+ if (isDraggable != other.isDraggable) return false
127
+ if (expandedOffset != other.expandedOffset) return false
128
+ if (halfExpandedRatio != other.halfExpandedRatio) return false
129
+ if (isHideable != other.isHideable) return false
130
+ if (peekHeight != other.peekHeight) return false
131
+ if (isFitToContents != other.isFitToContents) return false
132
+ if (skipCollapsed != other.skipCollapsed) return false
133
+ if (isGestureInsetBottomIgnored != other.isGestureInsetBottomIgnored) return false
134
+
135
+ return true
136
+ }
137
+
138
+ override fun hashCode (): Int {
139
+ var result = state.hashCode()
140
+ result = 31 * result + maxWidth.hashCode()
141
+ result = 31 * result + maxHeight.hashCode()
142
+ result = 31 * result + isDraggable.hashCode()
143
+ result = 31 * result + expandedOffset.hashCode()
144
+ result = 31 * result + halfExpandedRatio.hashCode()
145
+ result = 31 * result + isHideable.hashCode()
146
+ result = 31 * result + peekHeight.hashCode()
147
+ result = 31 * result + isFitToContents.hashCode()
148
+ result = 31 * result + skipCollapsed.hashCode()
149
+ result = 31 * result + isGestureInsetBottomIgnored.hashCode()
150
+ return result
151
+ }
152
+
153
+ @Immutable
154
+ enum class BottomSheetDialogState {
155
+ @Stable
156
+ Expanded ,
157
+ @Stable
158
+ HalfExpanded ,
159
+ @Stable
160
+ Collapsed ,
161
+ @Stable
162
+ Hidden
163
+ }
164
+
165
+ @JvmInline
166
+ @Immutable
167
+ value class Size (@Px val value : Int ) {
168
+
169
+ companion object {
170
+ @Stable
171
+ val NotSet = Size (- 1 )
172
+ }
173
+ }
174
+
175
+ @JvmInline
176
+ @Stable
177
+ value class PeekHeight (val value : Int ) {
178
+
179
+ companion object {
180
+ @Stable
181
+ val Auto = PeekHeight (PEEK_HEIGHT_AUTO )
182
+ }
183
+ }
184
+ }
185
+
93
186
/* *
94
187
* Properties used to customize navigationBar.
95
188
@@ -391,6 +484,25 @@ private class BottomSheetDialogWrapper(
391
484
}
392
485
}
393
486
487
+ private fun setBehaviorProperties (behaviorProperties : BottomSheetBehaviorProperties ) {
488
+ this .behavior.state = when (behaviorProperties.state) {
489
+ BottomSheetBehaviorProperties .BottomSheetDialogState .Expanded -> STATE_EXPANDED
490
+ BottomSheetBehaviorProperties .BottomSheetDialogState .Collapsed -> STATE_COLLAPSED
491
+ BottomSheetBehaviorProperties .BottomSheetDialogState .HalfExpanded -> STATE_HALF_EXPANDED
492
+ BottomSheetBehaviorProperties .BottomSheetDialogState .Hidden -> STATE_HIDDEN
493
+ }
494
+ this .behavior.maxWidth = behaviorProperties.maxWidth.value
495
+ this .behavior.maxHeight = behaviorProperties.maxHeight.value
496
+ this .behavior.isDraggable = behaviorProperties.isDraggable
497
+ this .behavior.expandedOffset = behaviorProperties.expandedOffset
498
+ this .behavior.halfExpandedRatio = behaviorProperties.halfExpandedRatio
499
+ this .behavior.isHideable = behaviorProperties.isHideable
500
+ this .behavior.peekHeight = behaviorProperties.peekHeight.value
501
+ this .behavior.isFitToContents = behaviorProperties.isFitToContents
502
+ this .behavior.skipCollapsed = behaviorProperties.skipCollapsed
503
+ this .behavior.isGestureInsetBottomIgnored = behaviorProperties.isGestureInsetBottomIgnored
504
+ }
505
+
394
506
fun updateParameters (
395
507
onDismissRequest : () -> Unit ,
396
508
properties : BottomSheetDialogProperties ,
@@ -402,6 +514,7 @@ private class BottomSheetDialogWrapper(
402
514
setLayoutDirection(layoutDirection)
403
515
setCanceledOnTouchOutside(properties.dismissOnClickOutside)
404
516
setNavigationBarProperties(properties.navigationBarProperties)
517
+ setBehaviorProperties(properties.behaviorProperties)
405
518
dismissWithAnimation = properties.dismissWithAnimation
406
519
}
407
520
0 commit comments