@adapty/capacitor - v4.0.1-beta.1
    Preparing search index...

    Class FlowViewController

    Controller for managing flow views.

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

    Index

    Properties

    locale?: string

    The localization the view was actually built with.

    May differ from the requested localization if it is not available in the flow.

    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 createFlowView(flow);
      await view.setEventHandlers({ onPurchaseCompleted: handlePurchase });

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

      Returns Promise<void>

      A promise that resolves when the flow is dismissed.

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

      AdaptyError if the view reference is invalid.

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

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

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

      const flow = await adapty.getFlow({ placementId: 'YOUR_PLACEMENT_ID' });
      const view = await createFlowView(flow);
      await view.present();

      Present with page sheet style on iOS

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

      Parameters

      • eventHandlers: Partial<FlowEventHandlers> = {}

        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 createFlowView (see DEFAULT_FLOW_EVENT_HANDLERS). Only two defaults close the view; all others keep it open:

      • onCloseButtonPress - closes the view (returns true)
      • onError - closes the view (returns true)
      • all other handlers keep the view open by default (return false), including onAndroidSystemBack, onRestoreCompleted, and onPurchaseCompleted

      Returning true from a handler closes the view; returning false keeps it open. To retain default behavior in a custom listener, return the same value as the default implementation (only onCloseButtonPress and onError close the view by default).

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

      Register custom event handlers

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

      const view = await createFlowView(flow);

      const unsubscribe = await view.setEventHandlers({
      onPurchaseStarted: (product) => {
      console.log('Purchase started:', product.vendorProductId);
      },
      onPurchaseCompleted: (result) => {
      console.log('Purchase completed:', result.type);
      // Return true to close the view after purchase (default keeps it open)
      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 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');
      }