Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancelable #5

Open
crm76 opened this issue Jul 12, 2018 · 1 comment
Open

Cancelable #5

crm76 opened this issue Jul 12, 2018 · 1 comment

Comments

@crm76
Copy link

crm76 commented Jul 12, 2018

It would be nice to control if it's cancelable. For my needs, I quickly changed show() to return the DialogFragment so I could set isCancelable like so...

val alert = AlertView("Title", "Message", AlertStyle.DIALOG)
var dialog = alert.show(this)
dialog.isCancelable = false


fun show(activity: AppCompatActivity) : android.support.v4.app.DialogFragment {
    var result : android.support.v4.app.DialogFragment

    when (style) {
        AlertStyle.BOTTOM_SHEET -> {
            val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            result = bottomSheet
        }
        AlertStyle.IOS -> {
            val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            result = bottomSheet
        }
        AlertStyle.DIALOG -> {
            val bottomSheet = DialogFragment(title, message, actions, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            result = bottomSheet
        }
    }
    
    return result
}

Thank you for the project.

@om79
Copy link

om79 commented Jun 11, 2019

You can simply set cancelable:

fun show(activity: AppCompatActivity, cancelable:Boolean) {
when (style) {
AlertStyle.BOTTOM_SHEET -> {
val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
bottomSheet.isCancelable=cancelable

        }
        AlertStyle.IOS -> {
            val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            bottomSheet.isCancelable=cancelable
        }
        AlertStyle.DIALOG -> {
            val bottomSheet = DialogFragment(title, message, actions, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            bottomSheet.isCancelable=cancelable
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants