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

Add Sharing Api #9253

Closed
wants to merge 20 commits into from
Closed

Add Sharing Api #9253

wants to merge 20 commits into from

Conversation

emmauss
Copy link
Contributor

@emmauss emmauss commented Oct 21, 2022

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

Breaking changes

Obsoletions / Deprecations

Fixed issues

@emmauss emmauss force-pushed the share branch 2 times, most recently from 8418526 to 0cf76f3 Compare October 21, 2022 09:25
@avaloniaui-team
Copy link
Contributor

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]

@kekekeks
Copy link
Member

  1. I believe the operation should be async
  2. Do we need the entire IStorageFile interface for sharing purposes? I suspect that only name, contents and may be MIME type are required

@kekekeks
Copy link
Member

@maxkatz6 do we want a separate interface or should the feature be exposed by IStorageProvider?

@emmauss
Copy link
Contributor Author

emmauss commented Oct 22, 2022

  1. I believe the operation should be async

  2. Do we need the entire IStorageFile interface for sharing purposes? I suspect that only name, contents and may be MIME type are required

  1. 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.
  2. 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.

@maxkatz6
Copy link
Member

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).

@maxkatz6
Copy link
Member

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:
#7234

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@avaloniaui-team
Copy link
Contributor

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]

@emmauss emmauss requested a review from a team January 31, 2023 20:49
@avaloniaui-team
Copy link
Contributor

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]

@maxkatz6
Copy link
Member

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.

@emmauss
Copy link
Contributor Author

emmauss commented Feb 22, 2023

Api now uses DataObjects. I've added helpers to store streams as DataObjects

@avaloniaui-team
Copy link
Contributor

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]

@jmacato
Copy link
Member

jmacato commented Nov 17, 2023

Closing this PR temporarily due to inactivity. Please ping me if this needs to be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants