@swiftbrowser/react 0.9.2 → 0.9.4

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
@@ -215,6 +215,20 @@ content and actions render as root-level elements while presented;
215
215
  `presentationDetents` inside a sheet sets its detents. `useDismiss()` inside
216
216
  a pushed screen or a sheet pops or dismisses it.
217
217
 
218
+ Navigation is mirrored in the browser's history by default: pushing a
219
+ screen or presenting a sheet adds an entry, and the browser's back (a
220
+ phone's edge swipe, Android's back gesture, the toolbar button) pops or
221
+ dismisses it exactly as the bar's back button would, through the app's own
222
+ state. The renderer's own swipe back ignores touch meanwhile, so the
223
+ browser's edge swipe is the swipe back (a mouse drag from the edge still
224
+ pops, since no browser navigates on one). The app popping on its own takes the history back
225
+ with it, and forward returns to the entry that matches rather than
226
+ re-pushing. The URL is left alone: an app that maps screens to paths sets
227
+ them with `history.replaceState` on the entry the renderer made (a
228
+ `pushState` of its own would add a second entry for the same screen).
229
+ `<SwiftUIView history={false}>` (or `mount(..., { history: false })`) leaves
230
+ the history untouched, for an island in a page whose own router owns it.
231
+
218
232
  ### Toolbars
219
233
 
220
234
  `ToolbarItem`'s `placement` takes SwiftUI's names. `secondaryAction` items
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { createContext, useContext, createElement, useRef, useLayoutEffect, useS
2
2
  import { DefaultEventPriority, ConcurrentRoot } from "react-reconciler/constants";
3
3
  import Reconciler from "react-reconciler";
4
4
  import { horizontalSizeClassFor } from "@swiftbrowser/web/src/protocol";
5
+ import { BrowserHistory } from "@swiftbrowser/web/src/browserHistory";
5
6
  import { Renderer } from "@swiftbrowser/web/src/renderer";
6
7
  import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
7
8
  import { applyTypeSizeVariables } from "@swiftbrowser/web/src/typography";
@@ -439,6 +440,8 @@ function mount(screen, element, options = {}) {
439
440
  renderer.setEnvironment({ colorScheme: environment.colorScheme, dynamicTypeSize: environment.dynamicTypeSize });
440
441
  if (options.safeArea !== void 0) renderer.setSafeArea(options.safeArea);
441
442
  root.setEnvironment(environment);
443
+ const browserHistory = (options.history ?? true) && typeof window !== "undefined" ? new BrowserHistory(renderer, screen) : null;
444
+ browserHistory?.enable();
442
445
  const applyScheme = () => {
443
446
  const scheme = preferred ?? pageScheme;
444
447
  const device = screen.closest(".device");
@@ -472,6 +475,7 @@ function mount(screen, element, options = {}) {
472
475
  },
473
476
  unmount() {
474
477
  observer?.disconnect();
478
+ browserHistory?.dispose();
475
479
  screen.removeEventListener("sb:color-scheme", onPreferredScheme);
476
480
  root.unmount();
477
481
  renderer?.dispose();
@@ -513,6 +517,7 @@ function SwiftUIView({
513
517
  contexts,
514
518
  assets,
515
519
  safeArea,
520
+ history = true,
516
521
  className,
517
522
  style
518
523
  }) {
@@ -530,6 +535,7 @@ function SwiftUIView({
530
535
  dynamicTypeSize,
531
536
  safeArea: insetsOf(safeArea, fit),
532
537
  contentHeight: fit === "content",
538
+ history,
533
539
  ...assets ? { assets } : {}
534
540
  });
535
541
  mounted.current = instance;
@@ -537,7 +543,7 @@ function SwiftUIView({
537
543
  mounted.current = null;
538
544
  instance.unmount();
539
545
  };
540
- }, [fit]);
546
+ }, [fit, history]);
541
547
  useLayoutEffect(() => {
542
548
  mounted.current?.root.render(tree);
543
549
  });