craft-native 0.0.135 → 0.0.136

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.135";
3306
+ var version = "0.0.136";
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.135";
313
+ var version = "0.0.136";
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.135";
61
+ var version = "0.0.136";
62
62
 
63
63
  // src/sdk-version.ts
64
64
  var SDK_VERSION = version;
@@ -535,8 +535,25 @@ final class CraftChrome: ObservableObject {
535
535
  private var occupied: CGFloat = 0
536
536
  private var pendingHide: DispatchWorkItem?
537
537
  private var splashDeadline: DispatchWorkItem?
538
+ /// The keyboard is up and covers the tab bar, so the page need not leave
539
+ /// room for it: the web view ends at the keyboard (CraftHybrid's webHost).
540
+ private var keyboardUp = false
538
541
 
539
- private init() {}
542
+ private init() {
543
+ let center = NotificationCenter.default
544
+ center.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { [weak self] _ in
545
+ self?.keyboardChanged(up: true)
546
+ }
547
+ center.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { [weak self] _ in
548
+ self?.keyboardChanged(up: false)
549
+ }
550
+ }
551
+
552
+ private func keyboardChanged(up: Bool) {
553
+ guard up != keyboardUp else { return }
554
+ keyboardUp = up
555
+ publishLayout()
556
+ }
540
557
 
541
558
  /// The tab bar from `tabs` in craft.config.json, there before the page
542
559
  /// loads; the page's own `tabBar` message replaces it later. `splash`
@@ -685,7 +702,7 @@ final class CraftChrome: ObservableObject {
685
702
  /// The bar's height as `--craft-tab-bar-height`, so the page leaves room
686
703
  /// for it, and as an event for anything that measures.
687
704
  func publishLayout() {
688
- let height = tabBarVisible ? Int(occupied) : 0
705
+ let height = tabBarVisible && !keyboardUp ? Int(occupied) : 0
689
706
  CraftHybrid.shared.tabBarCovers(CGFloat(height))
690
707
  let script = "document.documentElement.style.setProperty('--craft-tab-bar-height','\(height)px');window.dispatchEvent(new CustomEvent('craftTabBarLayout',{detail:{height:\(height)}}));"
691
708
  DispatchQueue.main.async { [weak self] in self?.webView?.evaluateJavaScript(script, completionHandler: nil) }
@@ -539,6 +539,14 @@ final class CraftHybrid: NSObject {
539
539
  }, function () { arriving = null; finish(); });
540
540
  });
541
541
  },
542
+ // Put the page at `path` in place of where it is, without a step in
543
+ // its history: the shell is back at a native screen and the page
544
+ // behind it had no history left to go back through (it reloaded).
545
+ reset: function (path) {
546
+ if (!(navigate && current && current.__craftHybrid)) { location.replace(path); return Promise.resolve(false); }
547
+ hostNav = path;
548
+ return Promise.resolve(navigate(path, { instant: true, replace: true }));
549
+ },
542
550
  setBase: function (value) { base = typeof value === 'number' ? value : null; },
543
551
  // Back to `target` in the page's stack, after the shell popped the
544
552
  // entries above it.
@@ -667,6 +675,11 @@ final class CraftHybrid: NSObject {
667
675
  webView?.evaluateJavaScript("window.__craftHybrid && window.__craftHybrid.setBase(\(value))", completionHandler: nil)
668
676
  }
669
677
 
678
+ func pageReset(to path: String) {
679
+ guard let data = try? JSONSerialization.data(withJSONObject: [path]), let json = String(data: data, encoding: .utf8) else { return }
680
+ webView?.evaluateJavaScript("window.__craftHybrid && window.__craftHybrid.reset && window.__craftHybrid.reset(\(json)[0])", completionHandler: nil)
681
+ }
682
+
670
683
  func pageBack(to depth: Int) {
671
684
  webView?.evaluateJavaScript("window.__craftHybrid && window.__craftHybrid.backTo(\(max(0, depth)))", completionHandler: nil)
672
685
  }
@@ -752,7 +765,10 @@ final class CraftHybridController: UIViewController, UINavigationControllerDeleg
752
765
 
753
766
  init(config: CraftConfig) {
754
767
  self.config = config
755
- webHost = UIHostingController(rootView: AnyView(CraftWebView(config: config).ignoresSafeArea()))
768
+ // Edge to edge, but not under the keyboard: the web view ends at its
769
+ // top. Under it, WebKit scrolled the page's layout viewport to show a
770
+ // focused field and carried every sticky header off the screen.
771
+ webHost = UIHostingController(rootView: AnyView(CraftWebView(config: config).ignoresSafeArea(.container)))
756
772
  super.init(nibName: nil, bundle: nil)
757
773
  hybrid.controller = self
758
774
  }
@@ -784,7 +800,7 @@ final class CraftHybridController: UIViewController, UINavigationControllerDeleg
784
800
  guard !webAttached else { return }
785
801
  webAttached = true
786
802
  webHost.view.backgroundColor = config.resolvedBackgroundColor
787
- if #available(iOS 16.4, *) { webHost.safeAreaRegions = [] }
803
+ if #available(iOS 16.4, *) { webHost.safeAreaRegions = [.keyboard] }
788
804
  if let slot = visibleStack?.topViewController as? CraftHybridWebSlot, slot.isViewLoaded {
789
805
  moveWeb(to: slot, in: slot.view)
790
806
  } else {
@@ -1109,6 +1125,16 @@ final class CraftHybridController: UIViewController, UINavigationControllerDeleg
1109
1125
  if let depth = removed.compactMap({ ($0 as? CraftHybridWebSlot)?.depth }).min() {
1110
1126
  hybrid.pageBack(to: depth - 1)
1111
1127
  }
1128
+ // Back at a tab's native root while the page, with no history left
1129
+ // to go back through (it reloaded on the screen just popped), still
1130
+ // shows that screen: it moves to the root's path. Left there, the
1131
+ // next screen opened from the root was pushed on top of it and named
1132
+ // it in its Back button ("Me" instead of "Today").
1133
+ if !removed.isEmpty, !(viewController is CraftHybridWebSlot), navigationController.viewControllers.first === viewController,
1134
+ let rootPath = nativePaths[ObjectIdentifier(viewController)], !rootPath.contains(":"), hybrid.pageDepth == 0,
1135
+ let pagePath = hybrid.pagePath, CraftHybridRoutes.normalize(pagePath) != CraftHybridRoutes.normalize(rootPath) {
1136
+ hybrid.pageReset(to: rootPath)
1137
+ }
1112
1138
  guard navigationController === visibleStack else { return }
1113
1139
  if let slot = viewController as? CraftHybridWebSlot { adoptWeb(into: slot) } else { parkWeb() }
1114
1140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.135",
3
+ "version": "0.0.136",
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>",