Skip to content

Commit

Permalink
fix: fix transaction exception crashing the app if the view no longer…
Browse files Browse the repository at this point in the history
… exists
  • Loading branch information
carlpoole committed Feb 8, 2024
1 parent 0c4886d commit 1421b1f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions IonicPortals/src/main/kotlin/io/ionic/portals/PortalView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.getcapacitor.Bridge
import com.getcapacitor.Logger
import java.util.ArrayList

/**
Expand Down Expand Up @@ -193,10 +194,15 @@ class PortalView : FrameLayout {
}
val handler = Handler()
val runnable = Runnable {
fmTransaction
.setReorderingAllowed(true)
.add(id, portalFragment!!, "")
.commitNowAllowingStateLoss()
val thisView = findViewById<PortalView>(id)
if(thisView != null) {
fmTransaction
.setReorderingAllowed(true)
.add(id, portalFragment!!, "")
.commitNowAllowingStateLoss()
} else {
Logger.warn("PortalView", "Unable to find active PortalView with id: $id. Skipping Portal inflation.")
}
}

handler.post(runnable)
Expand Down

0 comments on commit 1421b1f

Please sign in to comment.