@craft-native/ios 0.0.141 → 0.0.143

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.141",
3
+ "version": "0.0.143",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/ios#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,7 @@ enum CraftNativeActions {
38
38
  private static let sqliteTransient = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
39
39
 
40
40
  static func capabilities(config: CraftConfig) -> [String] {
41
- var values = ["device", "clipboard", "haptics", "storage", "lifecycle", "fetch"]
41
+ var values = ["device", "clipboard", "haptics", "storage", "lifecycle", "fetch", "dialog"]
42
42
  if config.enableBiometric { values.append("biometric") }
43
43
  if config.enableSecureStorage { values.append("secureStorage") }
44
44
  if config.enableLocalDatabase { values.append("database") }
@@ -146,6 +146,23 @@ enum CraftNativeActions {
146
146
  }
147
147
  databaseQueue.async { complete(requestToken, database(method: method, args: args), completion) }
148
148
  return
149
+ case ("Dialog", _):
150
+ // The system's own alert, confirmation and action sheet, the same
151
+ // ones a page gets (CraftNativeUI.swift), over the native screen.
152
+ let body = args.first as? [String: Any] ?? [:]
153
+ DispatchQueue.main.async {
154
+ switch method {
155
+ case "alert":
156
+ CraftDialogs.alert(body, from: nil) { complete(requestToken, .success(NSNull()), completion) }
157
+ case "confirm":
158
+ CraftDialogs.confirm(body, from: nil) { complete(requestToken, .success($0), completion) }
159
+ case "actionSheet":
160
+ CraftDialogs.actionSheet(body, from: nil) { complete(requestToken, .success($0 ?? NSNull()), completion) }
161
+ default:
162
+ complete(requestToken, failure("UNKNOWN_ACTION", "Unsupported Dialog method"), completion)
163
+ }
164
+ }
165
+ return
149
166
  case ("Health", _):
150
167
  // Apple Health, the same as a page's `craft.health` (CraftHealth.swift).
151
168
  guard config.enableHealthKit else {
@@ -525,7 +525,7 @@ final class CraftNativeFlatList: UICollectionView, UICollectionViewDelegateFlowL
525
525
 
526
526
  private static func identity(for node: [String: Any]) -> String? {
527
527
  let props = node["props"] as? [String: Any] ?? [:]
528
- return [node["id"], node["key"], props["key"], props["testID"]]
528
+ return [node["key"], props["key"], props["testID"], node["id"]]
529
529
  .compactMap { $0 as? String }
530
530
  .first { !$0.isEmpty }
531
531
  }
@@ -1789,14 +1789,36 @@ private final class CraftNativeSvgView: UIView {
1789
1789
  }
1790
1790
  }
1791
1791
 
1792
+ /// viewBox units to the view's points, set by each draw.
1793
+ private var viewTransform = CGAffineTransform.identity
1794
+
1795
+ /// viewBox to view: centred at one scale (SVG's default, `xMidYMid meet`),
1796
+ /// or each axis stretched to fill (`preserveAspectRatio="none"`), as a
1797
+ /// chart a page sizes to its width and a fixed height asks for.
1798
+ static func transform(box: CGRect, bounds: CGSize, preserveAspectRatio: String?) -> CGAffineTransform? {
1799
+ var sx = bounds.width / box.width
1800
+ var sy = bounds.height / box.height
1801
+ var dx: CGFloat = 0
1802
+ var dy: CGFloat = 0
1803
+ if preserveAspectRatio?.trimmingCharacters(in: .whitespaces) != "none" {
1804
+ let scale = min(sx, sy)
1805
+ sx = scale
1806
+ sy = scale
1807
+ dx = (bounds.width - box.width * scale) / 2
1808
+ dy = (bounds.height - box.height * scale) / 2
1809
+ }
1810
+ guard sx.isFinite, sy.isFinite, sx > 0, sy > 0 else { return nil }
1811
+ return CGAffineTransform(translationX: dx, y: dy).scaledBy(x: sx, y: sy).translatedBy(x: -box.minX, y: -box.minY)
1812
+ }
1813
+
1792
1814
  override func draw(_ rect: CGRect) {
1793
1815
  guard let context = UIGraphicsGetCurrentContext() else { return }
1816
+ viewTransform = .identity
1794
1817
  if let box = viewBox {
1795
- let scale = min(bounds.width / box.width, bounds.height / box.height)
1796
- guard scale.isFinite, scale > 0 else { return }
1797
- context.translateBy(x: (bounds.width - box.width * scale) / 2, y: (bounds.height - box.height * scale) / 2)
1798
- context.scaleBy(x: scale, y: scale)
1799
- context.translateBy(x: -box.minX, y: -box.minY)
1818
+ let props = drawing["props"] as? [String: Any] ?? [:]
1819
+ guard let transform = CraftNativeSvgView.transform(box: box, bounds: bounds.size, preserveAspectRatio: props["preserveAspectRatio"] as? String) else { return }
1820
+ viewTransform = transform
1821
+ context.concatenate(transform)
1800
1822
  }
1801
1823
  draw(children: drawing["children"] as? [Any] ?? [], paint: Paint().merged(drawing), in: context)
1802
1824
  }
@@ -1820,12 +1842,25 @@ private final class CraftNativeSvgView: UIView {
1820
1842
  path.fill()
1821
1843
  }
1822
1844
  if let stroke = own.resolve(own.stroke), own.strokeWidth > 0 {
1845
+ // `vector-effect="non-scaling-stroke"`: the stroke is in the
1846
+ // view's points, so a stretched chart's line keeps its width
1847
+ // and a round cap stays a round dot.
1848
+ let nonScaling = (shape["props"] as? [String: Any])?["vectorEffect"] as? String == "non-scaling-stroke"
1849
+ let line: UIBezierPath
1850
+ if nonScaling, let copy = path.copy() as? UIBezierPath {
1851
+ copy.apply(viewTransform)
1852
+ context.concatenate(viewTransform.inverted())
1853
+ line = copy
1854
+ }
1855
+ else {
1856
+ line = path
1857
+ }
1823
1858
  stroke.setStroke()
1824
- path.lineWidth = own.strokeWidth
1825
- path.lineCapStyle = own.linecap == "round" ? .round : own.linecap == "square" ? .square : .butt
1826
- path.lineJoinStyle = own.linejoin == "round" ? .round : own.linejoin == "bevel" ? .bevel : .miter
1827
- if let dashes = own.dashes, !dashes.isEmpty { path.setLineDash(dashes, count: dashes.count, phase: 0) }
1828
- path.stroke()
1859
+ line.lineWidth = own.strokeWidth
1860
+ line.lineCapStyle = own.linecap == "round" ? .round : own.linecap == "square" ? .square : .butt
1861
+ line.lineJoinStyle = own.linejoin == "round" ? .round : own.linejoin == "bevel" ? .bevel : .miter
1862
+ if let dashes = own.dashes, !dashes.isEmpty { line.setLineDash(dashes, count: dashes.count, phase: 0) }
1863
+ line.stroke()
1829
1864
  }
1830
1865
  context.restoreGState()
1831
1866
  }
@@ -3493,7 +3528,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
3493
3528
  private func explicitKey(_ node: [String: Any], props: [String: Any]) -> String? {
3494
3529
  // The current @stacksjs/stx native compiler emits key in props; accept the IR
3495
3530
  // field too so keyed children keep working when the compiler adopts it.
3496
- [node["id"], node["key"], props["key"], props["testID"]]
3531
+ [node["key"], props["key"], props["testID"], node["id"]]
3497
3532
  .compactMap { $0 as? String }
3498
3533
  .first { !$0.isEmpty }
3499
3534
  }
@@ -4293,7 +4328,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
4293
4328
  view.accessibilityValue = nil
4294
4329
  }
4295
4330
  let role = props["accessibilityRole"] as? String
4296
- view.isAccessibilityElement = role != "none" && (view.accessibilityLabel != nil || role != nil || ["Text", "Button", "Link", "Image", "TextInput", "Picker", "Switch", "Slider"].contains(type))
4331
+ view.isAccessibilityElement = role != "none" && (view.accessibilityLabel != nil || role != nil || ["Text", "Button", "Link", "Image", "Video", "TextInput", "Picker", "Switch", "Slider"].contains(type))
4297
4332
  var traits: UIAccessibilityTraits = []
4298
4333
  switch role ?? type.lowercased() {
4299
4334
  case "button": traits.insert(.button)