Skip to content

Commit

Permalink
Merge branch 'main' into removeXcodeProjects
Browse files Browse the repository at this point in the history
  • Loading branch information
mischreiber authored Sep 12, 2024
2 parents cf2c673 + 0fadbee commit 1781732
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ extension TableViewHeaderFooterViewDemoController {
}
footer?.setup(style: .footer, attributedTitle: title)

#if os(iOS)
if section.hasCustomLinkHandler {
footer?.delegate = self
}
#endif
}
footer?.titleNumberOfLines = section.numberOfLines
footer?.tokenSet.replaceAllOverrides(with: overrideTokens)
Expand Down Expand Up @@ -165,16 +163,24 @@ extension TableViewHeaderFooterViewDemoController {

// MARK: - TableViewHeaderFooterViewDemoController: TableViewHeaderFooterViewDelegate

#if os(iOS)
extension TableViewHeaderFooterViewDemoController: TableViewHeaderFooterViewDelegate {
@available (visionOS, deprecated: 1.0)
func headerFooterView(_ headerFooterView: TableViewHeaderFooterView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
let alertController = UIAlertController(title: "Link tapped", message: nil, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
return false
}

@available(iOS, introduced: 17)
func headerFooterView(_ headerFooterView: TableViewHeaderFooterView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
return UIAction { [weak self] _ in
let alertController = UIAlertController(title: "Link tapped", message: nil, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self?.present(alertController, animated: true, completion: nil)
}
}
}
#endif

extension TableViewHeaderFooterViewDemoController: DemoAppearanceDelegate {
func themeWideOverrideDidChange(isOverrideEnabled: Bool) {
Expand Down
43 changes: 35 additions & 8 deletions ios/FluentUI/Table View/TableViewHeaderFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@ import UIKit

// MARK: TableViewHeaderFooterViewDelegate

#if os(iOS)
@objc(MSFTableViewHeaderFooterViewDelegate)
public protocol TableViewHeaderFooterViewDelegate: AnyObject {
/// Returns: true if the interaction with the header view should be allowed; false if the interaction should not be allowed.
@available(iOS, deprecated: 17, message: "Replaced by primaryActionForTextItem: and menuConfigurationForTextItem: for additional customization options.")
@available(visionOS, deprecated: 1, message: "Replaced by primaryActionForTextItem: and menuConfigurationForTextItem: for additional customization options.")
@objc optional func headerFooterView(_ headerFooterView: TableViewHeaderFooterView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool

/// Asks the delegate for the action to be performed when interacting with a text item. If a nil action is provided, the text view
/// will request a menu to be presented on primary action if possible.
///
/// @param headerFooterView The `TableViewHeaderFooterView` requesting the primary action.
/// @param textItem The text item for performing said action.
/// @param defaultAction The default action for the text item. Return this to perform the default action.
///
/// @return Return a UIAction to be performed when the text item is interacted with. Return @c nil to prevent the action from being performed.
@available(iOS, introduced: 17)
@objc optional func headerFooterView(_ headerFooterView: TableViewHeaderFooterView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction?

/// Asks the delegate for the menu configuration to be performed when interacting with a text item.
///
/// @param headerFooterView The `TableViewHeaderFooterView` requesting the menu.
/// @param textItem The text item for performing said action.
/// @param defaultMenu The default menu for the specified text item.
///
/// @return Return a menu configuration to be presented when the text item is interacted with. Return @c nil to prevent the menu from being presented.
@available(iOS, introduced: 17)
@objc optional func headerFooterView(_ headerFooterView: TableViewHeaderFooterView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration?
}
#endif // os(iOS)

// MARK: - TableViewHeaderFooterView

Expand Down Expand Up @@ -125,9 +146,7 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
}
}

#if os(iOS)
@objc public weak var delegate: TableViewHeaderFooterViewDelegate?
#endif // os(iOS)

open override var intrinsicContentSize: CGSize {
return CGSize(
Expand Down Expand Up @@ -407,9 +426,7 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
open override func prepareForReuse() {
super.prepareForReuse()

#if os(iOS)
delegate = nil
#endif // os(iOS)

accessoryButtonStyle = .regular
titleNumberOfLines = 1
Expand Down Expand Up @@ -553,12 +570,22 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
// MARK: - TableViewHeaderFooterView: UITextViewDelegate

extension TableViewHeaderFooterView: UITextViewDelegate {
#if os(iOS)
@available(iOS, deprecated: 17, message: "Replaced by primaryActionForTextItem: and menuConfigurationForTextItem: for additional customization options.")
@available(visionOS, deprecated: 1, message: "Replaced by primaryActionForTextItem: and menuConfigurationForTextItem: for additional customization options.")
public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
// If the delegate function is not set, return `true` to let the default interaction handle this
return delegate?.headerFooterView?(self, shouldInteractWith: URL, in: characterRange, interaction: interaction) ?? true
}
#endif // os(iOS)

@available(iOS, introduced: 17)
public func textView(_ textView: UITextView, primaryActionFor textItem: UITextItem, defaultAction: UIAction) -> UIAction? {
return delegate?.headerFooterView?(self, primaryActionFor: textItem, defaultAction: defaultAction) ?? defaultAction
}

@available(iOS, introduced: 17)
public func textView(_ textView: UITextView, menuConfigurationFor textItem: UITextItem, defaultMenu: UIMenu) -> UITextItem.MenuConfiguration? {
return delegate?.headerFooterView?(self, menuConfigurationFor: textItem, defaultMenu: defaultMenu) ?? .init(menu: defaultMenu)
}
}

// MARK: - TableViewHeaderFooterTitleView
Expand Down
13 changes: 10 additions & 3 deletions macos/FluentUI/DatePicker/DatePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,17 @@ open class DatePickerController: NSViewController {

// In this case, we want to use Chinese numerals instead of western
// Setting dateStyle to .long before setting the dateFormat will achieve this
if calendar.identifier == .chinese && calendar.locale?.languageCode == "zh" {
formatter.dateStyle = .long
if calendar.identifier == .chinese {
let languageCode: String?
if #available(macOS 13.0, *) {
languageCode = calendar.locale?.language.languageCode?.identifier
} else {
languageCode = calendar.locale?.languageCode
}
if languageCode == "zh" {
formatter.dateStyle = .long
}
}

formatter.dateFormat = "d"

return formatter
Expand Down

0 comments on commit 1781732

Please sign in to comment.