From 04feaca3facc4224de20fb814140c894557381c2 Mon Sep 17 00:00:00 2001 From: robloo Date: Thu, 8 Oct 2020 13:14:48 -0400 Subject: [PATCH] feat(dragdrop): Update iOS clipboard usage of DataPackage --- .../DataTransfer/Clipboard.iOS.cs | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Uno.UWP/ApplicationModel/DataTransfer/Clipboard.iOS.cs b/src/Uno.UWP/ApplicationModel/DataTransfer/Clipboard.iOS.cs index 1f3cc49e820f..33985ef31e56 100644 --- a/src/Uno.UWP/ApplicationModel/DataTransfer/Clipboard.iOS.cs +++ b/src/Uno.UWP/ApplicationModel/DataTransfer/Clipboard.iOS.cs @@ -1,7 +1,9 @@ #if __IOS__ +using System; using System.Threading.Tasks; using Foundation; using UIKit; +using Windows.UI.Core; namespace Windows.ApplicationModel.DataTransfer { @@ -11,18 +13,38 @@ public static partial class Clipboard public static void SetContent(DataPackage content) { - // Setting to null doesn't reset the clipboard like for Android - UIPasteboard.General.String = content?.Text ?? string.Empty; + if (content is null) + { + throw new ArgumentNullException(nameof(content)); + } + + CoreDispatcher.Main.RunAsync( + CoreDispatcherPriority.High, + async () => + { + var data = content?.GetView(); // Freezes the DataPackage + + if (data?.Contains(StandardDataFormats.Text) ?? false) + { + var text = await data.GetTextAsync(); + + // Setting to null doesn't reset the clipboard like for Android + UIPasteboard.General.String = text ?? string.Empty; + } + }); } public static DataPackageView GetContent() { - var dataPackageView = new DataPackageView(); - if (UIPasteboard.General.String != null) + var dataPackage = new DataPackage(); + + var clipText = UIPasteboard.General.String; + if (clipText != null) { - dataPackageView.SetFormatTask(StandardDataFormats.Text, Task.FromResult(UIPasteboard.General.String)); + dataPackage.SetText(clipText); } - return dataPackageView; + + return dataPackage.GetView(); } public static void Clear()