Sharing

Sharing opens the system share sheet. Its result follows React Native's share action and does not confirm that another app received the content on Android.

Import
import { Sharing } from '@ng-native/device';
Inject
inject(Sharing)
import { Component, inject } from '@angular/core';
import { Pressable, Text } from '@ng-native/components';
import { Sharing } from '@ng-native/device';

@Component({
  selector: 'app-article',
  imports: [Pressable, Text],
  template: `<pressable (press)="share()"><text>Share</text></pressable>`,
})
export class Article {
  private readonly sharing = inject(Sharing);

  protected async share(): Promise<void> {
    const shared = await this.sharing.share({
      url: 'https://example.com/article',
      title: 'Article',
    });
    if (shared) this.trackShare();
  }

  private trackShare(): void {}
}

share(request) takes a ShareRequest: message and/or url (iOS prefers url when both are present), and title, passed in React Native's share-content object; the wrapper does not expose the separate dialogTitle or subject options. At least one of message or url is required; a request with neither resolves to false without opening anything.

React Native's own Share module has no url field on Android - only title and message reach it there, and its own docs say Android's message "will often include a URL". Sharing folds url into message on Android before calling it, on a line of its own if there is a message already, so share({ url, title }) opens a sheet with something to actually share on both platforms rather than an empty body on Android.

Share.share resolves either way - dismissing the sheet is not an error - and share() collapses both the failure and the dismissal cases down to false, reserving true for sharedAction: the user picked a target app on iOS, or the sheet reported the action on Android. Neither platform confirms that the receiving app actually consumed the content, so treat true as "the user chose to share", not as delivery confirmation.

Off a device and on the web

Off a device share() always resolves to false, because there is no Share module underneath it. The Web Share API is the nearest browser equivalent, but Sharing does not call it; a web build wanting the same affordance should call navigator.share directly.

Reference

Sharingservice@ng-native/device
import { Sharing } from '@ng-native/device';

Methods

share(request: ShareRequest): Promise<boolean>

Open the share sheet. Resolves to whether anything took the content.

Angular components as native iOS and Android views, built and shipped with Expo.

An alpha. MIT licensed. Sponsor its development.

An independent project, not affiliated with or endorsed by Google, the Angular team or Expo. Angular is a trademark of Google LLC.