Browse Source

Add fluent cancelable and cancelOnTouchOutside, resolves #1590

Aidan Follestad 6 years ago
parent
commit
ec474e01e6
2 changed files with 24 additions and 0 deletions
  1. 12 0
      README.md
  2. 12 0
      core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt

+ 12 - 0
README.md

@@ -250,6 +250,18 @@ val dialog: MaterialDialog = // ...
 dialog.dismiss()
 ```
 
+---
+
+You can prevent a dialog from being canceled, meaning it has to be explictly dismissed with an 
+action button or a call to the method above.
+
+```kotlin
+MaterialDialog(this).show {
+  cancelable(false)  // calls setCancelable on the underlying dialog
+  cancelOnTouchOutside(false)  // calls setCanceledOnTouchOutside on the underlying dialog
+}
+```
+
 ## Lists
 
 ### Plain

+ 12 - 0
core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt

@@ -288,6 +288,18 @@ class MaterialDialog(
     return this
   }
 
+  /** A fluent version of [setCancelable]. */
+  fun cancelable(cancelable: Boolean): MaterialDialog {
+    this.setCancelable(cancelable)
+    return this
+  }
+
+  /** A fluent version of [setCanceledOnTouchOutside]. */
+  fun cancelOnTouchOutside(cancelable: Boolean): MaterialDialog {
+    this.setCanceledOnTouchOutside(cancelable)
+    return this
+  }
+
   override fun dismiss() {
     hideKeyboard()
     super.dismiss()