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

Bugfix FXIOS-10392 [Menu] CFR's text is cut off: "Find what you need faster, fro..." (backport #22813) #22882

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public class ContextualHintView: UIView, ThemeApplicable {
label.font = FXFontStyles.Regular.headline.scaledFont()
label.textAlignment = .left
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
}

private lazy var descriptionLabel: UILabel = .build { label in
label.font = FXFontStyles.Regular.body.scaledFont()
label.textAlignment = .left
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
}

private lazy var actionButton: LinkButton = .build { button in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ class MainMenuViewController: UIViewController,
FeatureFlaggable {
private struct UX {
static let hintViewCornerRadius: CGFloat = 20
static let hintViewHeight: CGFloat = 120
static let hintViewHeight: CGFloat = 140
static let hintViewMargin: CGFloat = 20
}
typealias SubscriberStateType = MainMenuState

// MARK: - UI/UX elements
private lazy var menuContent: MenuMainView = .build()
private var hintView: ContextualHintView = .build { view in
view.isAccessibilityElement = true
}
private var hintViewHeightConstraint: NSLayoutConstraint?

// MARK: - Properties
var notificationCenter: NotificationProtocol
Expand All @@ -40,12 +44,18 @@ class MainMenuViewController: UIViewController,
private var menuState: MainMenuState
private let logger: Logger

private var hintView: ContextualHintView = .build()

let viewProvider: ContextualHintViewProvider

var currentWindowUUID: UUID? { return windowUUID }

private var isRegularSizeClass: Bool {
traitCollection.horizontalSizeClass == .regular &&
traitCollection.verticalSizeClass == .regular
}

// Used to save the last screen orientation
private var lastOrientation: UIDeviceOrientation

// MARK: - Initializers
init(
windowUUID: WindowUUID,
Expand All @@ -62,6 +72,7 @@ class MainMenuViewController: UIViewController,
menuState = MainMenuState(windowUUID: windowUUID)
viewProvider = ContextualHintViewProvider(forHintType: .mainMenu,
with: profile)
self.lastOrientation = UIDevice.current.orientation
super.init(nibName: nil, bundle: nil)

setupNotifications(forObserver: self,
Expand Down Expand Up @@ -153,8 +164,15 @@ class MainMenuViewController: UIViewController,

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { _ in
self.adjustLayout()
coordinator.animate(alongsideTransition: { [weak self] _ in
guard let self else { return }
// We should dismiss CFR when device is rotating
if UIDevice.current.orientation != lastOrientation {
lastOrientation = UIDevice.current.orientation
self.adjustLayout(isDeviceRotating: true)
} else {
self.adjustLayout()
}
}, completion: nil)
}

Expand Down Expand Up @@ -199,16 +217,27 @@ class MainMenuViewController: UIViewController,
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {
window.addSubview(hintView)
NSLayoutConstraint.activate([
hintView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: UX.hintViewMargin),
hintView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -UX.hintViewMargin),
hintView.bottomAnchor.constraint(equalTo: menuContent.accountHeaderView.topAnchor,
constant: -UX.hintViewMargin),
hintView.heightAnchor.constraint(equalToConstant: UX.hintViewHeight)
])
if isRegularSizeClass {
NSLayoutConstraint.activate([
hintView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: UX.hintViewMargin * 4),
hintView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -UX.hintViewMargin * 4),
hintView.topAnchor.constraint(equalTo: menuContent.accountHeaderView.topAnchor,
constant: UX.hintViewMargin)
])
} else {
NSLayoutConstraint.activate([
hintView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: UX.hintViewMargin),
hintView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -UX.hintViewMargin),
hintView.bottomAnchor.constraint(equalTo: menuContent.accountHeaderView.topAnchor,
constant: -UX.hintViewMargin)
])
}
hintViewHeightConstraint = hintView.heightAnchor.constraint(equalToConstant: UX.hintViewHeight)
hintViewHeightConstraint?.isActive = true
}
hintView.layer.cornerRadius = UX.hintViewCornerRadius
hintView.layer.masksToBounds = true
adjustLayout()
}

// MARK: - Redux
Expand Down Expand Up @@ -316,23 +345,39 @@ class MainMenuViewController: UIViewController,
menuA11yLabel: .MainMenu.TabsSection.AccessibilityLabels.MainMenu)
}

private func adjustLayout() {
private func adjustLayout(isDeviceRotating: Bool = false) {
menuContent.accountHeaderView.adjustLayout()
if isDeviceRotating {
hintView.removeFromSuperview()
} else {
if let screenHeight = view.window?.windowScene?.screen.bounds.height {
let maxHeight: CGFloat = if isRegularSizeClass {
view.frame.height / 2
} else {
screenHeight - view.frame.height - UX.hintViewMargin * 4
}
let height = min(UIFontMetrics.default.scaledValue(for: UX.hintViewHeight), maxHeight)
let contentSizeCategory = UIApplication.shared.preferredContentSizeCategory
hintViewHeightConstraint?.constant =
contentSizeCategory.isAccessibilityCategory ? height : UX.hintViewHeight
}
}
view.setNeedsLayout()
view.layoutIfNeeded()
}

private func shouldDisplayHintView() -> Bool {
// 1. Present hint if it was not presented before,
// 2. feature is enabled and
// 3. is not fresh install
if viewProvider.shouldPresentContextualHint() &&
featureFlags.isFeatureEnabled(.menuRefactorHint, checking: .buildOnly) {
if InstallType.get() == .fresh {
viewProvider.markContextualHintPresented()
return false
}
return true
// Don't display CFR in landscape mode for iPhones
if !isRegularSizeClass && UIDevice.current.orientation != .portrait {
return false
}

// Don't display CFR for fresh installs
if InstallType.get() == .fresh {
viewProvider.markContextualHintPresented()
return false
}
return false
return viewProvider.shouldPresentContextualHint() ? true : false
}

// MARK: - UIAdaptivePresentationControllerDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct ContextualHintEligibilityUtility: ContextualHintEligibilityUtilityProtoco
case .toolbarLocation:
hintTypeShouldBePresented = isSearchBarLocationFeatureEnabled
case .mainMenu:
hintTypeShouldBePresented = true
hintTypeShouldBePresented = canMenuCFRBePresented
case .inactiveTabs:
hintTypeShouldBePresented = true
case .shoppingExperience:
Expand All @@ -65,6 +65,14 @@ struct ContextualHintEligibilityUtility: ContextualHintEligibilityUtilityProtoco
return overlayState?.inOverlayMode ?? false
}

/// Determine if the CFR for Menu is presentable.
///
/// It's presentable on these conditions:
/// - menu-hint flag is enabled
private var canMenuCFRBePresented: Bool {
return featureFlags.isFeatureEnabled(.menuRefactorHint, checking: .buildOnly) ? true : false
}

/// If device is iPhone we present JumpBackIn and SyncTab CFRs only after Toolbar CFR has been
/// presented if the feature is enabled. If the Toolbar CFR flag is disabled or the device
/// is iPad (toolbar CFR is not presented on iPad) we bypass it
Expand Down
Loading