Skip to content

Commit

Permalink
Try to fix crash #62
Browse files Browse the repository at this point in the history
fix: add weakself reference to try to avoid crash (#92)

Closes #62
  • Loading branch information
Friend-LGA authored Sep 6, 2024
1 parent 096b256 commit 4e2b610
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions LGAlertView/LGAlertViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,22 @@ - (nonnull instancetype)initWithAlertView:(nonnull LGAlertView *)alertView view:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

__weak typeof(self) weakSelf = self;
__weak typeof(coordinator) weakCoordinator = coordinator;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:coordinator.transitionDuration animations:^{
[self setNeedsStatusBarAppearanceUpdate];
[self.alertView layoutValidateWithSize:size];
if (!weakSelf) {
return;
}
__strong typeof(weakSelf) strongSelf = weakSelf;
float transitionDuration = ^{
if (weakCoordinator) {
return weakCoordinator.transitionDuration;
}
return [[LGAlertView appearance] animationDuration];
}();
[UIView animateWithDuration:transitionDuration animations:^{
[strongSelf setNeedsStatusBarAppearanceUpdate];
[strongSelf.alertView layoutValidateWithSize:size];
}];
});
}
Expand Down

0 comments on commit 4e2b610

Please sign in to comment.