Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -61,6 +61,7 @@ class RoleErrorViewController: UIViewController {
super.viewDidLoad()

configureViews()
observeTraitChanges()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -95,6 +96,19 @@ class RoleErrorViewController: UIViewController {
configureLinkButton()
configurePrimaryActionButton()
configureSecondaryActionButton()

// Set initial image visibility based on vertical size class
imageView.isHidden = traitCollection.verticalSizeClass == .compact
}

private func observeTraitChanges() {
registerForTraitChanges([UITraitVerticalSizeClass.self, UITraitUserInterfaceStyle.self]) { (self: Self, _) in
// Hide image in compact height sizes (e.g. landscape iPhones)
// With limited space, text description should have higher priority
self.imageView.isHidden = self.traitCollection.verticalSizeClass == .compact

self.updateViewAppearances()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Should we separately register for UITraitVerticalSizeClass.self and UITraitUserInterfaceStyle.self? Also should we check against the previous trait for the UITraitUserInterfaceStyle as it was done in the previous implementation?

registerForTraitChanges([UITraitVerticalSizeClass.self]) { (self: Self, _) in
    // Hide image in compact height sizes (e.g. landscape iPhones)
    // With limited space, text description should have higher priority
    self.imageView.isHidden = self.traitCollection.verticalSizeClass == .compact

    self.updateViewAppearances()
}

registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection) in
    gaurd previousTraitCollection.hasDifferentColorAppearance(comparedTo: traitCollection) else  {
        return
    }

    // handle dynamic color appearance changes.
    updateViewAppearances()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, my change would slightly change the implementation, not just refactor from the old API. Updated de08354

}

func configureDescriptionLabel() {
Expand Down Expand Up @@ -128,24 +142,9 @@ class RoleErrorViewController: UIViewController {
}
}

// MARK: Trait Change Adjustments

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

// hide image in compact height sizes (e.g. landscape iphones).
// with limited space, text description should have higher priority.
imageView.isHidden = traitCollection.verticalSizeClass == .compact

// handle dynamic color appearance changes.
if let previousTrait = previousTraitCollection,
previousTrait.hasDifferentColorAppearance(comparedTo: traitCollection) {
updateViewAppearances()
}
}

/// update views that can adjust to color appearance changes.
/// this method is called when color appearance changes are detected in `traitCollectionDidChange`.
/// this method is called when color appearance changes are detected via trait change registration.
private func updateViewAppearances() {
// illustrations
imageView.image = viewModel.image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ final class ULAccountMismatchViewController: UIViewController {
configureSecondaryButon()

setUnifiedMargins(forWidth: view.frame.width)
observeTraitChanges()

viewModel.viewDidLoad(self)
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
setUnifiedMargins(forWidth: view.frame.width)
private func observeTraitChanges() {
registerForTraitChanges([UITraitHorizontalSizeClass.self, UITraitVerticalSizeClass.self]) { (self: Self, _) in
self.setUnifiedMargins(forWidth: self.view.frame.width)
}
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ final class ULErrorViewController: UIViewController {
configureButtonLabels()

setUnifiedMargins(forWidth: view.frame.width)
observeTraitChanges()

viewModel.viewDidLoad(self)
}
Expand All @@ -81,9 +82,10 @@ final class ULErrorViewController: UIViewController {
viewDidAppearSubject.send()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
setUnifiedMargins(forWidth: view.frame.width)
private func observeTraitChanges() {
registerForTraitChanges([UITraitHorizontalSizeClass.self, UITraitVerticalSizeClass.self]) { (self: Self, _) in
self.setUnifiedMargins(forWidth: self.view.frame.width)
}
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,13 @@ private enum Row: CaseIterable {
}

extension PrivacySettingsViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
presentURL(URL)
trackURLPresentation(URL)
return false
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
if case .link(let url) = textItem.content {
presentURL(url)
trackURLPresentation(url)
// Prevent default action
return nil
}
return defaultAction
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,13 @@ private extension SettingsViewController {
//
extension SettingsViewController: UITextViewDelegate {

func textView(_ textView: UITextView, shouldInteractWith URL: URL,
in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
weAreHiringWasPressed(url: URL)
return false
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
if case .link(let url) = textItem.content {
weAreHiringWasPressed(url: url)
// Prevent default action
return nil
}
return defaultAction
}
}

Expand Down
10 changes: 5 additions & 5 deletions WooCommerce/Classes/ViewRelated/FilterTabBar/FilterTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -518,23 +518,23 @@ private class TabBarButton: UIButton {
super.init(frame: frame)

setFont()
observeTraitChanges()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

setFont()
observeTraitChanges()
}

private func setFont() {
titleLabel?.applySubheadlineStyle()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory {
setFont()
private func observeTraitChanges() {
registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, _) in
self.setFont()
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions WooCommerce/Classes/ViewRelated/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ final class MainTabBarController: UITabBarController {
startListeningToHubMenuTabBadgeUpdates()

fixTabBarTraitCollectionOnIpadForiOS18()
observeTraitChanges()
}

private func observeTraitChanges() {
registerForTraitChanges([UITraitHorizontalSizeClass.self, UITraitVerticalSizeClass.self]) { (self: Self, _) in
self.fixTabBarTraitCollectionOnIpadForiOS18()
}
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -310,12 +317,6 @@ final class MainTabBarController: UITabBarController {

// MARK: - iPadOS 18 tabs support

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
fixTabBarTraitCollectionOnIpadForiOS18()
}


/// Force a previous bottom tab bar design on iPadOS 18 when built with Xcode 16
///
/// Override a trait collection for the tab bar controller to be compact to show the same tab layout as on iPhone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ private struct TextViewWrapper: UIViewRepresentable {
final class Coordinator: NSObject, UITextViewDelegate {
var openURL: ((URL) -> Void)?

func textView(_: UITextView, shouldInteractWith URL: URL, in _: NSRange, interaction _: UITextItemInteraction) -> Bool {
openURL?(URL)
return false
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
if case .link(let url) = textItem.content {
openURL?(url)
// Prevent default action
return nil
}
return defaultAction
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ final class TextViewTableViewCell: UITableViewCell {
}

extension TextViewTableViewCell: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if let onLinkTapped {
onLinkTapped(URL)
return false
func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
if case .link(let url) = textItem.content {
if let onLinkTapped {
onLinkTapped(url)
// Prevent default action
return nil
}
}
return true
// Allow default behavior
return defaultAction
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ final class SurveySubmittedViewController: UIViewController, SurveySubmittedView
applyStyleToComponents()
applyLocalizedTextsToComponents()
configureStackViewsAxis()
observeTraitChanges()
}

private func observeTraitChanges() {
registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, _) in
self.configureStackViewsAxis()
}
}

@IBAction private func contactUsButtonTapped(_ sender: Any) {
Expand Down Expand Up @@ -118,15 +125,6 @@ private extension SurveySubmittedViewController {
}
}

// MARK: Accessibility handling
//
extension SurveySubmittedViewController {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
configureStackViewsAxis()
}
}

// MARK: Constants
//
private extension SurveySubmittedViewController {
Expand Down
16 changes: 7 additions & 9 deletions WooCommerce/Classes/ViewRelated/Top Banner/TopBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ final class TopBannerView: UIView {
actionButtons = viewModel.actionButtons.map { _ in UIButton() }
super.init(frame: .zero)
configureSubviews(with: viewModel)
observeTraitChanges()
}

private func observeTraitChanges() {
registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, _) in
self.updateStackViewsAxis()
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -312,15 +319,6 @@ private extension TopBannerView {
}
}

// MARK: Accessibility Handling
//
extension TopBannerView {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateStackViewsAxis()
}
}

// MARK: UI Updates
//
private extension TopBannerView {
Expand Down