Skip to content

Commit

Permalink
Commit CoperFragment only before onStateSaved (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
swnishan authored May 22, 2024
1 parent cdfc590 commit 52f32c5
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 52f32c5

Please sign in to comment.