craft-native 0.0.176 → 0.0.177

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/dist/cli.js CHANGED
@@ -3303,7 +3303,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
3303
3303
  `);
3304
3304
  }
3305
3305
  // package.json
3306
- var version = "0.0.176";
3306
+ var version = "0.0.177";
3307
3307
 
3308
3308
  // bin/cli.ts
3309
3309
  var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
package/dist/index.cjs CHANGED
@@ -310,7 +310,7 @@ function craftBinaryNotFoundMessage(triedPath) {
310
310
  `);
311
311
  }
312
312
  // package.json
313
- var version = "0.0.176";
313
+ var version = "0.0.177";
314
314
 
315
315
  // src/sdk-version.ts
316
316
  var SDK_VERSION = version;
package/dist/index.js CHANGED
@@ -58,7 +58,7 @@ function craftBinaryNotFoundMessage(triedPath) {
58
58
  `);
59
59
  }
60
60
  // package.json
61
- var version = "0.0.176";
61
+ var version = "0.0.177";
62
62
 
63
63
  // src/sdk-version.ts
64
64
  var SDK_VERSION = version;
@@ -24,6 +24,11 @@ export type SimulatorStep = {
24
24
  } | {
25
25
  command: 'swipe';
26
26
  direction: 'up' | 'down' | 'left' | 'right';
27
+ }
28
+ /** The system back-swipe: a drag in from the left edge (or the right). */
29
+ | {
30
+ command: 'edge';
31
+ direction: 'left' | 'right';
27
32
  } | {
28
33
  command: 'tabbar';
29
34
  state: 'shown' | 'hidden';
@@ -270,14 +270,24 @@ final class CraftNativeFlatList: UICollectionView, UICollectionViewDelegateFlowL
270
270
 
271
271
  @objc private func keyboardTap() {
272
272
  guard keyboardShouldPersistTaps != "always" else { return }
273
- if keyboardShouldPersistTaps == "handled" {
274
- let point = keyboardTapGesture.location(in: self)
275
- var hit = hitTest(point, with: nil)
276
- while let view = hit, view !== self {
277
- if view is UIControl || !(view.gestureRecognizers ?? []).isEmpty { return }
278
- hit = view.superview
279
- }
273
+ let point = keyboardTapGesture.location(in: self)
274
+ var hit = hitTest(point, with: nil)
275
+ var onControl = false
276
+ var onButton = false
277
+ while let view = hit, view !== self {
278
+ if view is UIButton { onButton = true }
279
+ if view is UIControl || !(view.gestureRecognizers ?? []).isEmpty { onControl = true; break }
280
+ hit = view.superview
280
281
  }
282
+ if keyboardShouldPersistTaps == "handled", onControl { return }
283
+ // A button keeps the keyboard: its press gives the focus straight
284
+ // back. Ending editing first only let the keyboard's inset go while
285
+ // the finger was down, the button moved out from under it, and the
286
+ // press was lost.
287
+ if onButton { return }
288
+ // Otherwise the keyboard goes; after a tap on nothing, for good (the
289
+ // next render must not bring the last input back).
290
+ if !onControl { craftScreenController?.forgetFocusedInput() }
281
291
  window?.endEditing(true)
282
292
  }
283
293
 
@@ -1166,6 +1166,18 @@ enum CraftNativeFlexLayout {
1166
1166
  /// grid. It is a UIStackView in name only, so existing callers and tests keep
1167
1167
  /// `axis`, `alignment` and `arrangedSubviews`; the stack view's own
1168
1168
  /// constraints are never created, and every frame comes from `layout`.
1169
+ extension UIView {
1170
+ /// The native screen this view is drawn on, through the responder chain.
1171
+ var craftScreenController: CraftNativeScreenController? {
1172
+ var responder: UIResponder? = next
1173
+ while let current = responder {
1174
+ if let screen = current as? CraftNativeScreenController { return screen }
1175
+ responder = current.next
1176
+ }
1177
+ return nil
1178
+ }
1179
+ }
1180
+
1169
1181
  private class CraftNativeFlowView: UIStackView {
1170
1182
  var pressActiveOpacity: CGFloat?
1171
1183
  var pressBaseOpacity: CGFloat = 1
@@ -1358,6 +1370,13 @@ private class CraftNativeFlowView: UIStackView {
1358
1370
  craftApplyCornerRadius()
1359
1371
  let scale = window?.screen.scale ?? traitCollection.displayScale
1360
1372
  let result = layout(width: bounds.width, height: bounds.height, maxWidth: bounds.width, maxHeight: bounds.height, place: true)
1373
+ var moved = false
1374
+ defer {
1375
+ // The screen reports onLayout from its own layout pass, which a
1376
+ // change deep in a scroll view's content never runs: a view that
1377
+ // went from 240 to 180 wide kept saying 240.
1378
+ if moved { craftScreenController?.scheduleLayoutEvents() }
1379
+ }
1361
1380
  for (child, frame) in result.frames {
1362
1381
  var viewportFrame = frame
1363
1382
  if child === viewportChild, viewportChildFillsHeight {
@@ -1372,14 +1391,14 @@ private class CraftNativeFlowView: UIStackView {
1372
1391
  snapped.size = CraftNativeFlexLayout.ceiled(frame.size, scale: scale, atLeast: snapped.size)
1373
1392
  }
1374
1393
  if child.transform.isIdentity {
1375
- if child.frame != snapped { child.frame = snapped }
1394
+ if child.frame != snapped { child.frame = snapped; moved = true }
1376
1395
  } else {
1377
1396
  // A transformed child (a sticky header, a scaled spinner) is
1378
1397
  // placed by bounds and center: its frame is undefined then.
1379
1398
  let size = CGRect(origin: child.bounds.origin, size: snapped.size)
1380
1399
  let center = CGPoint(x: snapped.midX, y: snapped.midY)
1381
- if child.bounds != size { child.bounds = size }
1382
- if child.center != center { child.center = center }
1400
+ if child.bounds != size { child.bounds = size; moved = true }
1401
+ if child.center != center { child.center = center; moved = true }
1383
1402
  }
1384
1403
  child.craftApplyCornerRadius()
1385
1404
  }
@@ -2192,6 +2211,10 @@ private final class CraftNativeModalView: UIView {
2192
2211
 
2193
2212
  required init?(coder: NSCoder) { nil }
2194
2213
 
2214
+ /// Whether the modal takes touches is its own to say: shown, it takes
2215
+ /// every one (the scrim and its controls); the screen's press and long
2216
+ /// press bookkeeping once turned that off for a view with no handler of
2217
+ /// its own, and a shown modal let every tap through to the screen behind.
2195
2218
  func setVisible(_ visible: Bool, opacity: CGFloat, animationType: String?) {
2196
2219
  if visible { isUserInteractionEnabled = true }
2197
2220
  if renderedVisible == visible && isHidden == !visible {
@@ -2273,7 +2296,27 @@ private final class CraftNativeModalView: UIView {
2273
2296
  override func layoutSubviews() {
2274
2297
  super.layoutSubviews()
2275
2298
  blocker.frame = bounds
2276
- contentStack.frame = bounds
2299
+ // The scrim covers the whole screen; what the modal holds stays
2300
+ // clear of the bars and the home indicator it is drawn over.
2301
+ contentStack.frame = bounds.inset(by: UIEdgeInsets(top: contentInsets.top, left: 0, bottom: contentInsets.bottom, right: 0))
2302
+ }
2303
+
2304
+ /// Where the screen's own content starts and ends: the scrim covers the
2305
+ /// whole screen, what the modal holds stays clear of the bars.
2306
+ var contentInsets: UIEdgeInsets = .zero {
2307
+ didSet { if contentInsets != oldValue { setNeedsLayout() } }
2308
+ }
2309
+ }
2310
+
2311
+ /// The delegate of a Pressable's press-in/out feedback. That recognizer is
2312
+ /// a long press of no duration, so it begins the moment a finger lands; on its
2313
+ /// own it would claim the touch, and the tap that is the Pressable's onPress
2314
+ /// failed whenever onPressIn or onPressOut were set too. It only watches.
2315
+ final class CraftPressFeedbackDelegate: NSObject, UIGestureRecognizerDelegate {
2316
+ static let shared = CraftPressFeedbackDelegate()
2317
+
2318
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
2319
+ true
2277
2320
  }
2278
2321
  }
2279
2322
 
@@ -2545,14 +2588,24 @@ private final class CraftNativeScrollView: UIScrollView, UIGestureRecognizerDele
2545
2588
 
2546
2589
  @objc private func keyboardTap() {
2547
2590
  guard keyboardShouldPersistTaps != "always" else { return }
2548
- if keyboardShouldPersistTaps == "handled" {
2549
- let point = keyboardTapGesture.location(in: self)
2550
- var hit = hitTest(point, with: nil)
2551
- while let view = hit, view !== self {
2552
- if view is UIControl || !(view.gestureRecognizers ?? []).isEmpty { return }
2553
- hit = view.superview
2554
- }
2555
- }
2591
+ let point = keyboardTapGesture.location(in: self)
2592
+ var hit = hitTest(point, with: nil)
2593
+ var onControl = false
2594
+ var onButton = false
2595
+ while let view = hit, view !== self {
2596
+ if view is UIButton { onButton = true }
2597
+ if view is UIControl || !(view.gestureRecognizers ?? []).isEmpty { onControl = true; break }
2598
+ hit = view.superview
2599
+ }
2600
+ if keyboardShouldPersistTaps == "handled", onControl { return }
2601
+ // A button keeps the keyboard: its press gives the focus straight
2602
+ // back. Ending editing first only let the keyboard's inset go while
2603
+ // the finger was down, the button moved out from under it, and the
2604
+ // press was lost.
2605
+ if onButton { return }
2606
+ // Otherwise the keyboard goes; after a tap on nothing, for good (the
2607
+ // next render must not bring the last input back).
2608
+ if !onControl { craftScreenController?.forgetFocusedInput() }
2556
2609
  window?.endEditing(true)
2557
2610
  }
2558
2611
 
@@ -3056,6 +3109,13 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
3056
3109
  private var linkTargets: [ObjectIdentifier: String] = [:]
3057
3110
  private var renderedRoot: RenderedNode?
3058
3111
  private weak var lastFocusedInput: UIView?
3112
+
3113
+ /// The person put the keyboard away (Return, or a tap on nothing in a
3114
+ /// scroll view): the last input is let go. Kept, the next render or
3115
+ /// button press focused it again and the keyboard came straight back.
3116
+ func forgetFocusedInput(_ input: UIView? = nil) {
3117
+ if input == nil || lastFocusedInput === input { lastFocusedInput = nil }
3118
+ }
3059
3119
  private var flatListRows: [ObjectIdentifier: [String: RenderedNode]] = [:]
3060
3120
  private var flatListOwners: [String: String] = [:]
3061
3121
  /// A drawing's shapes are not views: a change to one redraws its `Svg`.
@@ -3192,6 +3252,10 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
3192
3252
  if !isAppScript, let routeName, !routeName.isEmpty {
3193
3253
  CraftCrashReporter.shared.screenAppeared(routeName)
3194
3254
  }
3255
+ // onLayout reports views that are on screen: a pushed screen lays
3256
+ // out before it has a window, and nothing moved again once it had
3257
+ // one, so its rows never reported.
3258
+ emitLayoutEvents()
3195
3259
  }
3196
3260
 
3197
3261
  override func viewDidDisappear(_ animated: Bool) {
@@ -3266,9 +3330,29 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
3266
3330
 
3267
3331
  override func viewDidLayoutSubviews() {
3268
3332
  super.viewDidLayoutSubviews()
3333
+ positionModals()
3269
3334
  emitLayoutEvents()
3270
3335
  }
3271
3336
 
3337
+ /// Modals cover the screen; their content starts below its bars (the
3338
+ /// status bar is all the safe area counts on a native screen, and a
3339
+ /// modal's first control sat under the navigation bar).
3340
+ private func positionModals() {
3341
+ let modals = view.subviews.compactMap { $0 as? CraftNativeModalView }
3342
+ guard !modals.isEmpty else { return }
3343
+ var insets = view.safeAreaInsets
3344
+ // The navigation bar floats over the screen without counting in its
3345
+ // safe area, and it is drawn above anything the screen adds.
3346
+ if let nav = navigationController, !nav.isNavigationBarHidden, nav.navigationBar.window != nil {
3347
+ let bar = nav.navigationBar.convert(nav.navigationBar.bounds, to: view)
3348
+ if bar.intersects(view.bounds) { insets.top = max(insets.top, bar.maxY) }
3349
+ }
3350
+ for modal in modals {
3351
+ if modal.frame != view.bounds { modal.frame = view.bounds }
3352
+ modal.contentInsets = insets
3353
+ }
3354
+ }
3355
+
3272
3356
  private static func safeJavaScriptString(_ value: JSValue?) -> String? {
3273
3357
  guard let value, !value.isUndefined, !value.isNull, value.isString else { return nil }
3274
3358
  return value.toString()
@@ -4469,6 +4553,10 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
4469
4553
  guard let target = drawnTarget(id) else { return false }
4470
4554
  guard applied.insert(target).inserted else { continue }
4471
4555
  guard let document = mutationDocument.node(target), let previous = renderedNode(target) else { return false }
4556
+ // A node that needs a new view (a TextInput turned multiline) is
4557
+ // its parent's to swap in: a targeted update only redraws in
4558
+ // place, and the new view was made and never attached.
4559
+ guard canReuseView(document, previous: previous) else { return false }
4472
4560
  let next = reconcile(document, identity: previous.identity, path: target, previous: previous)
4473
4561
  // A style patch is applied in place, layout included: the parent
4474
4562
  // reads the node's new layout style on its next pass.
@@ -4564,6 +4652,16 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
4564
4652
  return nil
4565
4653
  }
4566
4654
 
4655
+ /// Whether `previous`'s view can draw `node`: the same type, and for a
4656
+ /// TextInput the same kind of field (multiline is a UITextView).
4657
+ private func canReuseView(_ node: [String: Any], previous: RenderedNode) -> Bool {
4658
+ let type = canonicalType(node["type"] as? String ?? "View")
4659
+ guard previous.type == type else { return false }
4660
+ guard type == "TextInput" else { return true }
4661
+ let props = node["props"] as? [String: Any] ?? [:]
4662
+ return (previous.view is UITextView) == (props["multiline"] as? Bool == true)
4663
+ }
4664
+
4567
4665
  private func restoreFocus(_ focused: UIView?) {
4568
4666
  guard let focused, focused.window != nil, !focused.isFirstResponder else { return }
4569
4667
  _ = focused.becomeFirstResponder()
@@ -4576,9 +4674,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
4576
4674
  let events = node["events"] as? [String: String] ?? [:]
4577
4675
  let children = node["children"] as? [Any] ?? []
4578
4676
  let current: RenderedNode
4579
- let wantsMultilineTextView = type == "TextInput" && props["multiline"] as? Bool == true
4580
- let canReuseInput = type != "TextInput" || ((previous?.view is UITextView) == wantsMultilineTextView)
4581
- if let previous = previous, previous.identity == identity, previous.type == type, canReuseInput {
4677
+ if let previous = previous, previous.identity == identity, canReuseView(node, previous: previous) {
4582
4678
  current = previous
4583
4679
  } else {
4584
4680
  current = RenderedNode(identity: identity, type: type, view: makeView(type, props: props))
@@ -4796,6 +4892,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
4796
4892
  let modalID = ObjectIdentifier(modal)
4797
4893
  let wasVisible = modalVisibility[modalID]
4798
4894
  modalVisibility[modalID] = visible
4895
+ if visible, wasVisible != true { positionModals() }
4799
4896
  modal.setVisible(visible, opacity: number(style["opacity"]) ?? 1, animationType: props["animationType"] as? String)
4800
4897
  modal.onRequestClose = nonEmptyHandler(events["onRequestClose"]).map { handler in
4801
4898
  { [weak self] in self?.send(type: "EVENT", payload: ["handlerName": handler, "nativeEvent": [:]]) }
@@ -5199,14 +5296,18 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5199
5296
  }
5200
5297
  for child in next where child.type == "Modal" {
5201
5298
  guard let modal = child.view as? CraftNativeModalView else { continue }
5202
- if modal.superview !== stack {
5299
+ // A modal covers the screen, wherever it is declared. Laid over
5300
+ // its parent instead, one declared in a scroll view covered the
5301
+ // whole content: its controls sat wherever the content had
5302
+ // scrolled to, under the bar or off screen, out of reach.
5303
+ if modal.superview !== view {
5203
5304
  modal.removeFromSuperview()
5204
- stack.addSubview(modal)
5305
+ view.addSubview(modal)
5205
5306
  }
5206
- modal.frame = stack.bounds
5207
5307
  modal.autoresizingMask = [.flexibleWidth, .flexibleHeight]
5208
- stack.bringSubviewToFront(modal)
5308
+ view.bringSubviewToFront(modal)
5209
5309
  }
5310
+ positionModals()
5210
5311
  parent.children = next
5211
5312
  addJustificationSpacers(to: stack, value: style["justifyContent"] as? String)
5212
5313
  }
@@ -5326,7 +5427,12 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5326
5427
  }
5327
5428
  if node.view is CraftNativeSvgView, let owner = node.protocolId { svgOwners = svgOwners.filter { $0.value != owner } }
5328
5429
  let id = ObjectIdentifier(node.view)
5329
- if let modal = node.view as? CraftNativeModalView { modal.resetForTeardown() }
5430
+ if let modal = node.view as? CraftNativeModalView {
5431
+ modal.resetForTeardown()
5432
+ // It sits on the screen, not in its parent: leaving with the
5433
+ // parent's subtree does not take it away.
5434
+ modal.removeFromSuperview()
5435
+ }
5330
5436
  handlers.removeValue(forKey: id)
5331
5437
  linkTargets.removeValue(forKey: id)
5332
5438
  pressInHandlers.removeValue(forKey: id)
@@ -5401,6 +5507,20 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5401
5507
  emitLayoutEvents(for: renderedRoot)
5402
5508
  }
5403
5509
 
5510
+ private var layoutEventsScheduled = false
5511
+
5512
+ /// A view inside the screen moved: report onLayout once the pass that
5513
+ /// moved it is over, however deep it was.
5514
+ fileprivate func scheduleLayoutEvents() {
5515
+ guard !layoutEventsScheduled, !layoutHandlers.isEmpty else { return }
5516
+ layoutEventsScheduled = true
5517
+ DispatchQueue.main.async { [weak self] in
5518
+ guard let self else { return }
5519
+ self.layoutEventsScheduled = false
5520
+ self.emitLayoutEvents()
5521
+ }
5522
+ }
5523
+
5404
5524
  private func emitLayoutEvents(for node: RenderedNode) {
5405
5525
  let id = ObjectIdentifier(node.view)
5406
5526
  if let handler = layoutHandlers[id], isEffectivelyVisible(node.view) {
@@ -5463,7 +5583,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5463
5583
  }
5464
5584
  // A container keeps receiving touches without a handler of its own,
5465
5585
  // or every control inside it (and the screen root) would be dead.
5466
- if !(view is UIScrollView) { view.isUserInteractionEnabled = actionable || longPressHandlers[id] != nil || view is CraftNativeFlowView }
5586
+ if !(view is UIScrollView || view is CraftNativeModalView) { view.isUserInteractionEnabled = actionable || longPressHandlers[id] != nil || view is CraftNativeFlowView }
5467
5587
  }
5468
5588
 
5469
5589
  private func updatePressFeedback(_ pressIn: String?, _ pressOut: String?, for view: UIView) {
@@ -5472,7 +5592,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5472
5592
  if let pressOut, !pressOut.isEmpty { pressOutHandlers[id] = pressOut } else { pressOutHandlers.removeValue(forKey: id) }
5473
5593
  guard pressInHandlers[id] != nil || pressOutHandlers[id] != nil else {
5474
5594
  if let recognizer = pressFeedbackRecognizers.removeValue(forKey: id) { view.removeGestureRecognizer(recognizer) }
5475
- if !(view is UIScrollView) { view.isUserInteractionEnabled = handlers[id] != nil || linkTargets[id] != nil || longPressHandlers[id] != nil || view is CraftNativeFlowView }
5595
+ if !(view is UIScrollView || view is CraftNativeModalView) { view.isUserInteractionEnabled = handlers[id] != nil || linkTargets[id] != nil || longPressHandlers[id] != nil || view is CraftNativeFlowView }
5476
5596
  return
5477
5597
  }
5478
5598
  if pressFeedbackRecognizers[id] == nil {
@@ -5480,17 +5600,18 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5480
5600
  recognizer.minimumPressDuration = 0
5481
5601
  recognizer.allowableMovement = 10
5482
5602
  recognizer.cancelsTouchesInView = false
5603
+ recognizer.delegate = CraftPressFeedbackDelegate.shared
5483
5604
  pressFeedbackRecognizers[id] = recognizer
5484
5605
  view.addGestureRecognizer(recognizer)
5485
5606
  }
5486
- if !(view is UIScrollView) { view.isUserInteractionEnabled = true }
5607
+ if !(view is UIScrollView || view is CraftNativeModalView) { view.isUserInteractionEnabled = true }
5487
5608
  }
5488
5609
 
5489
5610
  private func updateLongPressHandler(_ handler: String?, for view: UIView) {
5490
5611
  let id = ObjectIdentifier(view)
5491
5612
  if let handler, !handler.isEmpty {
5492
5613
  longPressHandlers[id] = handler
5493
- if !(view is UIScrollView) { view.isUserInteractionEnabled = true }
5614
+ if !(view is UIScrollView || view is CraftNativeModalView) { view.isUserInteractionEnabled = true }
5494
5615
  if longPressRecognizers[id] == nil {
5495
5616
  let recognizer = UILongPressGestureRecognizer(target: self, action: #selector(viewLongPressed(_:)))
5496
5617
  longPressRecognizers[id] = recognizer
@@ -5501,7 +5622,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5501
5622
  if let recognizer = longPressRecognizers.removeValue(forKey: id) {
5502
5623
  view.removeGestureRecognizer(recognizer)
5503
5624
  }
5504
- if !(view is UIScrollView) { view.isUserInteractionEnabled = handlers[id] != nil || linkTargets[id] != nil || view is CraftNativeFlowView }
5625
+ if !(view is UIScrollView || view is CraftNativeModalView) { view.isUserInteractionEnabled = handlers[id] != nil || linkTargets[id] != nil || view is CraftNativeFlowView }
5505
5626
  }
5506
5627
  }
5507
5628
 
@@ -6116,6 +6237,8 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
6116
6237
  if state["checked"] as? Bool == true { traits.insert(.selected) }
6117
6238
  }
6118
6239
  if let control = view as? UIControl, !control.isEnabled { traits.insert(.notEnabled) }
6240
+ // A disabled Pressable or touchable takes no touches; it says so too.
6241
+ if props["disabled"] as? Bool == true { traits.insert(.notEnabled) }
6119
6242
  if type == "Checkbox", let checkbox = view as? CraftNativeCheckboxButton {
6120
6243
  if checkbox.isSelected { traits.insert(.selected) }
6121
6244
  view.accessibilityValue = checkbox.indeterminate ? "mixed" : checkbox.isSelected ? "checked" : "unchecked"
@@ -6266,13 +6389,23 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
6266
6389
  let value = snappedSliderValue(sender.value, for: sender)
6267
6390
  if sender.value != value { sender.value = value }
6268
6391
  guard let handler = handlers[ObjectIdentifier(sender)] else { return }
6269
- send(type: "EVENT", payload: ["handlerName": handler, "nativeEvent": ["value": Self.sliderEventValue(value)]])
6392
+ send(type: "EVENT", payload: ["handlerName": handler, "nativeEvent": ["value": Self.sliderEventValue(value, step: sliderSteps[ObjectIdentifier(sender)])]])
6270
6393
  }
6271
6394
 
6272
- /// A slider's value as the script reads it: the shortest decimal that is
6273
- /// the same Float, so a step of 0.1 gives 0.8 and not 0.800000011920929.
6274
- static func sliderEventValue(_ value: Float) -> Double {
6275
- Double(value.description) ?? Double(value)
6395
+ /// A slider's value as the script reads it. UISlider keeps a Float, and a
6396
+ /// step of 0.1 counted up in Floats lands beside the decimal (0.8 read as
6397
+ /// 0.800000011920929, nine steps as 0.90000004), so the value is the
6398
+ /// shortest decimal for that Float, rounded to as many places as the step
6399
+ /// has.
6400
+ static func sliderEventValue(_ value: Float, step: Float? = nil) -> Double {
6401
+ let decimal = Double(value.description) ?? Double(value)
6402
+ guard let step, step > 0, step.isFinite else { return decimal }
6403
+ // "0.1" is one place, "0.25" two, "1.0" none; a step as small as
6404
+ // "1e-07" is held to six.
6405
+ let fraction = step.description.split(separator: ".").dropFirst().first
6406
+ let places = step.description.contains("e") ? 6 : min(6, fraction.map { $0 == "0" ? 0 : $0.count } ?? 0)
6407
+ let scale = pow(10, Double(places))
6408
+ return (decimal * scale).rounded() / scale
6276
6409
  }
6277
6410
 
6278
6411
  /// `@change` on a DatePicker: the value as `<input type="date|time|
@@ -6378,7 +6511,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
6378
6511
 
6379
6512
  @objc private func sliderFinished(_ sender: UISlider) {
6380
6513
  guard let handler = sliderCompleteHandlers[ObjectIdentifier(sender)] else { return }
6381
- send(type: "EVENT", payload: ["handlerName": handler, "nativeEvent": ["value": Self.sliderEventValue(snappedSliderValue(sender.value, for: sender))]])
6514
+ send(type: "EVENT", payload: ["handlerName": handler, "nativeEvent": ["value": Self.sliderEventValue(snappedSliderValue(sender.value, for: sender), step: sliderSteps[ObjectIdentifier(sender)])]])
6382
6515
  }
6383
6516
 
6384
6517
  func numberOfComponents(in pickerView: UIPickerView) -> Int { 1 }
@@ -6423,6 +6556,8 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
6423
6556
  }
6424
6557
 
6425
6558
  @objc private func textSubmitted(_ sender: UITextField) {
6559
+ // Return put the keyboard away.
6560
+ forgetFocusedInput(sender)
6426
6561
  guard let handler = submitHandlers[ObjectIdentifier(sender)] else { return }
6427
6562
  send(type: "EVENT", payload: ["handlerName": handler, "nativeEvent": ["text": sender.text ?? ""]])
6428
6563
  }
@@ -286,6 +286,14 @@ final class DriverTests: XCTestCase {
286
286
  case "left": app.swipeLeft()
287
287
  default: app.swipeRight()
288
288
  }
289
+ case "edge":
290
+ // The system back-swipe: a drag in from the left edge (or the
291
+ // right one with `edge right`), which a centred swipe never is.
292
+ let fromRight = arg == "right"
293
+ let start = app.coordinate(withNormalizedOffset: CGVector(dx: fromRight ? 0.995 : 0.005, dy: 0.5))
294
+ let end = app.coordinate(withNormalizedOffset: CGVector(dx: fromRight ? 0.15 : 0.85, dy: 0.5))
295
+ start.press(forDuration: 0.05, thenDragTo: end)
296
+ note("edge \(fromRight ? "right" : "left"): ok")
289
297
  case "audit":
290
298
  var issues: [String] = []
291
299
  do {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.176",
3
+ "version": "0.0.177",
4
4
  "type": "module",
5
5
  "description": "Build desktop apps with web languages - TypeScript SDK for Craft",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",