Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tab bar remote message #3665

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

jotaemepereira
Copy link
Collaborator

@jotaemepereira jotaemepereira commented Dec 12, 2024

Task/Issue URL: https://app.asana.com/0/1204006570077678/1208970712110808/f
Tech Design URL:
CC:

Description
Adds a new remote message that is shown in the tab bar.

Steps to test this PR:

  1. Go to the RemoteMessagingClient and change the DEBUG endpoint URL to https://www.jsonblob.com/api/1316017217598578688
  2. Run the app
  3. You should see the new blue button in the tab bar
  4. When hovering it, it should show a popup.
  5. Tapping the button will take you to the survey
  6. Test that when the button is dismissed is removed in all windows
  7. Test that New Tab Page does not show this new message

Definition of Done:

Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against 7d54df2

@jotaemepereira jotaemepereira requested a review from ayoy December 17, 2024 14:16
@jotaemepereira jotaemepereira force-pushed the juan/poc-new-user-feedfack-point-of-action branch from 269b7a5 to 52a86be Compare December 17, 2024 15:25
@jotaemepereira jotaemepereira force-pushed the juan/poc-new-user-feedfack-point-of-action branch from b3b001b to 3fb8ec2 Compare December 17, 2024 18:59
Copy link
Collaborator

@ayoy ayoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jotaemepereira! The message works nicely but l've found a bug in HTML NTP and also wanted to suggest some changes in the view to better support localization. Please have a look, thanks!

})
)
.onAppear(perform: { onAppear() })
.frame(width: 147)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that behave with translations? Are we fine with truncating the text?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed. Now, both the button and the popover will resize accordingly.

Comment on lines 36 to 46
.buttonStyle(DefaultActionButtonStyle(
enabled: true,
onClose: { onClose() },
onHoverStart: {
onHover()
},
onHoverEnd: {
onHoverEnd()
})
)
.onAppear(perform: { onAppear() })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify this a bit by passing closures directly as arguments:

Suggested change
.buttonStyle(DefaultActionButtonStyle(
enabled: true,
onClose: { onClose() },
onHoverStart: {
onHover()
},
onHoverEnd: {
onHoverEnd()
})
)
.onAppear(perform: { onAppear() })
.buttonStyle(DefaultActionButtonStyle(enabled: true, onClose: onClose, onHoverStart: onHover, onHoverEnd: onHoverEnd))
.onAppear(perform: onAppear)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This button style was removed.

import SwiftUI

struct TabBarRemoteMessageView: View {
@State private var presentPopup: Bool = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unused

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it.

Comment on lines 53 to 56
enum Constants {
static let height: CGFloat = 92
static let width: CGFloat = 360
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, would be great to test it with long message bodies. Perhaps we'd want a variable height. The icon should probably stay aligned to the top, like in other remote messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed, now we do not have fixed a fixed height for the popover, the popover will increase in height in case it spans more lines.

DuckDuckGo/TabBar/Model/TabBarRemoteMessage.swift Outdated Show resolved Hide resolved
$remoteMessage.dropFirst().eraseToAnyPublisher()
$remoteMessage
.dropFirst()
.filter { $0?.isForTabBar == false }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating this check, but here are 2 more things:

  • This also needs to allow nil values, so { $0?.isForTabBar == false || $0 == nil }
  • This is just a publisher. NewTabPageActiveRemoteMessageProviding protocol also declares remoteMessage accessor which it taken directly from ActiveRemoteMessageModel.remoteMessage. That one isn't filtered in any way and the tab bar message still appears on HTML NTP.

What we've talked about on MM, i.e. adding 2 more variables to ActiveRemoteMessageModel called e.g. newTabPageRemoteMessage and tabBarRemoteMessage that would be updated every time remoteMessage is updated, by filtering that one appropriately, could help solve the problem here and move the filtering logic to the model.

Note that if you add these additional variables, you should update NewTabPageActiveRemoteMessageProviding protocol to use newTabPageRemoteMessage and newTabPageRemoteMessagePublisher but this should be straightforward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍🏼

Comment on lines 146 to 148
.padding(.top, 2.5)
.padding(.bottom, 3)
.padding(.horizontal, 7.5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I'm not sure if the design wants fraction paddings (or even odd numbers), so perhaps it's worth checking if 2, 4, and 8 would work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this button style.

Comment on lines 51 to 69
onClose: {
self.tabBarRemoteMessageViewModel.onMessageDismissed()
self.removeFeedbackButton()
},
onTap: { surveyURL in
DispatchQueue.main.async {
WindowControllersManager.shared.showTab(with: .contentFromURL(surveyURL, source: .appOpenUrl))
}
self.tabBarRemoteMessageViewModel.onSurveyOpened()
self.removeFeedbackButton()
},
onHover: {
self.startTabBarRemotMessageTimer(message: tabBarRemotMessage)
},
onHoverEnd: {
self.dismissTabBarRemoteMessagePopover()
},
onAppear: {
self.tabBarRemoteMessageViewModel.markTabBarRemoteMessageAsShown()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing self in closures to the view that's owned by a controller that's owned by self introduces a reference cycle. It shouldn't be a problem right here but to be on the safe side I'd use weak self.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private func startTabBarRemotMessageTimer(message: TabBarRemoteMessage) {
tabBarRemoteMessagePopoverHoverTimer?.invalidate()
tabBarRemoteMessagePopoverHoverTimer = Timer.scheduledTimer(withTimeInterval: 1.5, repeats: false) { _ in
self.showTabBarRemotePopup(message)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with weak self

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jotaemepereira jotaemepereira force-pushed the juan/poc-new-user-feedfack-point-of-action branch from 353b532 to 8b91013 Compare December 19, 2024 15:31
@jotaemepereira jotaemepereira requested a review from ayoy December 19, 2024 18:45
@@ -47,9 +47,9 @@ final class RemoteMessagingClient: RemoteMessagingProcessing {
static let minimumConfigurationRefreshInterval: TimeInterval = 60 * 30
static let endpoint: URL = {
#if DEBUG
URL(string: "https://raw.githubusercontent.com/duckduckgo/remote-messaging-config/main/samples/ios/sample1.json")!
URL(string: "https://www.jsonblob.com/api/1316017217598578688")!
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This shouldn’t be merged; after approval, I will revert this file to the original URLs.

.padding(.bottom, 9)
}
}
.frame(width: 360)
Copy link
Collaborator Author

@jotaemepereira jotaemepereira Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Now, we only fix the width of the popover; if the text is larger, the popover should increase its height.

Copy link
Contributor

This PR has been inactive for more than 7 days and will be automatically closed 7 days from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants