Skip to content

Commit

Permalink
feat: added jetpack compose support for bridge availability callback (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpoole committed Jan 10, 2023
1 parent b805b2f commit eea0af6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions IonicPortals/src/main/kotlin/io/ionic/portals/PortalView.kt
Expand Up @@ -14,6 +14,7 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.getcapacitor.Bridge
import java.util.ArrayList

class PortalView : FrameLayout {
Expand All @@ -25,21 +26,29 @@ class PortalView : FrameLayout {
private var mDrawDisappearingViewsFirst = true
private var portalFragment: PortalFragment? = null
private var webVitalsCallback: ((WebVitals.Metric, Long) -> Unit)? = null
private var onBridgeAvailable: ((bridge: Bridge) -> Unit)? = null
var portalId: String? = null
var viewId: String? = null
var tag: String? = null

constructor(context: Context) : super(context)

// Provided for Compose
constructor(context: Context, portalId: String) : this(context, portalId, portalId+"_view", null)
constructor(context: Context, portalId: String) : this(context, portalId, portalId+"_view", null, null)

// Provided for Compose
constructor(context: Context, portalId: String, webVitalsCallback: (metric: WebVitals.Metric, time: Long) -> Unit) : this(context, portalId, portalId+"_view", webVitalsCallback)
constructor(context: Context, portalId: String, onBridgeAvailable: ((bridge: Bridge) -> Unit)) : this(context, portalId, portalId+"_view", onBridgeAvailable, null)

// Provided for Compose
constructor(context: Context, portalId: String, viewId: String, webVitalsCallback: ((metric: WebVitals.Metric, long: Long) -> Unit)?) : super(context) {
constructor(context: Context, portalId: String, webVitalsCallback: (metric: WebVitals.Metric, time: Long) -> Unit) : this(context, portalId, portalId+"_view", null, webVitalsCallback)

// Provided for Compose
constructor(context: Context, portalId: String, onBridgeAvailable: ((bridge: Bridge) -> Unit), webVitalsCallback: (metric: WebVitals.Metric, time: Long) -> Unit) : this(context, portalId, portalId+"_view", onBridgeAvailable, webVitalsCallback)

// Provided for Compose
constructor(context: Context, portalId: String, viewId: String, onBridgeAvailable: ((bridge: Bridge) -> Unit)?, webVitalsCallback: ((metric: WebVitals.Metric, long: Long) -> Unit)?) : super(context) {
this.webVitalsCallback = webVitalsCallback
this.onBridgeAvailable = onBridgeAvailable
this.portalId = portalId
this.viewId = viewId
this.id = View.generateViewId()
Expand Down Expand Up @@ -129,6 +138,7 @@ class PortalView : FrameLayout {
) as PortalFragment

portalFragment?.portal = portal
portalFragment?.onBridgeAvailable = this.onBridgeAvailable
portalFragment?.webVitalsCallback = this.webVitalsCallback
attrs?.let { attributeSet ->
portalFragment?.onInflate(context, attributeSet, null)
Expand Down

0 comments on commit eea0af6

Please sign in to comment.