…lines 1–525 unchanged (525 lines)
526 if topViewController?.navigationItem.rightBarButtonItems?.first(where: { $0.tag == transfersButtonTag }) != nil {
527 return true
528 }
529 return false
530 }
531
532 /// Changes the tint color of a specific right bar button item identified by tag.
533 /// - Parameters:
534 /// - tag: The tag used to identify the UIBarButtonItem.
535 /// - color: The UIColor to be applied.
536 @MainActor
537 func setRightItemColor(tag: Int, to color: UIColor) {
538 guard
539 let items = topViewController?.navigationItem.rightBarButtonItems,
540 let item = items.first(where: { $0.tag == tag }),
541 let button = item.customView as? UIButton
542 else { return }
543
544 applyTint(button, color: color)
545 }
546
547 /// Changes the tint color of all right bar button items currently visible
548 /// in the topViewController's navigation item.
549 /// - Parameter color: The UIColor to be applied.
550 @MainActor
551 func setAllRightItemsColor(_ color: UIColor) {
552 guard let items = topViewController?.navigationItem.rightBarButtonItems else { return }
553
554 for item in items {
555 if let button = item.customView as? UIButton {
556 applyTint(button, color: color)
557 }
558 }
559 }
560
561 // MARK: - Left
562
563 func setNavigationLeftItems() async { }
564
565 /// Changes the tint color of a specific left bar button item identified by tag.
566 /// - Parameters:
567 /// - tag: The tag used to identify the UIBarButtonItem.
568 /// - color: The UIColor to be applied.
569 @MainActor
570 func setLeftItemColor(tag: Int, to color: UIColor) {
571 guard
572 let items = topViewController?.navigationItem.leftBarButtonItems,
573 let item = items.first(where: { $0.tag == tag }),
574 let button = item.customView as? UIButton
575 else { return }
576
577 applyTint(button, color: color)
578 }
579
580 /// Changes the tint color of all left bar button items currently visible
581 /// in the topViewController's navigation item.
582 /// - Parameter color: The UIColor to be applied.
583 @MainActor
584 func setAllLeftItemsColor(_ color: UIColor) {
585 guard let items = topViewController?.navigationItem.leftBarButtonItems else { return }
586
587 for item in items {
588 if let button = item.customView as? UIButton {
589 applyTint(button, color: color)
590 }
591 }
592 }
593
594 // MARK: - Tint helpers
595
596 /// Applies a tint color to a given UIButton, handling both UIButton.Configuration
597 /// and legacy setup with SF Symbols or titles.
598 /// - Parameters:
599 /// - button: The UIButton to apply the color.
600 /// - color: The UIColor to be applied.
601 @MainActor
602 private func applyTint(_ button: UIButton, color: UIColor) {
603 if var cfg = button.configuration {
604 // Se in futuro userai UIButton.Configuration, tieni il colore allineato qui
605 cfg.baseForegroundColor = color
606 button.configuration = cfg
607 } else {
608 // Config attuale (nessuna configuration): SF Symbols sono template, quindi basta tintColor
609 button.tintColor = color
610 button.setTitleColor(color, for: .normal)
611 }
612 }
613
614 /// Updates the tint color of all preloaded and currently visible right bar buttons.
615 /// - Parameter color: The UIColor to be applied to all right bar button items.
616 @MainActor
617 func updateRightBarButtonsTint(to color: UIColor) {
618 let rightButtons: [UIButton] = [
619 menuButton,
620 assistantButton,
621 notificationsButton,
622 transfersButton
623 ]
624
625 // Apply color to preloaded button instances
626 for button in rightButtons {
627 if var cfg = button.configuration {
628 cfg.baseForegroundColor = color
629 button.configuration = cfg
630 } else {
631 button.tintColor = color
632 button.setTitleColor(color, for: .normal)
633 }
634 }
635
636 // Update also those already visible in the navigation bar
637 if let rightItems = topViewController?.navigationItem.rightBarButtonItems {
638 for item in rightItems {
639 if let button = item.customView as? UIButton {
640 button.tintColor = color
641 button.setTitleColor(color, for: .normal)
642 }
643 }
644 }
645 }
646}
647