Skip to content

Commit

Permalink
commit fragment only before state saved
Browse files Browse the repository at this point in the history
  • Loading branch information
swnishan committed May 22, 2024
1 parent cdfc590 commit 7ae2c7a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions library/src/main/java/com/vinted/coper/CoperImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ internal class CoperImpl(
fragmentManager: FragmentManager
): CoperFragment {
return suspendCancellableCoroutine { continuation ->
fragmentManager.beginTransaction()
.add(this, FRAGMENT_TAG)
.runOnCommit {
continuation.resume(this)
}
.commit()
_latestCommittedFragmentFlow.value = this
if (!fragmentManager.isStateSaved) {
fragmentManager.beginTransaction()
.add(this, FRAGMENT_TAG)
.runOnCommit {
continuation.resume(this)
}
.commit()
_latestCommittedFragmentFlow.value = this
} else {
continuation.cancel()
}
}
}

Expand Down

0 comments on commit 7ae2c7a

Please sign in to comment.