Skip to content

Commit

Permalink
Merge branch 'dotnet:main' into lytico/gtk-ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
lytico authored Apr 11, 2024
2 parents 5fcf6a4 + 01e72e2 commit aab9469
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .github/policies/resourceManagement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,15 @@ configuration:
- removeLabel:
label: s/try-latest-version
description: Remove 's/try-latest-version' when new reply from author comes in
- if:
- payloadType: Issues
- activitySenderHasPermission:
permission: Write
- isAction:
action: Opened
then:
- addLabel:
label: s/triaged
description: Add 's/triaged' label to issues opened by the core team, we assume these issues do not need triaging
onFailure:
onSuccess:
2 changes: 2 additions & 0 deletions src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static class MauiProgram
public static MauiApp CreateMauiApp() =>
MauiApp
.CreateBuilder()
#if __ANDROID__ || __IOS__
.UseMauiMaps()
#endif
.UseMauiApp<App>()
.Build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<views:BasePage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.DropFileToMauiApp"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base">
<views:BasePage.Resources>
</views:BasePage.Resources>
<Grid x:Name="myLayout">
<Grid.GestureRecognizers>
<DropGestureRecognizer AllowDrop="True" DragOver="DropGestureDragOver" Drop="DropGestureDrop" DragLeave="DropGestureDragLeave"/>
</Grid.GestureRecognizers>
<Label x:Name="lblPath" HorizontalOptions="Center" VerticalOptions="Center" Text="Drag a file here like a .txt" />
</Grid>
</views:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

#if WINDOWS
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
#endif

#if IOS || MACCATALYST
using UIKit;
using Foundation;
#endif

namespace Maui.Controls.Sample.Pages
{
public partial class DropFileToMauiApp
{

public DropFileToMauiApp()
{
InitializeComponent();
}

void DropGestureDragLeave(object? sender, DragEventArgs e)
{

}

async void DropGestureDrop(object? sender, DropEventArgs e)
{
var filePaths = new List<string>();

#if WINDOWS
if (e.PlatformArgs is not null && e.PlatformArgs.DragEventArgs.DataView.Contains(StandardDataFormats.StorageItems))
{
var items = await e.PlatformArgs.DragEventArgs.DataView.GetStorageItemsAsync();
if (items.Any())
{
foreach (var item in items)
{
if (item is StorageFile file)
{
filePaths.Add(item.Path);
}
}

}
}
#elif MACCATALYST

var session = e.PlatformArgs?.DropSession;
if (session == null)
{
return;
}
foreach (UIDragItem item in session.Items)
{
var result = await LoadItemAsync(item.ItemProvider, item.ItemProvider.RegisteredTypeIdentifiers.ToList());
if (result is not null)
{
filePaths.Add(result.FileUrl?.Path!);
}
}
foreach (var item in filePaths)
{
Debug.WriteLine($"Path: {item}");
}

static async Task<LoadInPlaceResult?> LoadItemAsync(NSItemProvider itemProvider, List<string> typeIdentifiers)
{
if (typeIdentifiers is null || typeIdentifiers.Count == 0)
{
return null;
}

var typeIdent = typeIdentifiers.First();

if (itemProvider.HasItemConformingTo(typeIdent))
{
return await itemProvider.LoadInPlaceFileRepresentationAsync(typeIdent);
}

typeIdentifiers.Remove(typeIdent);

return await LoadItemAsync(itemProvider, typeIdentifiers);
}
#else
await Task.CompletedTask;
#endif

lblPath.Text = filePaths.FirstOrDefault();
}

void DropGestureDragOver(object? sender, DragEventArgs e)
{
Debug.WriteLine($"Dragging {e.Data?.Text}, {e.Data?.Image}");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
{
new SectionModel(typeof(DragAndDropBetweenLayouts), "Drag And Drop",
"Drag and Drop Views."),
new SectionModel(typeof(DropFileToMauiApp), "Drag and Drop file from OS",
"Drop File to App"),
new SectionModel(typeof(PanGestureGallery), "Pan Gesture",
"Pan Gesture."),
new SectionModel(typeof(PinchGestureTestPage), "Pinch Gesture",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ void HandleDrop(object sender, Microsoft.UI.Xaml.DragEventArgs e)
element = ve;
}

if (datapackage is null)
return;

var args = new DropEventArgs(datapackage.View, (relativeTo) => GetPosition(relativeTo, e), new PlatformDropEventArgs(sender as UIElement, e));
var args = new DropEventArgs(datapackage?.View, (relativeTo) => GetPosition(relativeTo, e), new PlatformDropEventArgs(sender as UIElement, e));
SendEventArgs<DropGestureRecognizer>(async rec =>
{
if (!rec.AllowDrop)
Expand Down
13 changes: 6 additions & 7 deletions src/Controls/src/Core/Platform/iOS/DragAndDropDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSes
{
UIDropOperation operation = UIDropOperation.Cancel;

if (session.LocalDragSession == null)
return new UIDropProposal(operation);

DataPackage package = null;

if (session.LocalDragSession.Items.Length > 0 &&
session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi)
if (session.LocalDragSession != null)
{
package = cdi.DataPackage;
if (session.LocalDragSession.Items.Length > 0 &&
session.LocalDragSession.Items[0].LocalObject is CustomLocalStateData cdi)
{
package = cdi.DataPackage;
}
}

var platformArgs = new PlatformDragEventArgs(_viewHandler.PlatformView, interaction, session);
Expand Down

0 comments on commit aab9469

Please sign in to comment.