Skip to content

Commit

Permalink
Use weak self on closures
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Dec 19, 2024
1 parent d68d8a4 commit 8b91013
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions DuckDuckGo/TabBar/View/TabBarRemoteMessagePresenting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,31 @@ extension TabBarRemoteMessagePresenting {
private func showTabBarRemoteMessage(_ tabBarRemotMessage: TabBarRemoteMessage) {
let feedbackButtonView = TabBarRemoteMessageView(
model: tabBarRemotMessage,
onClose: {
onClose: { [weak self] in
guard let self = self else { return }

self.tabBarRemoteMessageViewModel.onMessageDismissed()
self.removeFeedbackButton()
},
onTap: { surveyURL in
onTap: { [weak self] surveyURL in
guard let self = self else { return }

DispatchQueue.main.async {
WindowControllersManager.shared.showTab(with: .contentFromURL(surveyURL, source: .appOpenUrl))
}
self.tabBarRemoteMessageViewModel.onSurveyOpened()
self.removeFeedbackButton()
},
onHover: {
onHover: { [weak self] in
guard let self = self else { return }
self.startTabBarRemotMessageTimer(message: tabBarRemotMessage)
},
onHoverEnd: {
onHoverEnd: { [weak self] in
guard let self = self else { return }
self.dismissTabBarRemoteMessagePopover()
},
onAppear: {
onAppear: { [weak self] in
guard let self = self else { return }
self.tabBarRemoteMessageViewModel.markTabBarRemoteMessageAsShown()
}
)
Expand All @@ -115,7 +122,8 @@ extension TabBarRemoteMessagePresenting {
/// - Parameter message: The remote message associated with the popover
private func startTabBarRemotMessageTimer(message: TabBarRemoteMessage) {
tabBarRemoteMessagePopoverHoverTimer?.invalidate()
tabBarRemoteMessagePopoverHoverTimer = Timer.scheduledTimer(withTimeInterval: 1.5, repeats: false) { _ in
tabBarRemoteMessagePopoverHoverTimer = Timer.scheduledTimer(withTimeInterval: 1.5, repeats: false) { [weak self] _ in
guard let self = self else { return }
self.showTabBarRemotePopup(message)
}
}
Expand Down

0 comments on commit 8b91013

Please sign in to comment.