Avalonia
Avalonia copied to clipboard
Add Sharing Api
What does the pull request do?
Add sharing api and support for the following platforms; Web and Android
public interface IShare
{
/// <summary>
/// Shares text using platform's sharing feature
/// </summary>
/// <param name="text">The text string to be shared</param>
void Share(string text);
/// <summary>
/// Shares a file using platform's sharing feature
/// </summary>
/// <param name="file">The storage file <see cref="IStorageFile"/> to be shared</param>
void Share(IStorageFile file);
/// <summary>
/// Shares a list of files using platform's sharing feature
/// </summary>
/// <param name="files">The list of storage files <see cref="IStorageFile"/> to be shared</param>
void Share(IList<IStorageFile> files);
}
The api is accessed using the TopLevel.
public void Share(TopLevel parent)
{
parent.Share?.Share("Hello");
}
What is the current behavior?
What is the updated/expected behavior with this PR?
How was the solution implemented (if it's not obvious)?
Checklist
- [ ] Added unit tests (if possible)?
- [x] Added XML documentation to any related classes?
- [ ] Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with user documentation
Breaking changes
Obsoletions / Deprecations
Fixed issues
You can test this PR using the following package version. 11.0.999-cibuild0025158-beta
. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]
- I believe the operation should be async
- Do we need the entire IStorageFile interface for sharing purposes? I suspect that only name, contents and may be MIME type are required
@maxkatz6 do we want a separate interface or should the feature be exposed by IStorageProvider?
I believe the operation should be async
Do we need the entire IStorageFile interface for sharing purposes? I suspect that only name, contents and may be MIME type are required
- There may be an issue on Web, if the api is async. Navigator only allows sharing if the action is spawned by a user gesture. Moreover, the api on respective platforms do not expect a response to client, and is non blocking.
- For android, the uri is needed. For web, the original file handle provided by the file dialog is required. We can't use just the file path on web.
There may be an issue on Web, if the api is async. Navigator only allows sharing if the action is spawned by a user gesture.
Yes, but you still can have async API. Operation needs to be initiated on a user gesture. There is no difference if somewhere else it is awaited.
@maxkatz6 do we want a separate interface or should the feature be exposed by IStorageProvider
I don't have a strong opinion here. If can be in separated interface. But probably naming should be adjusted to be consistent. Like "IShareProvider" I guess.
Do we need the entire IStorageFile interface for sharing purposes? I suspect that only name, contents and may be MIME type are required For android, the uri is needed. For web, the original file handle provided by the file dialog is required. We can't use just the file path on web.
It is limiting as only allows to share physically existing file. I am pretty sure these platforms support sharing a stream of data (needs to be double checked).
Use case, app generates a 2GB data stream of a videl and user wants to share it to another application. Saving to a physical file and then sharing would be consuming (and problematic on web).
Stream based sharing API also aligns with our plans to have a fallback solution, when "save file picker" is not available on system (iOS and non-Chrome Browser).
See Task Export(FilePickerOptions options, Func<Stream, FilePickerFileType, Task> writer);
part:
https://github.com/AvaloniaUI/Avalonia/issues/7234
You can test this PR using the following package version. 11.0.999-cibuild0025246-beta
. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0025290-beta
. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0026619-beta
. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0027138-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-nightly/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0027235-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-nightly/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0027859-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0027920-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0028056-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0028594-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0029284-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.0.999-cibuild0030232-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
I am thinking about API like:
public interface IShareProvider
{
Task<bool> CanShareAsync(IDataObject dataObject);
Task ShareAsync(string title, IDataObject dataObject);
}
where IDataObject supports text, files and binary inputs (right now in master it's only text and files officially). With couple of extension methods, which would create IDataObject from text input and storage file input, which can be resued on all platforms.
Also, same API can be done for Windows as well. I need to take a look at this PR at some point and check how we can share a stream, possibly using a service worker.
Api now uses DataObjects. I've added helpers to store streams as DataObjects
You can test this PR using the following package version. 11.0.999-cibuild0030414-beta
. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]
Closing this PR temporarily due to inactivity. Please ping me if this needs to be reopened.