Skip to content

Commit

Permalink
Delay UIAlertController.onDismiss (#201)
Browse files Browse the repository at this point in the history
Currently, `onDismiss` is called _before_ the `UIAlertAction` is
processed, which generally isn't an issue, but if you care about the
order of operations, this can be a bit thorny. In the case of highly
generalized navigation patterns in TCA, the order is what we use to emit
warnings when invalid actions are received (like a `dismiss` action is
received for an already-dismissed feature), so let's address the problem
with a quick tick.

We could do this thread hop unconditionally if it makes sense to, but
let's localize to `UIAlertController` for now.
  • Loading branch information
stephencelis authored Aug 15, 2024
1 parent b8dced6 commit 42755eb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/UIKitNavigationShim/shim.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ - (void)UIKitNavigation_viewDidDisappear:(BOOL)animated {
[self UIKitNavigation_viewDidDisappear:animated];

if ((self.isBeingDismissed || self.isMovingFromParentViewController) && self.onDismiss != NULL) {
self.onDismiss();
self.onDismiss = nil;
if ([self isKindOfClass:UIAlertController.class]) {
dispatch_async(dispatch_get_main_queue(), ^{
self.onDismiss();
self.onDismiss = nil;
});
} else {
self.onDismiss();
self.onDismiss = nil;
}
}
}

Expand Down

0 comments on commit 42755eb

Please sign in to comment.