Skip to content

Commit

Permalink
Coordinate dismiss of ComposeVC with presentation of ConversationVC
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-signal committed May 16, 2024
1 parent 5a9244f commit e5a229c
Showing 1 changed file with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,20 @@ class ComposeViewController: RecipientPickerContainerViewController {

/// Presents the conversation for the given thread and dismisses this
/// controller such that the conversation is visible.
///
/// - Note
/// In practice, the view controller dismissing us here is the same one
/// (a ``ConversationSplitViewController``) that will ultimately present the
/// conversation. To that end, there be dragons in potential races between
/// the two actions, which seem to particularly be prominent when this
/// method is called from a `DispatchQueue.main` block. (This happens, for
/// example, when doing some asynchronous work, such as a lookup, which
/// completes in a `DispatchQueue.main` block that calls this method.)
///
/// Some example dragons found at the time of writing include user
/// interaction being disabled on the nav bar, incorrect nav bar layout,
/// keyboards refusing to pop, and the conversation input toolbar being
/// hidden behind the keyboard if it does pop.
///
/// Ensuring that the presentation and dismissal are in separate dispatch
/// blocks seems to dodge the dragons.
func newConversation(thread: TSThread) {
SignalApp.shared.presentConversationForThread(thread, action: .compose, animated: false)

DispatchQueue.main.async { [weak self] in
self?.presentingViewController?.dismiss(animated: true)
presentingViewController?.dismiss(animated: true)
if let transitionCoordinator = presentingViewController?.transitionCoordinator {
// When transitionCoordinator is present, coordinate the immediate presentation of
// the conversationVC with the animated dismissal of the compose VC
transitionCoordinator.animate { _ in
UIView.performWithoutAnimation {
SignalApp.shared.presentConversationForThread(thread, action: .compose, animated: false)
}
}
} else {
// There isn't a transition coordinator present for some reason, revert to displaying
// the conversation VC in parallel with the animated dismissal of the compose VC
SignalApp.shared.presentConversationForThread(thread, action: .compose, animated: false)
}
}

Expand Down

0 comments on commit e5a229c

Please sign in to comment.