Skip to content

Commit

Permalink
Merge pull request apache#3047 from wqyfavor/fix-toast-queue
Browse files Browse the repository at this point in the history
[iOS] Do not use queue for iOS toast.
  • Loading branch information
jianhan-he authored Dec 2, 2019
2 parents cc43523 + 7a6a954 commit d57f678
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions ios/sdk/WeexSDK/Sources/Module/WXModalUIModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ @implementation WXToastInfo

@interface WXToastManager : NSObject

@property (strong, nonatomic) NSMutableArray<WXToastInfo *> *toastQueue;
@property (strong, nonatomic) UIView *toastingView;

+ (WXToastManager *)sharedManager;
Expand All @@ -58,7 +57,6 @@ + (WXToastManager *)sharedManager{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shareInstance = [[WXToastManager alloc] init];
shareInstance.toastQueue = [NSMutableArray new];
});
return shareInstance;
}
Expand Down Expand Up @@ -122,16 +120,13 @@ - (void)toast:(NSString *)message duration:(double)duration
superView = self.weexInstance.rootView;
}
UIView *toastView = [self toastViewForMessage:message superView:superView];
WXToastInfo *info = [WXToastInfo new];
info.instance = self.weexInstance;
info.toastView = toastView;
info.superView = superView;
info.duration = duration;
[[WXToastManager sharedManager].toastQueue addObject:info];

if (![WXToastManager sharedManager].toastingView) {
[self showToast:toastView superView:superView duration:duration];
UIView* toastingView = [WXToastManager sharedManager].toastingView;
if (toastingView) {
[toastingView removeFromSuperview];
[WXToastManager sharedManager].toastingView = nil;
}
[self showToast:toastView superView:superView duration:duration];
}

- (UIView *)toastViewForMessage:(NSString *)message superView:(UIView *)superView
Expand All @@ -156,7 +151,10 @@ - (UIView *)toastViewForMessage:(NSString *)message superView:(UIView *)superVie
)];

CGPoint point = CGPointZero;
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
UIWindow* window = [UIApplication sharedApplication].delegate.window;
if (window == NULL) {
window = [[[UIApplication sharedApplication] windows] firstObject];
}

// adjust to screen orientation
UIInterfaceOrientation orientation = (UIInterfaceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
Expand Down Expand Up @@ -191,7 +189,7 @@ - (UIView *)toastViewForMessage:(NSString *)message superView:(UIView *)superVie

[toastView addSubview:messageLabel];
toastView.layer.cornerRadius = 7;
toastView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.7];
toastView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];

return toastView;
}
Expand All @@ -204,32 +202,15 @@ - (void)showToast:(UIView *)toastView superView:(UIView *)superView duration:(do

[WXToastManager sharedManager].toastingView = toastView;
[superView addSubview:toastView];
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.2 delay:duration options:UIViewAnimationOptionCurveEaseInOut animations:^{
toastView.transform = CGAffineTransformConcat(toastView.transform, CGAffineTransformMakeScale(0.8, 0.8)) ;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
toastView.alpha = 0;
} completion:^(BOOL finished){
[toastView removeFromSuperview];
[WXToastManager sharedManager].toastingView = nil;

NSMutableArray *queue = [WXToastManager sharedManager].toastQueue;
if (queue.count > 0) {
[queue removeObjectAtIndex:0];

// remove invalid toasts
for (NSInteger i = [queue count] - 1; i >= 0; i --) {
WXToastInfo *info = queue[i];
if (info.instance == nil) {
[queue removeObjectAtIndex:i];
}
}

if (queue.count > 0) {
WXToastInfo *info = [queue firstObject];
[weakSelf showToast:info.toastView superView:info.superView duration:info.duration];
}
if ([WXToastManager sharedManager].toastingView == toastView) {
[WXToastManager sharedManager].toastingView = nil;
}
}];
}];
Expand Down

0 comments on commit d57f678

Please sign in to comment.