Coder Social home page Coder Social logo

页面里面返回键会触发显示是否操作的弹窗,发现有一定的几率弹窗显示后会自动关闭 about xpopup HOT 2 OPEN

zhuzhao404 avatar zhuzhao404 commented on September 16, 2024
页面里面返回键会触发显示是否操作的弹窗,发现有一定的几率弹窗显示后会自动关闭

from xpopup.

Comments (2)

zhuzhao404 avatar zhuzhao404 commented on September 16, 2024

经我多次测试,如果这个弹窗显示是由系统的back键触发显示的就会偶发这种现象下面我会贴出代码和日志:
class MainActivity : AppCompatActivity() {
lateinit var textView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    textView = findViewById<TextView>(R.id.textView);
    textView.setOnClickListener {
        testDialog("onClickAction")
    }
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        testDialog("onKeyDownBackAction")
        return true
    }
    return super.onKeyDown(keyCode, event)
}

private fun testDialog(action: String) {
    val clickTime = Date().time
    val xPopup = XPopup.Builder(this).isDestroyOnDismiss(true)
        .setPopupCallback(object : SimpleCallback() {
            override fun onDismiss(popupView: BasePopupView?) {
                val dismissTime = Date().time
                Log.e(action, "onDismiss: ${dismissTime - clickTime}")
            }
        }).asConfirm("Confirm", "Are you sure to exit?") {

        }.setConfirmText("OK").setCancelText("Cancel")
    xPopup.show()
    textView.postDelayed({
        if (xPopup.isShow) {
            xPopup.dismiss()
        }
    }, 500)
}

}

image
可以看到keydownbackaction日志从显示到消失的时间很短,那么也就是触发自动关闭了

from xpopup.

zhuzhao404 avatar zhuzhao404 commented on September 16, 2024

#929
之前也有人提过这个问题

from xpopup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.