Skip to content

Commit 3acae59

Browse files
committed
Minor clean up
* Returning early when rendering complete is false and we try to dismiss an IAM * Fixed spelling mistakes in a comments
1 parent bbc56d7 commit 3acae59

File tree

1 file changed

+45
-48
lines changed

1 file changed

+45
-48
lines changed

iOS_SDK/OneSignalSDK/Source/OSInAppMessageViewController.m

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ @interface OSInAppMessageViewController ()
7979
// We start the timer once the message is displayed (not during loading the content)
8080
@property (weak, nonatomic, nullable) NSTimer *dismissalTimer;
8181

82-
// BOOL to track when an IAM has strated UI setup so we know when to bypass UI changes on dismissal or not
83-
// This is a fail safe for cases where global contraints are nil and we try to modify them on dismisal of an IAM
82+
// BOOL to track when an IAM has started UI setup so we know when to bypass UI changes on dismissal or not
83+
// This is a fail safe for cases where global contraints are nil and we try to modify them on dismissal of an IAM
8484
@property (nonatomic) BOOL didPageRenderingComplete;
8585

8686
@end
@@ -395,58 +395,55 @@ Dismisses the message view with a given direction (up or down) and velocity
395395
*/
396396
- (void)dismissCurrentInAppMessage:(BOOL)up withVelocity:(double)velocity {
397397

398-
// Validate whether or not WebView actually rendered the IAM code, which we lead to global constraits not being nil
399-
if (self.didPageRenderingComplete) {
400-
401-
// Inactivate the current Y constraints
402-
self.finalYConstraint.active = false;
403-
self.initialYConstraint.active = false;
404-
405-
// The distance that the dismissal animation will travel
406-
var distance = 0.0f;
398+
// If the rendering event never occurs any constraints being adjusted for dismissal will be nil
399+
// and we should bypass dismissal adjustments and animations and skip straight to the OSMessagingController callback for dismissing
400+
if (!self.didPageRenderingComplete) {
401+
[self.delegate messageViewControllerWasDismissed];
402+
return;
403+
}
407404

408-
// Add new Y constraints
409-
if (up) {
410-
distance = self.messageView.frame.origin.y + self.messageView.frame.size.height + 8.0f;
411-
[self.messageView.bottomAnchor constraintEqualToAnchor:self.view.topAnchor constant:-8.0f].active = true;
412-
} else {
413-
distance = self.view.frame.size.height - self.messageView.frame.origin.y + 8.0f;
414-
[self.messageView.topAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:8.0f].active = true;
415-
}
405+
// Inactivate the current Y constraints
406+
self.finalYConstraint.active = false;
407+
self.initialYConstraint.active = false;
416408

417-
var dismissAnimationDuration = velocity != 0.0f ? distance / fabs(velocity) : 0.3f;
418-
419-
var animationOption = UIViewAnimationOptionCurveLinear;
420-
421-
// Impose a minimum animation speed (max duration)
422-
if (dismissAnimationDuration > MAX_DISMISSAL_ANIMATION_DURATION) {
423-
animationOption = UIViewAnimationOptionCurveEaseIn;
424-
dismissAnimationDuration = MAX_DISMISSAL_ANIMATION_DURATION;
425-
} else if (dismissAnimationDuration < MIN_DISMISSAL_ANIMATION_DURATION) {
426-
animationOption = UIViewAnimationOptionCurveEaseIn;
427-
dismissAnimationDuration = MIN_DISMISSAL_ANIMATION_DURATION;
428-
}
429-
430-
[UIView animateWithDuration:dismissAnimationDuration delay:0.0f options:animationOption animations:^{
431-
self.view.backgroundColor = [UIColor clearColor];
432-
self.view.alpha = 0.0f;
433-
[self.view layoutIfNeeded];
434-
} completion:^(BOOL finished) {
435-
if (!finished)
436-
return;
437-
438-
[self dismissViewControllerAnimated:false completion:nil];
439-
440-
self.didPageRenderingComplete = false;
441-
[self.delegate messageViewControllerWasDismissed];
442-
}];
409+
// The distance that the dismissal animation will travel
410+
var distance = 0.0f;
411+
412+
// Add new Y constraints
413+
if (up) {
414+
distance = self.messageView.frame.origin.y + self.messageView.frame.size.height + 8.0f;
415+
[self.messageView.bottomAnchor constraintEqualToAnchor:self.view.topAnchor constant:-8.0f].active = true;
443416
} else {
417+
distance = self.view.frame.size.height - self.messageView.frame.origin.y + 8.0f;
418+
[self.messageView.topAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:8.0f].active = true;
419+
}
420+
421+
var dismissAnimationDuration = velocity != 0.0f ? distance / fabs(velocity) : 0.3f;
422+
423+
var animationOption = UIViewAnimationOptionCurveLinear;
424+
425+
// Impose a minimum animation speed (max duration)
426+
if (dismissAnimationDuration > MAX_DISMISSAL_ANIMATION_DURATION) {
427+
animationOption = UIViewAnimationOptionCurveEaseIn;
428+
dismissAnimationDuration = MAX_DISMISSAL_ANIMATION_DURATION;
429+
} else if (dismissAnimationDuration < MIN_DISMISSAL_ANIMATION_DURATION) {
430+
animationOption = UIViewAnimationOptionCurveEaseIn;
431+
dismissAnimationDuration = MIN_DISMISSAL_ANIMATION_DURATION;
432+
}
433+
434+
[UIView animateWithDuration:dismissAnimationDuration delay:0.0f options:animationOption animations:^{
435+
self.view.backgroundColor = [UIColor clearColor];
436+
self.view.alpha = 0.0f;
437+
[self.view layoutIfNeeded];
438+
} completion:^(BOOL finished) {
439+
if (!finished)
440+
return;
444441

445-
// If the rendering event never occurs any constraints being adjusted for dismissal will be nil
446-
// and we should bypass dismissal adjustments and animations and skip straight to the OSMessagingController callback for dismissing
442+
[self dismissViewControllerAnimated:false completion:nil];
443+
447444
self.didPageRenderingComplete = false;
448445
[self.delegate messageViewControllerWasDismissed];
449-
}
446+
}];
450447
}
451448

452449
/*

0 commit comments

Comments
 (0)