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

Dialog is dismissed on screen touch #41178

Closed
audkar opened this issue Sep 24, 2019 · 8 comments · Fixed by #42253
Closed

Dialog is dismissed on screen touch #41178

audkar opened this issue Sep 24, 2019 · 8 comments · Fixed by #42253
Assignees
Labels
f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically
Milestone

Comments

@audkar
Copy link

audkar commented Sep 24, 2019

Flutter dialog are closed immediately on screen touch. Android native behavior is different. User can touch screen and swipe away to abort dialog dismissal. Problem becomes very visible when using flutter dialogs with android 10 gestural navigation

Native Android Flutter
dialog_dismiss_native dialog_dismiss_flutter

Steps to Reproduce

  1. Open dialog
  2. Press & hold screen, make swipe gesture
  3. Drag back to abort back navigation
  4. Observe: Dialog should not be dismissed
RaisedButton(
  child: Text("openDialog"),
  onPressed: () async => await showDialog(
    context: context,
    builder: (context) => SimpleDialog(
      children: <Widget>[Text("Some dialog")],
    ),
)),

Logs

[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Linux, locale en_US.UTF-8)
    • Flutter version 1.9.1+hotfix.2 at /home/audrius/Documents/flutter
    • Framework revision 2d2a1ffec9 (2 weeks ago), 2019-09-06 18:39:49 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/audrius/Documents/android-sdk-canary
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /home/audrius/Documents/android-sdk-canary
    • Java binary at:
      /home/audrius/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-1/191.5791312/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.
@janmoppel janmoppel added f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically platform-linux Building on or for Linux specifically labels Sep 24, 2019
@sroddy
Copy link
Contributor

sroddy commented Sep 24, 2019

This behavior is not consistent also w.r.t. iOS. There is not a single app (even Google ones) which dismisses modals on tap down.

This problem has been worsened even more after #36956. It's now impossible to dismiss modals if another gesture recognizer participates in the arena, as the _AnyTapGestureRecognizer immediately rejects the gesture on PointerUpEvent. I think it should be much better to use a recognizer that accepts anyTap (but not any tapDown).

cc @dkwingsmt, author of the PR

@stuartmorgan stuartmorgan removed the platform-linux Building on or for Linux specifically label Sep 24, 2019
@HansMuller HansMuller added the f: material design flutter/packages/flutter/material repository. label Sep 24, 2019
@dkwingsmt
Copy link
Contributor

dkwingsmt commented Sep 24, 2019

Sorry for causing the trouble.

@audkar Is this something new to Android 10? I've tested this on several apps on earlier Android versions and it seems to me that those dialogs are closed on tap down. (I don't have Android 10 devices to test on for now.) Are dialogs dismissed on tap up even when not competing with back navigation (for example, when gesture navigation is off), and are they still cancelable?

@sroddy Rejecting gestures is definitely a bug that I should fix. Thanks for bringing this up.
As for iOS dialogs, the only dismissable native dialog I can find is action sheets (corresponding to CupertinoActionSheet), and I can see that it's indeed dismissed on tap up instead of tap down. I'll fix it after I figure out how I'm supposed to deal with Android.

@dkwingsmt dkwingsmt self-assigned this Sep 24, 2019
@dkwingsmt dkwingsmt added this to the November 2019 milestone Sep 24, 2019
@audkar
Copy link
Author

audkar commented Sep 25, 2019

Is this something new to Android 10?

No. This not specific to Android 10 or gesture navigation. It happens on all Android versions

This is not true

@dkwingsmt
Copy link
Contributor

@audkar I built the following example that contains nothing but a dialog, and tested on a Pixel running Android 9. I confirm that the dialog is dismissed on tap down instead of tap up.

package com.example.testdialog

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

import kotlinx.android.synthetic.main.activity_main.*
import android.app.AlertDialog


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setSupportActionBar(toolbar)

        fab.setOnClickListener { _ ->
            showDialog()
        }
    }

    private fun showDialog() {
        val alertDialog = AlertDialog.Builder(this).create()
        alertDialog.setTitle("Alert")
        alertDialog.setMessage("Alert message to be shown")
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK") { dialog, _ ->
            dialog.dismiss()
        }
        alertDialog.show()
    }
}

Your experience of dismiss on tap up might be a result of gesture competence: when another gesture is competing with the modal barrier, the tap gesture won't claim victory until all other competitors leave the arena when pointer is up. With this conclusion I'll leave the Android behavior as tap down.

Nevertheless, the modal barrier should compete with the gesture navigator on Android 10, resulting in dismissing on tap up. I'll see if I can find a fix.

@audkar
Copy link
Author

audkar commented Sep 25, 2019

I confirm that the dialog is dismissed on tap down instead of tap up.

Seems that this behavior is different on android 10. I can reproduce that

  • Dialog is dismissed on tap down on Android 9
  • Dialog is dismissed on tap up on Android 10

dialog_dismiss_android_10

@dkwingsmt
Copy link
Contributor

@audkar Thank you very much. It's very important. Let me discuss with others and see how we handle this.

@MustafaYusef
Copy link

showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return alert;
},
);
for me set barrierDismissible :false solve the issue

@lock
Copy link

lock bot commented Apr 5, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants