Skip to content

Commit

Permalink
Merge pull request cruffenach#14 from dmiedema/master
Browse files Browse the repository at this point in the history
Remove unintended side effects of accessing toast.notificationView
  • Loading branch information
dmiedema committed Jan 16, 2015
2 parents 6f24b43 + 6ba99a3 commit 8e8ca5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
32 changes: 23 additions & 9 deletions CRToast/CRToast.m
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ + (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType)

@interface CRToast ()
@property (nonatomic, readonly) BOOL snapshotWindow;
@property (strong, nonatomic) CRToastView *privateNotificationView;
@property (strong, nonatomic) UIView *privateStatusBarView;
@end

@implementation CRToast
Expand Down Expand Up @@ -426,10 +428,16 @@ + (void)setDefaultOptions:(NSDictionary*)defaultOptions {
#pragma mark - Notification View Helpers

- (UIView*)notificationView {
CGSize size = CRNotificationViewSize(self.notificationType, self.preferredHeight);
CRToastView *notificationView = [[CRToastView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
notificationView.toast = self;
return notificationView;
return self.privateNotificationView;
}

- (UIView *)privateNotificationView {
if (!_privateNotificationView) {
CGSize size = CRNotificationViewSize(self.notificationType, self.preferredHeight);
_privateNotificationView = [[CRToastView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
_privateNotificationView.toast = self;
}
return _privateNotificationView;
}

- (CGRect)notificationViewAnimationFrame1 {
Expand All @@ -441,12 +449,18 @@ - (CGRect)notificationViewAnimationFrame2 {
}

- (UIView*)statusBarView {
UIView *statusBarView = [[UIView alloc] initWithFrame:self.statusBarViewAnimationFrame1];
if (self.snapshotWindow) {
[statusBarView addSubview:CRStatusBarSnapShotView(self.displayUnderStatusBar)];
return self.privateStatusBarView;
}

- (UIView *)privateStatusBarView {
if (!_privateStatusBarView) {
_privateStatusBarView = [[UIView alloc] initWithFrame:self.statusBarViewAnimationFrame1];
if (self.snapshotWindow) {
[_privateStatusBarView addSubview:CRStatusBarSnapShotView(self.displayUnderStatusBar)];
}
_privateStatusBarView.clipsToBounds = YES;
}
statusBarView.clipsToBounds = YES;
return statusBarView;
return _privateStatusBarView;
}

- (CGRect)statusBarViewAnimationFrame1 {
Expand Down
7 changes: 4 additions & 3 deletions CRToast/CRToastManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ - (void)displayNotification:(CRToast*)notification {

notification.state = CRToastStateEntering;

[self showNotification:notification notificationView:notificationView statusBarView:statusBarView inwardAnimationBlock:inwardAnimationsBlock inwardCompletionAnimationBlock:inwardAnimationsCompletionBlock];
[self showNotification:notification inwardAnimationBlock:inwardAnimationsBlock inwardCompletionAnimationBlock:inwardAnimationsCompletionBlock];

if (notification.text.length > 0 || notification.subtitleText.length > 0) {
// Synchronous notifications (say, tapping a button that presents a toast) cause VoiceOver to read the button immediately, which interupts the toast. A short delay (not the best solution :/) allows the toast to interupt the button.
Expand All @@ -319,8 +319,6 @@ - (void)displayNotification:(CRToast*)notification {
}

- (void)showNotification:(CRToast *)notification
notificationView:(UIView *)notificationView
statusBarView:(UIView *)statusBarView
inwardAnimationBlock:(CRToastAnimationStepBlock)inwardAnimationsBlock
inwardCompletionAnimationBlock:(CRToastAnimationCompletionBlock)inwardAnimationsCompletionBlock {

Expand All @@ -340,6 +338,9 @@ - (void)showNotification:(CRToast *)notification
completion:inwardAnimationsCompletionBlock];
} break;
case CRToastAnimationTypeGravity: {
UIView *notificationView = notification.notificationView;
UIView *statusBarView = notification.statusBarView;

[notification initiateAnimator:_notificationWindow.rootViewController.view];
[notification.animator removeAllBehaviors];
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[notificationView, statusBarView]];
Expand Down

0 comments on commit 8e8ca5d

Please sign in to comment.