[ios] Fix isolines reminder being displayed on top of other dialogs #7694

Merged
v-lozko merged 3 commits from Isoline into master 2024-04-05 22:16:20 +00:00
2 changed files with 34 additions and 11 deletions

View file

@ -7,11 +7,20 @@ final class Toast: NSObject {
}
Review
  @objc static func hideAll() {
```suggestion @objc static func hideAll() { ```
Review

nit: it's better to write in single line easy iterations toastsCopy.forEach { $0.hide() }

nit: it's better to write in single line easy iterations `toastsCopy.forEach { $0.hide() }`
private var blurView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
private var timer: Timer?
private static var toasts: [Toast] = []
@objc static func toast(withText text: String) -> Toast {
return Toast(text)
let toast = Toast(text)
toasts.append(toast)
return toast
}
@objc static func hideAll() {
toasts.forEach { $0.hide() }
}
private init(_ text: String) {
blurView.layer.setCorner(radius: 8)
blurView.clipsToBounds = true
@ -34,6 +43,10 @@ final class Toast: NSObject {
label.bottomAnchor.constraint(equalTo: blurView.contentView.bottomAnchor, constant: -8)
])
}
deinit {
timer?.invalidate()
}
@objc func show() {
show(in: UIApplication.shared.keyWindow, alignment: .bottom)
@ -72,15 +85,20 @@ final class Toast: NSObject {
self.blurView.alpha = 1
}
Timer.scheduledTimer(timeInterval: 3,
target: self,
selector: #selector(onTimer),
userInfo: nil,
repeats: false)
timer = Timer.scheduledTimer(timeInterval: 3,
target: self,
selector: #selector(hide),
userInfo: nil,
repeats: false)
}
@objc private func onTimer() {
UIView.animate(withDuration: kDefaultAnimationDuration,
animations: { self.blurView.alpha = 0 }) { [self] _ in self.blurView.removeFromSuperview() }
@objc func hide() {
timer?.invalidate()
if self.blurView.superview != nil {
UIView.animate(withDuration: kDefaultAnimationDuration,
animations: { self.blurView.alpha = 0 }) { [self] _ in
self.blurView.removeFromSuperview()
Review

I think it's better to try to place this line into the UIView.animate's completion handler to remove the toast instance as a final step.

I think it's better to try to place this line into the `UIView.animate`'s completion handler to remove the toast instance as a final step.
Self.toasts.removeAll(where: { $0 === self }) }
}
}
}

View file

@ -63,6 +63,11 @@ NSArray<UIImage *> *imagesWithName(NSString *name) {
[StyleManager.shared removeListener:self];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[MWMToast hideAll];
}
- (void)configLayout {
UIView *sv = self.view;
UIView *ov = sv.superview;