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

    Class OnboardingViewController

    Controller for managing onboarding views.

    This class provides methods to present, dismiss, and handle events for onboarding views created with the Onboarding Builder. Create instances using the createOnboardingView 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 createOnboardingView(onboarding);
      await view.setEventHandlers({ onClose: handleClose });

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

      Returns Promise<void>

      A promise that resolves when the onboarding is dismissed.

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

      AdaptyError if the view reference is invalid.

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

      const view = await createOnboardingView(onboarding);
      await view.present();
      // ... later
      await view.dismiss();
    • Presents the onboarding 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 onboarding is presented.

      Calling present on an already visible onboarding view will result in an error. The onboarding will be displayed with the configured presentation style on iOS. On Android, the onboarding 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, createOnboardingView } from '@adapty/capacitor';

      const onboarding = await adapty.getOnboarding({ placementId: 'YOUR_PLACEMENT_ID' });
      const view = await createOnboardingView(onboarding);
      await view.present();

      Present with page sheet style on iOS

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

      Parameters

      • eventHandlers: Partial<OnboardingEventHandlers> = {}

        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 createOnboardingView and provide standard closing behavior:

      • onClose - closes the onboarding when the close button is pressed or system back is used

      If you want to override the onClose listener, we strongly recommend returning true 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 { createOnboardingView } from '@adapty/capacitor';

      const view = await createOnboardingView(onboarding);

      const unsubscribe = await view.setEventHandlers({
      onClose: () => {
      console.log('Onboarding closed');
      // Return true to keep default closing behavior
      return true;
      },
      onActionPerformed: (action) => {
      console.log('Action performed:', action.name);
      },
      onProductSelected: (product) => {
      console.log('Product selected:', product.vendorProductId);
      }
      });

      await view.present();

      // Later, unsubscribe all handlers
      unsubscribe();