dotnet / dotnet/maui

[Enhancement] iOS: Add support for BarButtonItem to Share API to set position of presentation controller

Open
#3,813 1 comment 0 reactions 0 assignees View on GitHub
area-essentials proposal/open
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### Description

There's already a property `ShareRequestBase.PresentationSourceBounds` to set a `Rectangle` to give the presentation controller used by `UIActivityViewController` on iPads a hint where to anchor the displayed view. It's directly applied to `activityController.PopoverPresentationController.SourceRect`.

I suggest a API change/addition to be able to pass a `UIBarButtonItem` instead to the presentation controller as there's no good way to find the `SourceRect` for a bar button item.

Was a feature request as https://github.com/xamarin/Essentials/issues/1939

### Public API Changes

- Adds a new property `ShareRequestBase.PresentationOptions`
- Adds an interface `IPresentationOptions`
- Adds a shared class `SourceBoundsPresentationOptions`
- Adds a iOS class `UIBarButtonItemPresentationOptions`
- Changes behavior of `ShareRequestBase.PresentationSourceBounds` to be a projection of new `ShareRequestBase.PresentationOptions` property. One may deprecated this property completely.

```c#
public abstract class ShareRequestBase
{
// ...
public IPresentationOptions PresentationOptions { get; set; }
public Rectangle PresentationSourceBounds {
get
{
if(PresentationOptions is SourceBoundsPresentationOptions bounds)
{
return bounds.Bounds;
}
else
{
return Rectangle.Empty;
}
}
set => PresentationOptions = new SourceBoundsPresentationOptions(value);
}
}
public interface IPresentationOptions {}
public sealed class SourceBoundsPresentationOptions : IPresentationOptions
{
public SourceBoundsPresentationOptions(Rectangle bounds)
=> Bounds = bounds;
public Rectangle Bounds { get; }
}
public sealed class UIBarButtonItemPresentationOptions : IPresentationOptions
{
public UIBarButtonItemPresentationOptions(UIBarButtonItem barButtonItem)
=> BarButtonItem = barButtonItem;
public UIBarButtonItem BarButtonItem { get; set; }
}
```

### Intended Use-Case

There's no good way to find the `SourceRect` for a bar button item and though leverage the existing property `ShareRequestBase.PresentationSourceBounds`.

Contributor guide

Open the contributing guide

Research direction

Start with ShareRequestBase.PresentationSourceBounds and its use with UIActivityViewController.PopoverPresentationController.SourceRect. Review the proposed IPresentationOptions, SourceBoundsPresentationOptions, and UIBarButtonItemPresentationOptions API; done means preserving bounds behavior while allowing a UIBarButtonItem to position the iOS presentation controller.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, ios
Domain
api, mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.