Browse Source

Fix default radius not being set. Resolves #1909.

Aidan Follestad 5 years ago
parent
commit
df285c22a4

+ 4 - 1
core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt

@@ -445,7 +445,10 @@ class MaterialDialog(
       resolveColor(attr = R.attr.colorBackgroundFloating)
     }
     window?.setBackgroundDrawable(ColorDrawable(TRANSPARENT))
-    val cornerRadius = cornerRadius ?: resolveDimen(windowContext, attr = R.attr.md_corner_radius)
+    val cornerRadius =
+      cornerRadius ?: resolveDimen(windowContext, attr = R.attr.md_corner_radius) {
+        context.resources.getDimension(R.dimen.md_dialog_default_corner_radius)
+      }
     view.cornerRadius = cornerRadius
     dialogBehavior.setBackgroundColor(
         view = view,

+ 1 - 2
core/src/main/java/com/afollestad/materialdialogs/utils/Dimens.kt

@@ -21,13 +21,12 @@ import android.view.View
 import androidx.annotation.AttrRes
 import androidx.annotation.DimenRes
 import com.afollestad.materialdialogs.MaterialDialog
-import com.afollestad.materialdialogs.R
 import com.afollestad.materialdialogs.utils.MDUtil.assertOneSet
 
 internal fun MaterialDialog.dimen(
   @DimenRes res: Int? = null,
   @AttrRes attr: Int? = null,
-  fallback: Float = windowContext.resources.getDimension(R.dimen.md_dialog_default_corner_radius)
+  fallback: Float = 0f
 ): Float {
   assertOneSet("dimen", attr, res)
   if (res != null) {

+ 2 - 2
core/src/main/java/com/afollestad/materialdialogs/utils/MDUtil.kt

@@ -159,11 +159,11 @@ object MDUtil {
   @RestrictTo(LIBRARY_GROUP) fun resolveDimen(
     context: Context,
     @AttrRes attr: Int,
-    defaultValue: Float = 0f
+    defaultValue: (() -> Float)? = null
   ): Float {
     val a = context.theme.obtainStyledAttributes(intArrayOf(attr))
     try {
-      return a.getDimension(0, defaultValue)
+      return a.getDimension(0, defaultValue?.invoke() ?: 0f)
     } finally {
       a.recycle()
     }

+ 1 - 1
core/src/main/res/values/dimens.xml

@@ -2,7 +2,7 @@
 <resources>
 
   <dimen name="md_dialog_max_width">356dp</dimen>
-  <dimen name="md_dialog_default_corner_radius">2dp</dimen>
+  <dimen name="md_dialog_default_corner_radius">4dp</dimen>
   <dimen name="md_dialog_vertical_margin">52dp</dimen>
   <dimen name="md_dialog_horizontal_margin">32dp</dimen>