@craft-native/ios 0.0.226 → 0.0.227

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/ios",
3
- "version": "0.0.226",
3
+ "version": "0.0.227",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/ios#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -616,6 +616,10 @@ final class CraftChrome: ObservableObject {
616
616
  let symbol: String
617
617
  var badge: String?
618
618
  var iconText: String? = nil
619
+ var titleOverride: String? = nil
620
+ var iconTint: String? = nil
621
+ var iconPulse = false
622
+ var displayTitle: String { titleOverride ?? title }
619
623
  var accessibilityLabel: String? = nil
620
624
  var image: String? = nil
621
625
  }
@@ -673,12 +677,21 @@ final class CraftChrome: ObservableObject {
673
677
  /// the next screen shown says again. The page's own hideTabBar is apart.
674
678
  private(set) var hiddenByScreen = false
675
679
 
676
- /// Change one tab's icon without replacing tabs, navigation stacks or selection.
680
+ /// Change one tab's caption or icon without replacing stacks or selection.
677
681
  func updateTab(_ item: [String: Any]) {
678
682
  guard let id = item["id"] as? String, let index = tabs.firstIndex(where: { $0.id == id }) else { return }
679
683
  if item.keys.contains("iconText") {
680
684
  tabs[index].iconText = (item["iconText"] as? String).flatMap { $0.isEmpty ? nil : String($0.prefix(8)) }
681
685
  }
686
+ if item.keys.contains("title") {
687
+ tabs[index].titleOverride = (item["title"] as? String).flatMap { $0.isEmpty ? nil : String($0.prefix(40)) }
688
+ }
689
+ if item.keys.contains("iconTint") {
690
+ tabs[index].iconTint = (item["iconTint"] as? String).flatMap { UIColor(hex: $0) == nil ? nil : $0 }
691
+ }
692
+ if item.keys.contains("iconPulse") {
693
+ tabs[index].iconPulse = item["iconPulse"] as? Bool ?? false
694
+ }
682
695
  if item.keys.contains("accessibilityLabel") {
683
696
  tabs[index].accessibilityLabel = (item["accessibilityLabel"] as? String).map { String($0.prefix(160)) }
684
697
  }
@@ -923,6 +936,7 @@ struct CraftTabBarView: View {
923
936
  @ObservedObject private var chrome = CraftChrome.shared
924
937
  @Namespace private var selection
925
938
  @Environment(\.accessibilityReduceMotion) private var reduceMotion
939
+ @Environment(\.scenePhase) private var scenePhase
926
940
  // Dynamic Type, relative to the styles UIKit's own bar uses. The bar is
927
941
  // capped at the largest standard size (below), as UITabBar is; past that
928
942
  // a long press shows the large content viewer instead.
@@ -1030,9 +1044,7 @@ struct CraftTabBarView: View {
1030
1044
  .minimumScaleFactor(0.7)
1031
1045
  .frame(height: iconSize + 6)
1032
1046
  } else {
1033
- Image(systemName: symbol(tab.symbol, selected: isSelected))
1034
- .font(.system(size: iconSize, weight: isSelected ? .semibold : .regular))
1035
- .frame(height: iconSize + 6)
1047
+ tabSymbol(tab, selected: isSelected)
1036
1048
  }
1037
1049
  if let badge = tab.badge {
1038
1050
  Text(badge)
@@ -1044,8 +1056,9 @@ struct CraftTabBarView: View {
1044
1056
  .offset(x: 10, y: -4)
1045
1057
  }
1046
1058
  }
1047
- Text(tab.title)
1059
+ Text(tab.displayTitle)
1048
1060
  .font(.system(size: labelSize, weight: isSelected ? .semibold : .medium))
1061
+ .monospacedDigit()
1049
1062
  .lineLimit(1)
1050
1063
  .minimumScaleFactor(0.8)
1051
1064
  }
@@ -1063,9 +1076,10 @@ struct CraftTabBarView: View {
1063
1076
  .buttonStyle(.plain)
1064
1077
  .accessibilityShowsLargeContentViewer {
1065
1078
  Image(systemName: symbol(tab.symbol, selected: isSelected))
1066
- Text(tab.title)
1079
+ Text(tab.displayTitle)
1067
1080
  }
1068
- .accessibilityLabel(tab.accessibilityLabel ?? tab.badge.map { "\(tab.title), \($0)" } ?? tab.title)
1081
+ .accessibilityIdentifier("craft-tab-\(tab.id)")
1082
+ .accessibilityLabel(tab.accessibilityLabel ?? tab.badge.map { "\(tab.displayTitle), \($0)" } ?? tab.displayTitle)
1069
1083
  .accessibilityAddTraits(isSelected ? [.isSelected, .isButton] : .isButton)
1070
1084
  }
1071
1085
  }
@@ -1075,6 +1089,20 @@ struct CraftTabBarView: View {
1075
1089
  chrome.tint.map { Color($0) } ?? Color.primary
1076
1090
  }
1077
1091
 
1092
+ /// Live styling belongs to the icon, leaving selection and the caption clear.
1093
+ @ViewBuilder private func tabSymbol(_ tab: CraftChrome.Tab, selected: Bool) -> some View {
1094
+ let color = tab.iconTint.flatMap { UIColor(hex: $0) }.map { Color($0) } ?? (selected ? selectedColor : Color.primary)
1095
+ let icon = Image(systemName: symbol(tab.symbol, selected: selected))
1096
+ .font(.system(size: iconSize, weight: selected ? .semibold : .regular))
1097
+ .foregroundStyle(color)
1098
+ .frame(height: iconSize + 6)
1099
+ if #available(iOS 17.0, *) {
1100
+ icon.symbolEffect(.pulse, options: .repeating, isActive: tab.iconPulse && !reduceMotion && scenePhase == .active)
1101
+ } else {
1102
+ icon
1103
+ }
1104
+ }
1105
+
1078
1106
  /// The filled variant for the current tab, when the symbol has one.
1079
1107
  private func symbol(_ name: String, selected: Bool) -> String {
1080
1108
  guard selected, !name.hasSuffix(".fill"), UIImage(systemName: "\(name).fill") != nil else { return name }