Skip to content

Commit 051d683

Browse files
committed
Fix up rounded to respect daynight
1 parent 691ec10 commit 051d683

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

modalbottomsheetdialogfragment/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
compileSdkVersion 32
77

88
defaultConfig {
9-
minSdkVersion 16
9+
minSdkVersion 21
1010
targetSdkVersion 32
1111
versionCode 1
1212
versionName "1.0"

modalbottomsheetdialogfragment/src/main/java/com/commit451/modalbottomsheetdialogfragment/ModalBottomSheetDialogFragment.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
5656
MenuInflater(context)
5757
}
5858

59-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
59+
override fun onCreateView(
60+
inflater: LayoutInflater,
61+
container: ViewGroup?,
62+
savedInstanceState: Bundle?
63+
): View? {
6064
return inflater.inflate(R.layout.modal_bottom_sheet_dialog_fragment, container, false)
6165
}
6266

@@ -65,8 +69,10 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
6569
val arguments = arguments
6670
?: throw IllegalStateException("You need to create this via the builder")
6771
val isRounded = arguments.getBoolean(KEY_ROUNDED)
68-
if (isRounded){
69-
setStyle(STYLE_NORMAL, R.style.RoundedBottomSheetDialogTheme)
72+
if (isRounded) {
73+
setStyle(STYLE_NORMAL, R.style.ModalBottomSheetDialogThemeRounded)
74+
} else {
75+
setStyle(STYLE_NORMAL, R.style.ModalBottomSheetDialogTheme)
7076
}
7177
}
7278

@@ -75,7 +81,7 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
7581
super.onViewCreated(view, savedInstanceState)
7682
list = view.findViewById(R.id.list)
7783
val arguments = arguments
78-
?: throw IllegalStateException("You need to create this via the builder")
84+
?: throw IllegalStateException("You need to create this via the builder")
7985

8086
val optionHolders = arguments.getParcelableArrayList<OptionHolder>(KEY_OPTIONS)!!
8187

@@ -150,6 +156,7 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
150156
class Builder {
151157

152158
internal var options = ArrayList<OptionHolder>()
159+
153160
@LayoutRes
154161
internal var layoutRes = R.layout.modal_bottom_sheet_dialog_fragment_item
155162
internal var columns = 1
@@ -194,7 +201,10 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
194201
/**
195202
* Add a custom header to the modal, using the custom layout if provided
196203
*/
197-
fun header(header: String, @LayoutRes layoutRes: Int = R.layout.modal_bottom_sheet_dialog_fragment_header): Builder {
204+
fun header(
205+
header: String,
206+
@LayoutRes layoutRes: Int = R.layout.modal_bottom_sheet_dialog_fragment_header
207+
): Builder {
198208
this.header = header
199209
this.headerLayoutRes = layoutRes
200210
return this
@@ -203,7 +213,7 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
203213
/*
204214
* Set rounded on top bottom sheet dialog
205215
*/
206-
fun rounded(isRounded: Boolean): Builder{
216+
fun rounded(isRounded: Boolean): Builder {
207217
this.isRounded = isRounded
208218
return this
209219
}
@@ -235,7 +245,8 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
235245
fun onModalOptionSelected(tag: String?, option: Option)
236246
}
237247

238-
internal class Adapter(private val callback: (option: Option) -> Unit) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
248+
internal class Adapter(private val callback: (option: Option) -> Unit) :
249+
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
239250

240251
companion object {
241252
const val VIEW_TYPE_HEADER = 0
@@ -252,7 +263,8 @@ class ModalBottomSheetDialogFragment : BottomSheetDialogFragment() {
252263
when (viewType) {
253264

254265
VIEW_TYPE_HEADER -> {
255-
val view = LayoutInflater.from(parent.context).inflate(headerLayoutRes, parent, false)
266+
val view =
267+
LayoutInflater.from(parent.context).inflate(headerLayoutRes, parent, false)
256268
return HeaderViewHolder(view)
257269
}
258270
VIEW_TYPE_ITEM -> {

modalbottomsheetdialogfragment/src/main/res/drawable/rounded.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<corners
55
android:topLeftRadius="16dp"
66
android:topRightRadius="16dp"/>
7-
<solid android:color="@android:color/white"/>
7+
<solid android:color="?android:attr/colorBackground"/>
88

99
</shape>
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<style name="RoundedBottomSheetDialogTheme"
4-
parent="Theme.Design.Light.BottomSheetDialog">
5-
<item name="bottomSheetStyle">@style/RedoundedModalStyle</item>
3+
4+
<style name="ModalBottomSheetDialogTheme" parent="Theme.Material3.DayNight.BottomSheetDialog"/>
5+
6+
<style name="ModalBottomSheetDialogThemeRounded" parent="Theme.Material3.DayNight.BottomSheetDialog">
7+
<item name="bottomSheetStyle">@style/RoundedModalStyle</item>
68
</style>
79

8-
<style name="RedoundedModalStyle" parent="Widget.Design.BottomSheet.Modal">
10+
<style name="RoundedModalStyle" parent="Widget.Material3.BottomSheet.Modal">
911
<item name="android:background">@drawable/rounded</item>
1012
</style>
1113
</resources>

0 commit comments

Comments
 (0)