Skip to content

Commit

Permalink
feat: Always have an initialContext (#19)
Browse files Browse the repository at this point in the history
feat: Previously, if no initialContext no was passed to a portal, the web side of the portal would not have access to its name property. This change allows for the portal to have access to its name regardless of there being an initial value passed in or not.
  • Loading branch information
Steven0351 committed Nov 7, 2022
1 parent 760b3cf commit 60f0089
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions IonicPortals/src/main/kotlin/io/ionic/portals/PortalFragment.kt
Expand Up @@ -192,24 +192,27 @@ open class PortalFragment : Fragment {
}

private fun setupInitialContextListener() {
val initialContext = this.initialContext ?: portal?.initialContext ?: return
val jsonObject: JSONObject = when (initialContext) {
is String -> {
try {
JSONObject(initialContext)
} catch (ex: JSONException) {
val initialContext = this.initialContext ?: portal?.initialContext
val portalInitialContext = if (initialContext != null) {
val jsonObject: JSONObject = when (initialContext) {
is String -> {
try {
JSONObject(initialContext)
} catch (ex: JSONException) {
throw Error("initialContext must be a JSON string or a Map")
}
}
is Map<*, *> -> {
JSONObject(initialContext.toMap())
}
else -> {
throw Error("initialContext must be a JSON string or a Map")
}
}
is Map<*, *> -> {
JSONObject(initialContext.toMap())
}
else -> {
throw Error("initialContext must be a JSON string or a Map")
}
"{ \"name\": \"" + portal?.name + "\"," + " \"value\": " + jsonObject.toString() + " } "
} else {
"{ \"name\": \"" + portal?.name + "\"" + " } "
}
val portalInitialContext = "{ \"name\": \"" + portal?.name + "\"," +
" \"value\": " + jsonObject.toString() + " } "

val newWebViewClient = object: BridgeWebViewClient(bridge) {
override fun shouldInterceptRequest(
Expand Down

0 comments on commit 60f0089

Please sign in to comment.