Skip to content

Commit 8710c12

Browse files
authored
Merge pull request #14 from abema/IOS-9957-Fix
[IOS-9957] トースト出ている時にボトムタブ触れなくなっちゃってる現象の修正
2 parents d8505e2 + be1f68e commit 8710c12

1 file changed

Lines changed: 63 additions & 33 deletions

File tree

NavigationNotice/NavigationNotice.swift

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ open class NavigationNotice {
133133

134134
noticeView.clipsToBounds = false
135135
noticeView.showsVerticalScrollIndicator = false
136-
noticeView.isPagingEnabled = true
137136
noticeView.bounces = false
138137
noticeView.delegate = self
139138
switch position {
@@ -221,15 +220,7 @@ open class NavigationNotice {
221220
contentOffsetY = -(safeAreaInsets.bottom + bottomInset)
222221
}
223222

224-
showContent({
225-
switch self.position {
226-
case .top:
227-
self.contentOffsetY = -self.contentHeight
228-
case .bottom:
229-
self.contentOffsetY = self.contentHeight
230-
}
231-
self.setNeedsStatusBarAppearanceUpdateIfNeeded()
232-
}) { _ in
223+
scrollToOrigin {
233224
completion()
234225
}
235226
}
@@ -240,18 +231,7 @@ open class NavigationNotice {
240231
autoHidden = false
241232

242233
if animated == true {
243-
hideContent({
244-
switch self.position {
245-
case .top:
246-
self.contentOffsetY = self.safeAreaInsets.top + self.topInset
247-
case .bottom:
248-
self.contentOffsetY = -(self.safeAreaInsets.bottom + self.bottomInset)
249-
}
250-
self.setNeedsStatusBarAppearanceUpdateIfNeeded()
251-
}) { _ in
252-
self.removeContent()
253-
self.hideCompletionHandler?()
254-
}
234+
scrollToRemove()
255235
} else {
256236
self.setNeedsStatusBarAppearanceUpdateIfNeeded()
257237
removeContent()
@@ -317,8 +297,54 @@ open class NavigationNotice {
317297
}
318298

319299
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
320-
if autoHidden == true && decelerate == false && hiddenTimer == nil {
321-
timer(hiddenTimeInterval)
300+
let isScrollToOrigin: Bool = {
301+
switch position {
302+
case .top:
303+
return contentOffsetY < topInset + safeAreaInsets.top - contentHeight * 0.75
304+
case .bottom:
305+
return contentOffsetY > contentHeight * 0.75 - bottomInset - safeAreaInsets.bottom
306+
}
307+
}()
308+
309+
if isScrollToOrigin {
310+
if autoHidden == true && decelerate == false {
311+
scrollToOrigin {
312+
if self.hiddenTimer == nil {
313+
self.timer(self.hiddenTimeInterval)
314+
}
315+
}
316+
}
317+
} else {
318+
scrollToRemove()
319+
}
320+
}
321+
322+
func scrollToOrigin(completion: @escaping () -> Void) {
323+
showContent({
324+
switch self.position {
325+
case .top:
326+
self.contentOffsetY = -self.contentHeight
327+
case .bottom:
328+
self.contentOffsetY = self.contentHeight
329+
}
330+
self.setNeedsStatusBarAppearanceUpdateIfNeeded()
331+
}) { _ in
332+
completion()
333+
}
334+
}
335+
336+
func scrollToRemove() {
337+
hideContent({
338+
switch self.position {
339+
case .top:
340+
self.contentOffsetY = self.safeAreaInsets.top + self.topInset
341+
case .bottom:
342+
self.contentOffsetY = -(self.safeAreaInsets.bottom + self.bottomInset)
343+
}
344+
self.setNeedsStatusBarAppearanceUpdateIfNeeded()
345+
}) { _ in
346+
self.removeContent()
347+
self.hideCompletionHandler?()
322348
}
323349
}
324350

@@ -362,16 +388,20 @@ open class NavigationNotice {
362388
noticeView.contentSize = noticeView.bounds.size
363389
switch position {
364390
case .top:
365-
noticeView.frame.size.height += (safeAreaInsets.top + topInset)
366-
noticeView.contentInset.top = contentHeight
367-
noticeView.contentInset.bottom = (safeAreaInsets.top + topInset)
368-
noticeView.frame.origin = .zero
391+
noticeView.contentInset = UIEdgeInsets(top: contentHeight,
392+
left: 0.0,
393+
bottom: contentHeight + safeAreaInsets.top + topInset,
394+
right: 0.0);
395+
noticeView.frame.origin = CGPoint(x: 0, y: safeAreaInsets.top + topInset)
369396
contentView.frame.origin = CGPoint(x: (safeAreaInsets.right + safeAreaInsets.left) / 2,
370-
y: -contentHeight + safeAreaInsets.top + topInset)
397+
y: -contentHeight)
371398
case .bottom:
372-
noticeView.frame.size.height += (safeAreaInsets.bottom + bottomInset)
373-
noticeView.contentInset.bottom = contentHeight + (safeAreaInsets.bottom + bottomInset)
374-
noticeView.frame.origin = CGPoint(x: 0, y: self.view.bounds.height - contentHeight)
399+
noticeView.contentInset = UIEdgeInsets(top: contentHeight + safeAreaInsets.bottom + bottomInset,
400+
left: 0.0,
401+
bottom: contentHeight,
402+
right: 0.0);
403+
noticeView.frame.origin = CGPoint(x: 0, y: self.view.bounds.height - contentHeight -
404+
safeAreaInsets.bottom - bottomInset)
375405
contentView.frame.origin = CGPoint(x: (safeAreaInsets.right + safeAreaInsets.left) / 2,
376406
y: contentHeight)
377407
}
@@ -423,7 +453,7 @@ open class NavigationNotice {
423453
showingNotice?.noticeViewController.setNeedsStatusBarAppearanceUpdateIfNeeded()
424454
showingNotice = nil
425455

426-
mainWindow?.makeKeyAndVisible()
456+
mainWindow?.makeKey()
427457
noticeWindow = nil
428458
}
429459

0 commit comments

Comments
 (0)