Fix Leaks

This commit is contained in:
James Magahern
2021-03-30 15:39:24 -07:00
parent 84143edfaf
commit 6eb462aeb7
3 changed files with 11 additions and 10 deletions

View File

@@ -244,7 +244,7 @@ class BrowserViewController: UIViewController
webView.goBack() webView.goBack()
}, for: .touchUpInside) }, for: .touchUpInside)
documentControls.observations.append(webView.observe(\.canGoBack, changeHandler: { (_, _) in documentControls.observations.append(webView.observe(\.canGoBack, changeHandler: { (webView, _) in
documentControls.navigationControlView.backButton.isEnabled = webView.canGoBack documentControls.navigationControlView.backButton.isEnabled = webView.canGoBack
})) }))
@@ -253,7 +253,7 @@ class BrowserViewController: UIViewController
webView.goForward() webView.goForward()
}, for: .touchUpInside) }, for: .touchUpInside)
documentControls.observations.append(webView.observe(\.canGoForward, changeHandler: { (_, _) in documentControls.observations.append(webView.observe(\.canGoForward, changeHandler: { (webView, _) in
documentControls.navigationControlView.forwardButton.isEnabled = webView.canGoForward documentControls.navigationControlView.forwardButton.isEnabled = webView.canGoForward
})) }))

View File

@@ -128,8 +128,8 @@ class TabBarView: UIView
{ {
static let preferredHeight: CGFloat = 30.0 static let preferredHeight: CGFloat = 30.0
public var delegate: TabBarViewDelegate? public weak var delegate: TabBarViewDelegate?
public var dataSource: TabBarViewDataSource? public weak var dataSource: TabBarViewDataSource?
private var tabViews: [TabView] = [] private var tabViews: [TabView] = []
private var activeTabIndex: Int = 0 private var activeTabIndex: Int = 0
@@ -192,9 +192,10 @@ class TabBarView: UIView
UIView.animate(withDuration: 0.22, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: [], animations: { [unowned self] in UIView.animate(withDuration: 0.22, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: [], animations: { [unowned self] in
layoutSubviews() layoutSubviews()
}, completion: { [unowned self] finished in }, completion: { [weak self] finished in
guard let self = self else { return }
tabViewsRemoved.forEach { $0.removeFromSuperview() } tabViewsRemoved.forEach { $0.removeFromSuperview() }
tabViews.removeAll { tabViewsRemoved.contains($0) } self.tabViews.removeAll { tabViewsRemoved.contains($0) }
}) })
} }
@@ -232,14 +233,14 @@ class TabBarView: UIView
let tabView = TabView() let tabView = TabView()
tabView.identifier = identifier tabView.identifier = identifier
tabView.addAction(UIAction(handler: { [unowned self, tabView] _ in tabView.addAction(UIAction(handler: { [unowned self, unowned tabView] _ in
guard let delegate = self.delegate else { return } guard let delegate = self.delegate else { return }
guard let tabIndex = self.tabViews.firstIndex(of: tabView) else { return } guard let tabIndex = self.tabViews.firstIndex(of: tabView) else { return }
delegate.tabBarView(self, didClickToActivateTabAtIndex: tabIndex) delegate.tabBarView(self, didClickToActivateTabAtIndex: tabIndex)
}), for: .touchUpInside) }), for: .touchUpInside)
tabView.closeButton.addAction(UIAction(handler: { [unowned self, tabView] _ in tabView.closeButton.addAction(UIAction(handler: { [unowned self, unowned tabView] _ in
guard let delegate = self.delegate else { return } guard let delegate = self.delegate else { return }
guard let tabIndex = self.tabViews.firstIndex(of: tabView) else { return } guard let tabIndex = self.tabViews.firstIndex(of: tabView) else { return }

View File

@@ -29,11 +29,11 @@ class TabBarViewController: UIViewController, TabBarViewDataSource, TabBarViewDe
tabBarView.delegate = self tabBarView.delegate = self
tabBarView.reloadTabs() tabBarView.reloadTabs()
tabObserver = tabController.$tabs.sink(receiveValue: { [tabBarView] (newTabs: [Tab]) in tabObserver = tabController.$tabs.sink(receiveValue: { [unowned self] (newTabs: [Tab]) in
DispatchQueue.main.async { tabBarView.reloadTabs() } DispatchQueue.main.async { tabBarView.reloadTabs() }
}) })
activeTabIndexObserver = tabController.$activeTabIndex.sink(receiveValue: { [tabBarView] (activeIndex: Int) in activeTabIndexObserver = tabController.$activeTabIndex.sink(receiveValue: { [unowned self] (activeIndex: Int) in
tabBarView.activateTab(atIndex: activeIndex) tabBarView.activateTab(atIndex: activeIndex)
}) })
} }