Skip to content
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
29 changes: 15 additions & 14 deletions Sources/FluentUI_iOS/Components/BadgeField/BadgeField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ open class BadgeField: UIView, TokenizedControl {
selectedBadgeTextField.text = Constants.emptyTextFieldString
addSubview(selectedBadgeTextField)

setupDraggingWindow()
setupDraggingWindow(frame: .zero)

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleBadgeFieldTapped(_:)))
addGestureRecognizer(tapGesture)
Expand Down Expand Up @@ -268,11 +268,15 @@ open class BadgeField: UIView, TokenizedControl {
textField.hoverStyle = nil
}

private func setupDraggingWindow() {
private func setupDraggingWindow(frame: CGRect) {
// The dragging window must be on top of any other window (keyboard, status bar etc.)
draggingWindow.windowLevel = UIWindow.Level(rawValue: .greatestFiniteMagnitude)
draggingWindow.backgroundColor = .clear
draggingWindow.isHidden = true
if let activeWindowScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
draggingWindow = UIWindow(windowScene: activeWindowScene)
}
draggingWindow?.frame = frame
draggingWindow?.windowLevel = UIWindow.Level(rawValue: .greatestFiniteMagnitude)
draggingWindow?.backgroundColor = .clear
draggingWindow?.isHidden = true
}

// MARK: Layout
Expand Down Expand Up @@ -559,7 +563,7 @@ open class BadgeField: UIView, TokenizedControl {

var draggedBadge: BadgeView?
private var draggedBadgeTouchCenterOffset: CGPoint?
private var draggingWindow = UIWindow()
private var draggingWindow: UIWindow?

/// Shows all badges when text field starts editing and resorts back to constrained badges (if originalNumberOfLines > 0) when editing ends
private var showAllBadgesForEditing: Bool = false {
Expand Down Expand Up @@ -924,7 +928,7 @@ open class BadgeField: UIView, TokenizedControl {
switch gesture.state {
case .began:
// Already dragging another badge: cancel this new gesture
if !draggingWindow.isHidden {
if draggingWindow?.isHidden == false {
cancelRunningGesture(gesture)
return
}
Expand Down Expand Up @@ -980,10 +984,10 @@ open class BadgeField: UIView, TokenizedControl {
let touchLocation = gestureRecognizer.location(in: badge)
draggedBadgeTouchCenterOffset = CGPoint(x: round(touchLocation.x - badge.frame.width / 2), y: round(touchLocation.y - badge.frame.height / 2))
// Dragging window becomes front window
draggingWindow.isHidden = false
draggingWindow?.isHidden = false
// Move dragged badge to main window
draggedBadge?.frame = convert(draggedBadge!.frame, to: containingWindow)
draggingWindow.addSubview(draggedBadge!)
draggingWindow?.addSubview(draggedBadge!)
// Animate scale
UIView.animate(withDuration: Constants.dragAndDropScaleAnimationDuration) {
self.draggedBadge!.layer.transform = CATransform3DMakeScale(Constants.dragAndDropScaleFactor, Constants.dragAndDropScaleFactor, 1)
Expand Down Expand Up @@ -1078,7 +1082,7 @@ open class BadgeField: UIView, TokenizedControl {
}

@objc private func hideDraggingWindow() {
draggingWindow.isHidden = true
draggingWindow?.isHidden = true
}

private func cancelRunningGesture(_ gesture: UIGestureRecognizer) {
Expand All @@ -1100,10 +1104,7 @@ open class BadgeField: UIView, TokenizedControl {
return
}
cancelBadgeDraggingIfNeeded()
// Reinstanciate a window with fresh orientation
draggingWindow = UIWindow()
draggingWindow.frame = containingWindow.frame
setupDraggingWindow()
setupDraggingWindow(frame: containingWindow.frame)
}
}

Expand Down
12 changes: 7 additions & 5 deletions Sources/FluentUI_iOS/Components/Navigation/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ open class NavigationBar: UINavigationBar, TokenizedControl, TwoLineTitleViewDel
private var leftBarButtonItemsObserver: NSKeyValueObservation?
private var rightBarButtonItemsObserver: NSKeyValueObservation?
private var titleObserver: NSKeyValueObservation?
#if !os(visionOS)
private var subtitle26Observer: NSKeyValueObservation?
#endif // !os(visionOS)
private var subtitleObserver: NSKeyValueObservation?
private var titleAccessoryObserver: NSKeyValueObservation?
private var titleImageObserver: NSKeyValueObservation?
Expand Down Expand Up @@ -705,12 +702,17 @@ open class NavigationBar: UINavigationBar, TokenizedControl, TwoLineTitleViewDel
titleObserver = navigationItem.observe(\UINavigationItem.title) { [unowned self] item, _ in
self.navigationItemDidUpdate(item)
}
#if os(visionOS)
subtitleObserver = navigationItem.observe(\UINavigationItem.fluentConfiguration.subtitle) { [unowned self] item, _ in
self.navigationItemDidUpdate(item)
}
#if !os(visionOS)
#else
if #available(iOS 26, macCatalyst 26, *) {
subtitle26Observer = navigationItem.observe(\UINavigationItem.subtitle) { [unowned self] item, _ in
subtitleObserver = navigationItem.observe(\UINavigationItem.subtitle) { [unowned self] item, _ in
self.navigationItemDidUpdate(item)
}
} else {
subtitleObserver = navigationItem.observe(\UINavigationItem.fluentConfiguration.subtitle) { [unowned self] item, _ in
self.navigationItemDidUpdate(item)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ extension TwoLineTitleView {
animatesWhenPressed = false
}

var subtitle: String?
#if !os(visionOS)
let subtitle: String?
#if os(visionOS)
subtitle = navigationItem.fluentConfiguration.subtitle
#else
// Prefer the UINavigationItem `.subtitle` property over the one on fluentConfiguration.
if #available(iOS 26, macCatalyst 26, *) {
subtitle = navigationItem.subtitle
}
#endif // !os(visionOS)
if subtitle == nil {
} else {
subtitle = navigationItem.fluentConfiguration.subtitle
}
#endif // !os(visionOS)

setup(title: title,
titleImage: navigationItem.fluentConfiguration.titleImage,
subtitle: navigationItem.fluentConfiguration.subtitle,
subtitle: subtitle,
alignment: alignment,
interactivePart: interactivePart,
animatesWhenPressed: animatesWhenPressed,
Expand Down
Loading