Skip to main content

Portal

The Portal class is the main entry point for your application. It contains the data to be passed into the web context. It is not advised to use this class directly. PortalBuilder or PortalManager should be used instead to construct a Portal instance.

Constructors

constructor

Usage

val name: String = "Hello World"
val portal: Portal = Portal(name)

Parameters

NameTypeDescription
nameStringThe name of the Portal to be referenced via the PortalManager or the PortalView

Returns: Portal

Properties

startDir

read-only

The start directory of the portal web app. If this value is not set, the startDir property will default to the name of the portal passed in the constructor.

Usage

val portal: Portal = someValue
val directoryOnDevice: String = portal.startDir

Returns: String

portalFragmentType

The PortalFragment type used by a PortalView when using Portals directly in Android layouts/XML. The default value is PortalFragment, but any class that extends PortalFragment can be used.

Usage

val portal: Portal = someValue
val fragmentType: Class<out PortalFragment?> = MyPortalFragment::class.java

Methods

addPlugin

Add a Capacitor Plugin to be loaded with this Portal.

Usage

val portal: Portal = someValue
portal.addPlugin(MyPlugin::class.java)

Parameters

NameTypeDescription
pluginClass<out Plugin?>A Plugin to be used with the Portal.

addPlugins

Add multiple Capacitor Plugins to be loaded with this Portal.

Usage

val portal: Portal = someValue
val list: List<Class<out Plugin?>> = listOf(
FooPlugin::class.java,
BarPlugin::class.java,
BazPlugin::class.java
)
portal.addPlugins(list)

Parameters

NameTypeDescription
pluginsList<Class<out Plugin?>>A list of Plugins to be used with the Portal.

setInitialContext

Sets the initial context to pass to the WebView. You can pass in either a Map or a String that will be parsed into a JSON object.

Usage

Map Usage

val portal: Portal = someValue
val map: Map<String, Any> = mapOf(
"foo" to "bar",
"ionic" to "portals"
"num" to 42
)
portal.setInitialContext(map)

String Usage

val portal: Portal = someValue
val str: String = '{ "foo": "bar", "ionic": "portals", "num": 42 }'
portal.setInitialContext(str)

In the examples above, your initial context in the web portion of the code will be parsed like this:

interface MyPortalInitialContext {
foo: string,
ionic: string,
num: number
}

const context = getInitialContext<MyPortalInitialContext>();
console.log(context?.value?.foo) // "bar"
console.log(context?.value?.ionic) // "portals"
console.log(context?.value?.num) // 42

Parameters

NameTypeDescription
initialContextMap<String, Any>A map containing key/pair values that will be converted to a JavaScript object in the WebView.
NameTypeDescription
initialContextStringA JSON-valid string that will be converted to a JavaScript object in the WebView.