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

Provide a dialog option to make dialog text selectable #8731

Open
SpurguX opened this issue Jul 24, 2020 · 4 comments
Open

Provide a dialog option to make dialog text selectable #8731

SpurguX opened this issue Jul 24, 2020 · 4 comments

Comments

@SpurguX
Copy link
Contributor

SpurguX commented Jul 24, 2020

Is your feature request related to a problem? Please describe.

I would like the user to be able to select and copy the text shown in an alert dialog message.

Describe the solution you'd like

Provide an additional dialog option for dialog functions, e.g. the alert function, such as textIsSelectable.

Additional context

I'm developing on Android so I'm uncertain whether this is an issue on iOS.

@Ross-Olivares
Copy link

Ross-Olivares commented Jul 27, 2020

Hi @SpurguX
Thank you for reporting this.
We are going to review the case and see what can be the possible solution.

@Ross-Olivares
Copy link

Ross-Olivares commented Jul 31, 2020

Hi @SpurguX
Can you try this by having a custom view in the dialog, for the reference you can take a look here: https://stackoverflow.com/questions/7197939/copy-text-from-android-alertdialog
Let me know how it goes.

@SpurguX
Copy link
Contributor Author

SpurguX commented Aug 6, 2020

I'll give it a try when I find a suitable moment

@SpurguX
Copy link
Contributor Author

SpurguX commented Aug 14, 2020

So I could accomplish what I wanted my modifying the function createAlertDialog in dialogs.android.js:

function createAlertDialog(options) {
    var alert = new android.app.AlertDialog.Builder(application_1.android.foregroundActivity);
    var alertMessage = options && isString(options.message) ? options.message : ""

    if (options && options.textIsSelectable === true) {
        const textView = new android.widget.TextView(application_1.android.foregroundActivity);
        textView.setTextIsSelectable(true);
        textView.setText(alertMessage)
        textView.setPadding(50, 20, 50, 20)
        textView.setTextSize(16)
        textView.setTextColor(android.graphics.Color.BLACK)
        alert.setView(textView)
    } else {
        alert.setMessage(alertMessage);
    }
    alert.setTitle(options && isString(options.title) ? options.title : "");

    if (options && options.cancelable === false) {
        alert.setCancelable(false);
    }
    return alert;
  }

So now I can call alert like so to get a dialog with selectable text:

alert({
      title: 'Test',
      message: 'Lorem impsum.',
      okButtonText: 'OK',
      textIsSelectable: true,
 })

And the end result looks identical to a regular call:

alert({
      title: 'Test',
      message: 'Lorem impsum.',
      okButtonText: 'OK',
})

Not the most versatile solution, what with the hard coded values, but it gets the job done in my case. It would require some more effort to come up with a good solution for submitting a PR...

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