Git Product home page Git Product logo

Comments (9)

MihailsKuzmins avatar MihailsKuzmins commented on May 27, 2024 3

@Jeffcole1 cc @amtdev

Well I have a solution for this case. You will need to provide a custom clipboard service when adding services in MauiProgram.cs as it is shown down below:

builder.Services.AddMudMarkdownClipboardService<ClipboardService>();

// Implementation
public class ClipboardService : IMudMarkdownClipboardService
{
	public async ValueTask CopyToClipboardAsync(string text)
	{
		await Clipboard.Default.SetTextAsync(text)
			.ConfigureAwait(false);
	}
}

I will finalise the MR and make a new NuGet version a bit later today.

from mudblazor.markdown.

Jeffcole1 avatar Jeffcole1 commented on May 27, 2024 1

Link to sample repository: https://github.com/Jeffcole1/MudblazorMarkdownAndroidTest

Instructions to set up and run Android Emulator:

  1. In Visual Studio (I'm using Community 2022), ensure that the ".NET Multi-Platform App UI Development" workload is installed.
  2. With the solution open, select Tools -> Android -> Android Device Manager.
  3. Check that at least one virtual device is shown in the table. If there are none, click New. If there are any, skip to step 6.
  4. Give the virtual device a name and select a base device and Android API to use (I used Pixel 5 with Android 9.0 - API 28).
  5. Click Create to create the virtual device.
  6. The virtual device should appear in the table. Click the Start button to start the virtual device and ensure it runs properly.
  7. In Visual Studio, select the virtual device in the device list (next to the Configuration dropdowns), then click the Start button to start debugging. If you did it properly, the app should begin running in the virtual device. It may take a couple of minutes for the app to build and deploy to the virtual device.

from mudblazor.markdown.

MihailsKuzmins avatar MihailsKuzmins commented on May 27, 2024

It might be related to permissions as it is specified here: Interact with the clipboard. Could you try to run navigator.permissions.query({ name: "clipboard-write" }) directly and see what happens?

Alternatively, it might be a problem with the browser you used on mobile as it is stated here: Copy to clipboard is worked fine on PC but not works on Android device

and the same error occurred

By the way, what was the same error? Was null just printed in the browser console after you had executed the clipboard command directly?

from mudblazor.markdown.

Jeffcole1 avatar Jeffcole1 commented on May 27, 2024

I'm not using an actual browser. This is a .NET MAUI Blazor app written in Visual Studio and deployed to an Android emulator for testing. I used chrome://inspect#devices to open a dev tools page on the running app in the emulator.

When I click the copy button on the code block, this message appears:
blazorErrorMessage

Running the query command gave me a TypeError; polling the navigator.permissions property returned undefined, and polling navigator by itself returned this:
appClipboardWrite

For comparison, here is the message I got when I opened Chrome on the emulator and ran the same command:
chromeClipboardWrite

from mudblazor.markdown.

MihailsKuzmins avatar MihailsKuzmins commented on May 27, 2024

I see, so probably more work will be needed - like trying to create a workaround for this issue in the JS section of the code.
Something like

const element = document.createElement("textarea");
element.value = clipboardData;
document.body.appendChild(element)
element.select();
document.execCommand("copy");
document.body.removeChild(element);

But could you provide a sample solution where the error can be reproduced easily. I have neither MAUI nor android emulators installed on my PC, so it will take me some time to analyse this issue, sorry for trouble, but if it is possible could you provide a link to a GitHub repo where this issue can be reproduced?

Maybe some instructions about "deploying it to the Android enulator" would also come in handy

from mudblazor.markdown.

MihailsKuzmins avatar MihailsKuzmins commented on May 27, 2024

Thanks, I will try to take a look as soon as I can. It will take some time so please understand it 🙇

from mudblazor.markdown.

amtdev avatar amtdev commented on May 27, 2024

Thanks, I will try to take a look as soon as I can. It will take some time so please understand it 🙇

Any update on this? I am having the same issue.

from mudblazor.markdown.

MihailsKuzmins avatar MihailsKuzmins commented on May 27, 2024

@amtdev Sorry, not so much time I can devote to this project lately :(
Maybe this weekend I will have time...

from mudblazor.markdown.

MihailsKuzmins avatar MihailsKuzmins commented on May 27, 2024

@Jeffcole1 cc @amtdev

I've been working on this issue today and copying to clibboard in maui does not work as expected (well, it does not work even with document.execCommand('copy') which works in a browser, e.g. Chrome).
I have come across this issue - dotnet/maui#6846. Does it make sense to you?

I have only found out that it is possible to use the following in MainPage.cs, but I have no idea how to grant copy permissions in this callback. MAUI documentation (or the afore cited issue) does not provide any details how to do it. In any case I can try to open the same issue and hopefully someone will give an example how to do it.

blazorWebView.BlazorWebViewInitialized += BlazorWebView_BlazorWebViewInitialized;

from mudblazor.markdown.

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.