-
Notifications
You must be signed in to change notification settings - Fork 10
Lab 7: Web Share API
The Web Share API is a relatively new addition to the web platform. It’s a draft specification allowing to share objects using a native share dialog. Hence, Chrome for Android is the only browser supporting it. But following the principle of progressive enhancements, in this lab we will also enable other browsers and platforms to enable sharing (in an old-school way 😉).
Please run the following commands on your command line, e.g. in the root ngeurope-2018-pwa
root folder:
$ git reset --hard
$ git clean -df
$ git checkout workshop/lab7
In the demo application, navigate to the Features page. Find Web Share API in the list. If the toggle switch is activated, your browser supports this feature. Isn't this a cool page?
Let’s implement the principle of Progressive Enhancement. Extend the ShareService
(client/src/modules/shared/services/share.service.ts
) by implementing the following logic in the share
method:
- Use the
FeatureService
to detect if the Web Share APIBrowserFeatureKey.WebShareAPI
is available. - If Web Share API is available, call the
_share
method. - Otherwise, call the
_sendMail
method.
Implement the _share
method. The Web Share API is triggered by calling navigator.share
. You might refer to this Web Share API documentation.
Click the sharing button next to a to-do item.
On a device with support for Web Share API, the native share dialog should come up.
On a device lacking support for Web Share API, an email dialog should come up instead.