@adapty/capacitor - v3.12.0-beta.1
    Preparing search index...

    Class PaywallViewController

    Controller for managing paywall views.

    This class provides methods to present, dismiss, and handle events for paywall views created with the Paywall Builder. Create instances using the createPaywallView function rather than directly constructing this class.

    Index

    Methods

    • Clears all registered event handlers.

      Returns void

      This method removes all previously registered event handlers. After calling this method, no event handlers will be active until you call setEventHandlers again.

      Use this after dismiss to remove all event handlers

      const view = await createPaywallView(paywall);
      await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });

      // Later, clear all handlers
      view.clearEventHandlers();
    • Dismisses the paywall view.

      Returns Promise<void>

      A promise that resolves when the paywall is dismissed.

      This method closes the paywall and cleans up associated resources. After dismissing, the view controller instance cannot be reused.

      AdaptyError if the view reference is invalid.

      import { createPaywallView } from '@adapty/capacitor';

      const view = await createPaywallView(paywall);
      await view.present();
      // ... later
      await view.dismiss();
    • Presents the paywall view as a modal screen.

      Parameters

      • options: { iosPresentationStyle?: AdaptyIOSPresentationStyle } = {}

        Optional presentation options

        • OptionaliosPresentationStyle?: AdaptyIOSPresentationStyle

          iOS presentation style. Available options: 'full_screen' (default) or 'page_sheet'. Only affects iOS platform.

      Returns Promise<void>

      A promise that resolves when the paywall is presented.

      Calling present on an already visible paywall view will result in an error. The paywall will be displayed with the configured presentation style on iOS. On Android, the paywall is always presented as a full-screen activity.

      AdaptyError if the view reference is invalid or the view is already presented.

      Present with default full-screen style

      import { adapty, createPaywallView } from '@adapty/capacitor';

      const paywall = await adapty.getPaywall({ placementId: 'YOUR_PLACEMENT_ID' });
      const view = await createPaywallView(paywall);
      await view.present();

      Present with page sheet style on iOS

      await view.present({ iosPresentationStyle: 'page_sheet' });
      
    • Registers event handlers for paywall UI events.

      Parameters

      • eventHandlers: Partial<EventHandlers> = {}

        Set of event handling callbacks. Only provided handlers will be registered or updated.

      Returns Promise<() => void>

      A promise that resolves to an unsubscribe function that removes all registered listeners.

      Each event type can have only one handler — new handlers replace existing ones. Default handlers are registered automatically in createPaywallView and provide standard closing behavior:

      • onCloseButtonPress - closes the paywall
      • onAndroidSystemBack - closes the paywall (Android only)
      • onRestoreCompleted - closes the paywall after successful restore
      • onPurchaseCompleted - closes the paywall after successful purchase

      If you want to override these listeners, we strongly recommend returning true (or purchaseResult.type !== 'user_cancelled' in case of onPurchaseCompleted) from your custom listener to retain default closing behavior.

      Calling this method multiple times will replace previously registered handlers for provided events.

      Register custom event handlers

      import { createPaywallView } from '@adapty/capacitor';

      const view = await createPaywallView(paywall);

      const unsubscribe = await view.setEventHandlers({
      onPurchaseStarted: (product) => {
      console.log('Purchase started:', product.vendorProductId);
      },
      onPurchaseCompleted: (result) => {
      console.log('Purchase completed:', result.type);
      // Return true to keep default closing behavior
      return result.type !== 'user_cancelled';
      },
      onPurchaseFailed: (error) => {
      console.error('Purchase failed:', error);
      }
      });

      await view.present();

      // Later, unsubscribe all handlers
      unsubscribe();
    • Displays a dialog to the user.

      Parameters

      • config: AdaptyUiDialogConfig

        Configuration for the dialog.

        • Optionalcontent?: string

          Descriptive text that provides additional details about the reason for the dialog.

        • primaryActionTitle: string

          The action title to display as part of the dialog. If you provide two actions, be sure primaryAction cancels the operation and leaves things unchanged.

        • OptionalsecondaryActionTitle?: string

          The secondary action title to display as part of the dialog.

        • Optionaltitle?: string

          The title of the dialog.

      Returns Promise<AdaptyUiDialogActionType>

      A promise that resolves to the action type that the user selected: 'primary' or 'secondary'.

      Use this method to show custom dialogs within the paywall flow. If you provide two actions in the config, the primary action should cancel the operation and leave things unchanged, while the secondary action should confirm the operation.

      AdaptyError if the view reference is invalid.

      Show confirmation dialog

      const action = await view.showDialog({
      title: 'Confirm Purchase',
      content: 'Are you sure you want to proceed with this purchase?',
      primaryActionTitle: 'Cancel',
      secondaryActionTitle: 'Continue'
      });

      if (action === 'secondary') {
      console.log('User confirmed');
      }