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

第2次show()的时候弹不出来 #1191

Open
actor20170211030627 opened this issue Dec 12, 2023 · 2 comments
Open

第2次show()的时候弹不出来 #1191

actor20170211030627 opened this issue Dec 12, 2023 · 2 comments

Comments

@actor20170211030627
Copy link

actor20170211030627 commented Dec 12, 2023

XPopup版本
2.10.0

手机系统和型号
Vivo X27, Android 10

描述你的问题

kotlin代码(没有缓存对象, 每次都new)

XPopup.Builder(activity)
    .atView(viewBinding.line)
    .isClickThrough(false)//是否点击弹窗背景时将点击事件透传到Activity下,默认是false
    .dismissOnTouchOutside(true)//点击外部消失
    .autoOpenSoftInput(false)//是否自动打开输入法,当弹窗包含输入框时很有用,默认为false
    .asCustom(GradeNormalView(activity, fragment,
        isShowWrongNum = true,
        isChangeGrade = true
    ) {
        model.gradeId = this.id
        getDatas(true)
    }.setGradeId(model.gradeId)).show()

GradeNormalView里有1个model对象:
private val model by activity.viewModels<GradeNormalDialogModel>()

model对象里有几个接口, 还有几个回调监听:

val changeGrade = MutableLiveData<Boolean>()
//
fun changeGrade(gradeId: String, onSuccess: () -> Unit) {
    viewModelScope.launch {
        update(
            api = {
                api.changeGrade(gradeId)
            },
            success = {
                changeGrade.value = true    //这种回调监听会导致第2次弹不出来
                //onSuccess()        //这种方式回调, 第2次才能正常弹出!!
            }
        )
    }
}
  1. 第1次show()正常.
    然后点击了里面的某一个item, 比如"司法", 然后在GradeNormalView里会调用model.changeGrade(gradeId)方法, 问题就出在这儿!
    调用以上接口后, 如果在GradeNormalView里这样监听:
model.changeGrade.observe(activity) {
    model.selectedGrade?.apply {
        listener(this)
    }
    dismiss()        //感觉这儿dismiss就会出问题
}

然后第2次就弹不起来了, 我也不知道是啥原因.

  1. 但是, 如果不使用上方的回调监听方式, 而是使用onSuccess()直接回调结果, 就不会出问题
@cgq-source
Copy link

我也遇到FullScreenPopupView在第二次show的时候概率性弹不出来的问题,换成BottomPopupView就不会出现这个问题
对应版本:com.github.li-xiaojun:XPopup:2.4.6

@billdizl
Copy link

implementation('com.github.billdizl:XPopup:2.10.4') 百万日活app验证无问题

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

3 participants