Skip to main content

PortalFragment

The PortalFragment class is an Android Fragment containing a Portal instance. You can use the class as is, or extend it to provide customizable loading functionality.

Because PortalFragment is an extended Fragment class, you can override the following Fragment functions:

  • onViewCreated
  • onDestroy
  • onResume
  • onPause
  • onConfigurationChanged

Constructors

constructor

Usage

val fragment: PortalFragment = PortalFragment()

Additionally, you can pass in an already initialized Portal instance to a new PortalFragment

val portal: Portal = someValue
val fragment: PortalFragment = PortalFragment(portal)

Parameters

NameTypeDescription
portalPortalAn initialized Portal object to contain within the PortalFragment

Returns: PortalFragment

Methods

addPlugin

Add a Plugin to the Portal within PortalFragment

Usage

val fragment: PortalFragment = PortalFragment()
fragment.addPlugin(MyPlugin::class.java)

Parameters

NameTypeDescription
pluginClass<out Plugin?>The Capacitor Plugin class to add to your Portal

setConfig

Set a CapConfig configuration object to this PortalFragment

Usage

val fragment: PortalFragment = PortalFragment()
val config: CapConfig = someValue;
fragment.setConfig(config)

Parameters

NameTypeDescription
configCapConfigThe Capacitor CapConfig class to add to your Portal

getBridge

Returns the Capacitor Bridge object connected to the PortalFragment.

Usage

val fragment: PortalFragment = PortalFragment()
val bridge: Bridge = fragment.getBridge()

Returns: Bridge

addWebViewListener

Add a WebViewListener instance to the PortalFragment to listen for web events.

Usage

val fragment: PortalFragment = PortalFragment()
val listener: WebViewListener = someValue;
fragment.addWebViewListener(listener)

Parameters

NameTypeDescription
webViewListenerWebViewListenerThe Capacitor WebViewListener class that you can use to listen to web loading events.

linkMessageReceivers

Link a class with methods decorated with the @PortalMethod annotation to use as Portals message receivers.

The name of the method should match the message name used to send messages via the Portal. Alternatively the @PortalMethod annotation name property can be used to designate a different name. The registered methods should accept a single String representing the payload of a message sent through the Portal.

Usage

val fragment: PortalFragment = PortalFragment()
fragment.linkMessageReceivers(this)

Parameters

NameTypeDescription
messageReceiverParentAnyThe parent object of the message receivers. This value will almost always be this.