@craft-native/ios 0.0.471 → 0.0.476

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/README.md CHANGED
@@ -342,6 +342,11 @@ needs a solid bar.
342
342
  The `backgroundColor` navigation option is shared with the Android native host;
343
343
  omitting it or passing `null` returns to the app's dynamic light/dark colour.
344
344
 
345
+ Set `titleColor` to a screen's text colour when its branded palette needs a
346
+ different navigation title contrast. Both native hosts apply it to inline and
347
+ large titles. Passing `null` restores the host's normal title colour; it does
348
+ not change the bar material, button colours, or another screen's appearance.
349
+
345
350
  The optional Liquid Glass tab-bar styling is compiler-gated for Xcode 26/Swift 6.2 and later. Older SDKs compile the same tab bar with the material fallback, so generated projects remain buildable on Xcode 16.
346
351
 
347
352
  The iOS host overlays `craft.config.json` on its defaults. Missing or `null` capability flags stay disabled; explicitly set a flag to `true` to enable it. Both the Swift host and Zig bridge reject malformed values and fall back to all capabilities disabled.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/ios",
3
- "version": "0.0.471",
3
+ "version": "0.0.476",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/ios#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -819,6 +819,7 @@ final class CraftChrome: ObservableObject {
819
819
  var image: String? = nil
820
820
  /// A compact floating icon, instead of the system full-width accessory shelf.
821
821
  var iconOnly = false
822
+ var companions: [Tab] = []
822
823
  }
823
824
 
824
825
  @Published var tabs: [Tab] = []
@@ -828,8 +829,12 @@ final class CraftChrome: ObservableObject {
828
829
  /// The visible destination may be the accessory, independently of its owning stack.
829
830
  @Published var visiblePath: String?
830
831
  var accessorySelected: Bool {
831
- guard let path = visiblePath, let accessory = tabAccessory?.id else { return false }
832
- return path == accessory || path.hasPrefix(accessory + "/")
832
+ guard let accessory = tabAccessory else { return false }
833
+ return ([accessory] + accessory.companions).contains { accessorySelected($0) }
834
+ }
835
+ func accessorySelected(_ accessory: Tab) -> Bool {
836
+ guard let path = visiblePath else { return false }
837
+ return path == accessory.id || path.hasPrefix(accessory.id + "/")
833
838
  }
834
839
  var highlightedTab: String? { accessorySelected ? nil : selected }
835
840
  let tabSwipeProgress = CraftTabSwipeProgress()
@@ -954,7 +959,14 @@ final class CraftChrome: ObservableObject {
954
959
  next = Tab(id: path, title: title, symbol: item["symbol"] as? String ?? "message",
955
960
  badge: (item["badge"] as? String).flatMap { $0.isEmpty ? nil : String($0.prefix(8)) },
956
961
  accessibilityLabel: item["accessibilityLabel"] as? String,
957
- iconOnly: item["iconOnly"] as? Bool ?? false)
962
+ iconOnly: item["iconOnly"] as? Bool ?? false,
963
+ companions: ((item["companions"] as? [[String: Any]]) ?? []).prefix(2).compactMap { action in
964
+ guard let companionPath = action["path"] as? String,
965
+ companionPath.hasPrefix("/"), !companionPath.hasPrefix("//"), companionPath != path,
966
+ let companionTitle = action["title"] as? String else { return nil }
967
+ return Tab(id: companionPath, title: companionTitle, symbol: action["symbol"] as? String ?? "circle",
968
+ accessibilityLabel: action["accessibilityLabel"] as? String, iconOnly: true)
969
+ })
958
970
  } else {
959
971
  next = nil
960
972
  }
@@ -1265,43 +1277,45 @@ private struct CraftTabBarContent: View {
1265
1277
  if !chrome.tabs.isEmpty {
1266
1278
  HStack(spacing: 8) {
1267
1279
  bar
1268
- if let accessory = chrome.tabAccessory {
1269
- Button { CraftHybrid.shared.open(accessory.id) } label: {
1270
- surface {
1271
- Image(systemName: accessory.symbol)
1272
- .font(.system(size: iconSize))
1273
- .foregroundStyle(chrome.accessorySelected ? selectedColor : Color.primary)
1274
- .frame(width: 62, height: 62)
1275
- .background {
1276
- if chrome.accessorySelected {
1277
- Circle().fill(selectedColor.opacity(0.14)).padding(4)
1280
+ if let primary = chrome.tabAccessory {
1281
+ ForEach(primary.companions + [primary]) { accessory in
1282
+ Button { CraftHybrid.shared.open(accessory.id) } label: {
1283
+ surface {
1284
+ Image(systemName: accessory.symbol)
1285
+ .font(.system(size: iconSize))
1286
+ .foregroundStyle(chrome.accessorySelected(accessory) ? selectedColor : Color.primary)
1287
+ .frame(width: 62, height: 62)
1288
+ .background {
1289
+ if chrome.accessorySelected(accessory) {
1290
+ Circle().fill(selectedColor.opacity(0.14)).padding(4)
1291
+ }
1292
+ }
1293
+ }
1294
+ .contentShape(Rectangle())
1295
+ .overlay(alignment: .topTrailing) {
1296
+ if let badge = accessory.badge {
1297
+ Text(badge)
1298
+ .font(.system(size: badgeSize, weight: .bold))
1299
+ .foregroundStyle(.white)
1300
+ .padding(.horizontal, 4)
1301
+ .frame(minWidth: 18, minHeight: 18)
1302
+ .background(Capsule().fill(Color.red))
1278
1303
  }
1279
1304
  }
1280
1305
  }
1281
- .contentShape(Rectangle())
1282
- .overlay(alignment: .topTrailing) {
1283
- if let badge = accessory.badge {
1284
- Text(badge)
1285
- .font(.system(size: badgeSize, weight: .bold))
1286
- .foregroundStyle(.white)
1287
- .padding(.horizontal, 4)
1288
- .frame(minWidth: 18, minHeight: 18)
1289
- .background(Capsule().fill(Color.red))
1290
- }
1291
- }
1292
- }
1293
- .buttonStyle(.plain)
1294
- .accessibilityShowsLargeContentViewer {
1295
- Image(systemName: accessory.symbol)
1296
- Text(accessory.accessibilityLabel ?? accessory.title)
1306
+ .buttonStyle(.plain)
1307
+ .accessibilityShowsLargeContentViewer {
1308
+ Image(systemName: accessory.symbol)
1309
+ Text(accessory.accessibilityLabel ?? accessory.title)
1310
+ }
1311
+ // Keep accessibility intent for the viewer; displayed
1312
+ // sizes come from the bounded metrics owned above.
1313
+ .environment(\.dynamicTypeSize, viewerTextSize)
1314
+ .accessibilityLabel(accessory.accessibilityLabel ?? accessory.title)
1315
+ .accessibilityValue(accessory.badge ?? "")
1316
+ .accessibilityIdentifier("craft-tab-accessory")
1317
+ .accessibilityAddTraits(chrome.accessorySelected(accessory) ? .isSelected : [])
1297
1318
  }
1298
- // Keep accessibility intent for the viewer; displayed
1299
- // sizes come from the bounded metrics owned above.
1300
- .environment(\.dynamicTypeSize, viewerTextSize)
1301
- .accessibilityLabel(accessory.accessibilityLabel ?? accessory.title)
1302
- .accessibilityValue(accessory.badge ?? "")
1303
- .accessibilityIdentifier("craft-tab-accessory")
1304
- .accessibilityAddTraits(chrome.accessorySelected ? .isSelected : [])
1305
1319
  }
1306
1320
  }
1307
1321
  .padding(.horizontal, 16)
@@ -1192,6 +1192,9 @@ final class CraftHybridController: UITabBarController, UITabBarControllerDelegat
1192
1192
  private var synchronizingTabs = false
1193
1193
  private var accessoryModel: CraftChrome.Tab?
1194
1194
  private let accessoryButton = UIButton(type: .system)
1195
+ private var companionButtons: [UIButton] = []
1196
+ private var companionModels: [CraftChrome.Tab] = []
1197
+ private var companionGlasses: [UIVisualEffectView] = []
1195
1198
  private let accessoryBadge = UILabel()
1196
1199
  private let accessoryGlass = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
1197
1200
  private static let tabPictures = NSCache<NSURL, UIImage>()
@@ -1410,6 +1413,40 @@ final class CraftHybridController: UITabBarController, UITabBarControllerDelegat
1410
1413
  private func updateSystemAccessory(hidden: Bool) {
1411
1414
  let chrome = CraftChrome.shared
1412
1415
  let model = hidden ? nil : chrome.tabAccessory
1416
+ // Keep controls when only the selected destination or unread badge changes.
1417
+ let companions = model?.iconOnly == true ? model?.companions ?? [] : []
1418
+ if companionModels != companions {
1419
+ companionModels = companions
1420
+ for button in companionButtons { button.removeFromSuperview() }
1421
+ for glass in companionGlasses { glass.removeFromSuperview() }
1422
+ companionButtons.removeAll()
1423
+ companionGlasses.removeAll()
1424
+ for action in companions {
1425
+ let button = UIButton(type: .system)
1426
+ var configuration = UIButton.Configuration.plain()
1427
+ configuration.image = UIImage(systemName: action.symbol)
1428
+ button.configuration = configuration
1429
+ button.accessibilityIdentifier = "craft-tab-companion:" + action.id
1430
+ button.accessibilityLabel = action.accessibilityLabel ?? action.title
1431
+ button.accessibilityValue = action.badge
1432
+ button.accessibilityTraits = chrome.accessorySelected(action) ? [.button, .selected] : [.button]
1433
+ button.addAction(UIAction { [weak self] _ in self?.hybrid.open(action.id) }, for: .touchUpInside)
1434
+ let glass = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
1435
+ #if compiler(>=6.2)
1436
+ if #available(iOS 26.0, *) { glass.effect = UIGlassEffect() }
1437
+ #endif
1438
+ glass.layer.cornerRadius = 24
1439
+ glass.clipsToBounds = true
1440
+ glass.isUserInteractionEnabled = false
1441
+ view.addSubview(glass)
1442
+ view.addSubview(button)
1443
+ companionGlasses.append(glass)
1444
+ companionButtons.append(button)
1445
+ }
1446
+ }
1447
+ for (index, action) in companionModels.enumerated() {
1448
+ companionButtons[index].accessibilityTraits = chrome.accessorySelected(action) ? [.button, .selected] : [.button]
1449
+ }
1413
1450
  if let model {
1414
1451
  var configuration = UIButton.Configuration.plain()
1415
1452
  configuration.image = UIImage(systemName: model.symbol)
@@ -1419,7 +1456,7 @@ final class CraftHybridController: UITabBarController, UITabBarControllerDelegat
1419
1456
  accessoryButton.configuration = configuration
1420
1457
  accessoryButton.accessibilityLabel = model.accessibilityLabel ?? model.displayTitle
1421
1458
  accessoryButton.accessibilityValue = model.badge
1422
- accessoryButton.accessibilityTraits = chrome.accessorySelected ? [.button, .selected] : [.button]
1459
+ accessoryButton.accessibilityTraits = chrome.accessorySelected(model) ? [.button, .selected] : [.button]
1423
1460
  }
1424
1461
  #if compiler(>=6.2)
1425
1462
  if #available(iOS 26.0, *), model?.iconOnly != true {
@@ -1493,6 +1530,11 @@ final class CraftHybridController: UITabBarController, UITabBarControllerDelegat
1493
1530
  let x = iconOnly ? view.bounds.maxX - view.safeAreaInsets.right - width - 20 : 16
1494
1531
  accessoryButton.frame = CGRect(x: x, y: tabBar.frame.minY - height - (iconOnly ? 8 : 0), width: width, height: height)
1495
1532
  accessoryGlass.frame = accessoryButton.frame
1533
+ for (index, button) in companionButtons.enumerated() {
1534
+ // Array order reads left to right, ending at the primary action.
1535
+ button.frame = accessoryButton.frame.offsetBy(dx: -CGFloat(companionButtons.count - index) * (width + 12), dy: 0)
1536
+ companionGlasses[index].frame = button.frame
1537
+ }
1496
1538
  let badgeWidth = max(18, accessoryBadge.intrinsicContentSize.width + 8)
1497
1539
  accessoryBadge.frame = CGRect(x: accessoryButton.frame.maxX - badgeWidth + 4, y: accessoryButton.frame.minY - 3, width: badgeWidth, height: 18)
1498
1540
  // A compact action floats over the page, not across its whole width.
@@ -7856,6 +7856,8 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
7856
7856
  /// the home indicator too, where its content never reaches: a black
7857
7857
  /// full-screen timer is black edge to edge. nil is the app's.
7858
7858
  private var screenBackgroundColor: UIColor?
7859
+ /// Title contrast belongs to this screen, independently of the bar material.
7860
+ private var navigationTitleColor: UIColor?
7859
7861
 
7860
7862
  override var preferredStatusBarStyle: UIStatusBarStyle {
7861
7863
  statusBarStyleOverride ?? .default
@@ -7926,6 +7928,9 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
7926
7928
  if let solid = options["navigationBarSolid"] as? Bool {
7927
7929
  navigationBarSolid = solid
7928
7930
  }
7931
+ if options.keys.contains("titleColor") {
7932
+ navigationTitleColor = color(options["titleColor"])
7933
+ }
7929
7934
  if let hidden = options["hidden"] as? Bool {
7930
7935
  navigationBarHidden = hidden
7931
7936
  if navigationController?.topViewController === self {
@@ -7941,7 +7946,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
7941
7946
  let buttons = (options["rightButtons"] as? [[String: Any]]) ?? []
7942
7947
  navigationItem.rightBarButtonItems = buttons.compactMap(navigationButton).reversed()
7943
7948
  }
7944
- if options.keys.contains("backgroundColor") || options.keys.contains("navigationBarSolid") {
7949
+ if options.keys.contains("backgroundColor") || options.keys.contains("navigationBarSolid") || options.keys.contains("titleColor") {
7945
7950
  applyNavigationBarAppearance()
7946
7951
  trackContentScrollView()
7947
7952
  }
@@ -7952,25 +7957,44 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
7952
7957
  }
7953
7958
  }
7954
7959
 
7955
- /// Applies the screen's optional opaque bar without changing the default
7956
- /// UIKit material when the screen did not opt in.
7960
+ /// Per-item appearances preserve each UIKit bar state and never recolour a
7961
+ /// sibling controller's title or opt a material bar into an opaque fill.
7957
7962
  private func applyNavigationBarAppearance() {
7958
- guard navigationBarSolid else {
7963
+ guard navigationBarSolid || navigationTitleColor != nil else {
7959
7964
  navigationItem.standardAppearance = nil
7960
7965
  navigationItem.scrollEdgeAppearance = nil
7961
7966
  navigationItem.compactAppearance = nil
7962
7967
  navigationItem.compactScrollEdgeAppearance = nil
7963
7968
  return
7964
7969
  }
7965
- let appearance = UINavigationBarAppearance()
7966
- appearance.configureWithOpaqueBackground()
7967
- appearance.backgroundColor = screenBackgroundColor ?? config.resolvedBackgroundColor
7968
- appearance.shadowColor = .clear
7969
- CraftChromeFonts.apply(to: appearance)
7970
- navigationItem.standardAppearance = appearance
7971
- navigationItem.scrollEdgeAppearance = appearance
7972
- navigationItem.compactAppearance = appearance
7973
- navigationItem.compactScrollEdgeAppearance = appearance
7970
+ let bar = navigationController?.navigationBar
7971
+ let standard = bar?.standardAppearance ?? UINavigationBarAppearance()
7972
+ // UIKit's unspecified scroll-edge appearance uses a transparent
7973
+ // background. Copy its standard text/button attributes before applying
7974
+ // that background so adding title contrast preserves the same states.
7975
+ let scrollEdge = bar?.scrollEdgeAppearance ?? {
7976
+ let appearance = UINavigationBarAppearance(barAppearance: standard)
7977
+ appearance.configureWithTransparentBackground()
7978
+ return appearance
7979
+ }()
7980
+ func styled(_ base: UINavigationBarAppearance) -> UINavigationBarAppearance {
7981
+ let appearance = UINavigationBarAppearance(barAppearance: base)
7982
+ if navigationBarSolid {
7983
+ appearance.configureWithOpaqueBackground()
7984
+ appearance.backgroundColor = screenBackgroundColor ?? config.resolvedBackgroundColor
7985
+ appearance.shadowColor = .clear
7986
+ }
7987
+ CraftChromeFonts.apply(to: appearance)
7988
+ if let navigationTitleColor {
7989
+ appearance.titleTextAttributes[.foregroundColor] = navigationTitleColor
7990
+ appearance.largeTitleTextAttributes[.foregroundColor] = navigationTitleColor
7991
+ }
7992
+ return appearance
7993
+ }
7994
+ navigationItem.standardAppearance = styled(standard)
7995
+ navigationItem.scrollEdgeAppearance = styled(scrollEdge)
7996
+ navigationItem.compactAppearance = styled(bar?.compactAppearance ?? standard)
7997
+ navigationItem.compactScrollEdgeAppearance = styled(bar?.compactScrollEdgeAppearance ?? scrollEdge)
7974
7998
  }
7975
7999
 
7976
8000
  private func applyStatusBar(_ props: [String: Any]) {
@@ -11444,6 +11468,17 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
11444
11468
  // UISwitch also owns its native identity and enabled/on state.
11445
11469
  // Assigning .button changes its legacy AX type into a button while
11446
11470
  // modern XCTest still identifies its UIKit class as a switch.
11471
+ // The solid variant publishes "1"/"0" as a string from
11472
+ // refreshAccessibility(). A UISwitch left to UIKit does not: the value
11473
+ // it hands XCTest arrives as a number, so every `value as? String`
11474
+ // read finds nothing. The driver's flip check is one of those reads,
11475
+ // which is why a switch that did flip was reported as never flipping,
11476
+ // and only sometimes - it depends which representation the accessibility
11477
+ // snapshot was built from. Publishing the string makes both variants
11478
+ // answer the same way. An authored accessibilityValue still wins.
11479
+ if let toggle = view as? UISwitch, !authoredAccessibilityValues.contains(id) {
11480
+ view.accessibilityValue = toggle.isOn ? "1" : "0"
11481
+ }
11447
11482
  if view is UITextView || view is UISwitch { return }
11448
11483
  if let toggle = view as? CraftNativeSolidSwitch { toggle.refreshAccessibility(); return }
11449
11484
  view.accessibilityTraits = traits
@@ -30,14 +30,22 @@ enum CraftPresenter {
30
30
  }
31
31
 
32
32
  /// Present over whatever is on screen. A controller that shows as a
33
- /// popover on iPad (an action sheet, a share sheet) points at `anchor` in
34
- /// `view`, or sits in the middle of it with no arrow; iPadOS raises an
35
- /// exception for a popover with neither. False when nothing can present,
36
- /// so the caller answers rather than waiting.
33
+ /// popover (an action sheet, a share sheet, on a regular-width screen)
34
+ /// points at `anchor` in `view`, or sits in the middle of it with no
35
+ /// arrow; iPadOS raises an exception for a popover with neither. False
36
+ /// when nothing can present, so the caller answers rather than waiting.
37
+ ///
38
+ /// Only where the presentation really is a popover. A `.actionSheet`
39
+ /// always carries a `popoverPresentationController`, phone included, and
40
+ /// from iOS 26 configuring it is enough to make the phone present the
41
+ /// sheet as a centred popover -- which silently drops its cancel action,
42
+ /// as UIKit never draws one in a popover. A compact screen is left alone
43
+ /// and gets the standard sheet, with its Cancel.
37
44
  @discardableResult
38
45
  static func present(_ controller: UIViewController, from view: UIView?, anchor: CGRect? = nil) -> Bool {
39
46
  guard let top = topViewController() else { return false }
40
- if let popover = controller.popoverPresentationController {
47
+ let asPopover = (view ?? top.view)?.traitCollection.horizontalSizeClass == .regular
48
+ if asPopover, let popover = controller.popoverPresentationController {
41
49
  let source = view ?? top.view!
42
50
  popover.sourceView = source
43
51
  if let anchor {