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

fix(share): fix share button unresponsive on Overview for iOS and Android #967

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Uno.Gallery/Uno.Gallery.Shared/Controls/SamplePageLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Media;
using Windows.ApplicationModel.DataTransfer;


namespace Uno.Gallery
{
Expand Down Expand Up @@ -166,10 +168,22 @@ void OnScrolled(object sender, ScrollViewerViewChangedEventArgs e)

private void OnShareClicked(Hyperlink sender, HyperlinkClickEventArgs args)
{
#if (__IOS__ || __ANDROID__) && !NET6_0_OR_GREATER
var sample = DataContext as Sample;
_ = Deeplinking.BranchService.Instance.ShareSample(sample, _design);
#endif
if (DataTransferManager.IsSupported())
{
var dataTransferManager = DataTransferManagerHelper.GetForCurrentView();
dataTransferManager.DataRequested += DataRequested_URI;
DataTransferManagerHelper.ShowShareUI();
}
}

private void DataRequested_URI(DataTransferManager sender, DataRequestedEventArgs args)
{
args.Request.Data.Properties.Title = "Uno Gallery - Share-Sample Title";
args.Request.Data.Properties.Description = "See this awesome project:";

args.Request.Data.SetWebLink(new Uri("https://gallery.platform.uno/"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't share yhe sample I believe?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you say the sample... what do you mean?? what this does is shares the URL :/
what was the old behavior??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old behavior is that the shared link corresponds to a specific sample and design (fluent, material, cupertino, agnostic).

Opening the link should then open the app on the specific sample.

See my PR for the approach I took for this.


sender.DataRequested -= DataRequested_URI;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Windows.ApplicationModel.DataTransfer;
using WinRT.Interop;
using WinRT;

namespace Uno.Gallery.Helpers
{
public static class DataTransferManagerHelper
{
private static readonly Guid _dtm_iid = new Guid("a5caee9b-8708-49d1-8d36-67d25a8da00c");

#if WINDOWS
static IDataTransferManagerInterop DataTransferManagerInterop => DataTransferManager.As<IDataTransferManagerInterop>();
#endif

public static DataTransferManager GetForCurrentView()
{
#if WINDOWS
IntPtr result;
var hwnd = WindowNative.GetWindowHandle(App.Instance.MainWindow);
result = DataTransferManagerInterop.GetForWindow(hwnd, _dtm_iid);
DataTransferManager dataTransferManager = MarshalInterface<DataTransferManager>.FromAbi(result);
return (dataTransferManager);
#else
return DataTransferManager.GetForCurrentView();
#endif
}

public static void ShowShareUI(ShareUIOptions options = null)
{
#if WINDOWS
var hwnd = WindowNative.GetWindowHandle(App.Instance.MainWindow);
DataTransferManagerInterop.ShowShareUIForWindow(hwnd, options);
#else
DataTransferManager.ShowShareUI(options);
#endif
}

#if WINDOWS
[ComImport]
[Guid("3A3DCD6C-3EAB-43DC-BCDE-45671CE800C8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDataTransferManagerInterop
{
IntPtr GetForWindow([In] IntPtr appWindow, [In] ref Guid riid);
void ShowShareUIForWindow(IntPtr appWindow, ShareUIOptions options);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;
using WinRT;
using WinRT.Interop;
using Uno.Gallery.Helpers;

namespace Uno.Gallery.Views.Samples
{
Expand Down Expand Up @@ -133,47 +134,4 @@ private void DataRequested_TextLight(DataTransferManager sender, DataRequestedEv
sender.DataRequested -= DataRequested_TextLight;
}
}

public static class DataTransferManagerHelper
{
private static readonly Guid _dtm_iid = new Guid("a5caee9b-8708-49d1-8d36-67d25a8da00c");

#if WINDOWS
static IDataTransferManagerInterop DataTransferManagerInterop => DataTransferManager.As<IDataTransferManagerInterop>();
#endif

public static DataTransferManager GetForCurrentView()
{
#if WINDOWS
IntPtr result;
var hwnd = WindowNative.GetWindowHandle(App.Instance.MainWindow);
result = DataTransferManagerInterop.GetForWindow(hwnd, _dtm_iid);
DataTransferManager dataTransferManager = MarshalInterface<DataTransferManager>.FromAbi(result);
return (dataTransferManager);
#else
return DataTransferManager.GetForCurrentView();
#endif
}

public static void ShowShareUI(ShareUIOptions options = null)
{
#if WINDOWS
var hwnd = WindowNative.GetWindowHandle(App.Instance.MainWindow);
DataTransferManagerInterop.ShowShareUIForWindow(hwnd, options);
#else
DataTransferManager.ShowShareUI(options);
#endif
}

#if WINDOWS
[ComImport]
[Guid("3A3DCD6C-3EAB-43DC-BCDE-45671CE800C8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDataTransferManagerInterop
{
IntPtr GetForWindow([In] IntPtr appWindow, [In] ref Guid riid);
void ShowShareUIForWindow(IntPtr appWindow, ShareUIOptions options);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
Style="{StaticResource BodyMedium}">
<Run Text="You can" />

<Hyperlink x:Name="PART_ShareHyperlink">
<Hyperlink x:Name="PART_ShareHyperlink" >
<Run Text="share" />
</Hyperlink>

Expand Down