@oxyhq/bloom 0.79.1 → 0.80.0
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/lib/commonjs/scroll/index.web.js +52 -18
- package/lib/commonjs/scroll/index.web.js.map +1 -1
- package/lib/commonjs/scroll/scrollable.web.js +9 -3
- package/lib/commonjs/scroll/scrollable.web.js.map +1 -1
- package/lib/commonjs/tabs/Tabs.js +263 -63
- package/lib/commonjs/tabs/Tabs.js.map +1 -1
- package/lib/commonjs/tabs/expo-router/RouterTabs.js +215 -0
- package/lib/commonjs/tabs/expo-router/RouterTabs.js.map +1 -0
- package/lib/commonjs/tabs/expo-router/index.js +13 -0
- package/lib/commonjs/tabs/expo-router/index.js.map +1 -0
- package/lib/module/scroll/index.web.js +52 -18
- package/lib/module/scroll/index.web.js.map +1 -1
- package/lib/module/scroll/scrollable.web.js +9 -3
- package/lib/module/scroll/scrollable.web.js.map +1 -1
- package/lib/module/tabs/Tabs.js +271 -65
- package/lib/module/tabs/Tabs.js.map +1 -1
- package/lib/module/tabs/expo-router/RouterTabs.js +210 -0
- package/lib/module/tabs/expo-router/RouterTabs.js.map +1 -0
- package/lib/module/tabs/expo-router/index.js +10 -0
- package/lib/module/tabs/expo-router/index.js.map +1 -0
- package/lib/typescript/commonjs/scroll/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/scroll/scrollable.web.d.ts +18 -5
- package/lib/typescript/commonjs/scroll/scrollable.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/tabs/Tabs.d.ts +41 -1
- package/lib/typescript/commonjs/tabs/Tabs.d.ts.map +1 -1
- package/lib/typescript/commonjs/tabs/expo-router/RouterTabs.d.ts +80 -0
- package/lib/typescript/commonjs/tabs/expo-router/RouterTabs.d.ts.map +1 -0
- package/lib/typescript/commonjs/tabs/expo-router/index.d.ts +9 -0
- package/lib/typescript/commonjs/tabs/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/tabs/types.d.ts +48 -4
- package/lib/typescript/commonjs/tabs/types.d.ts.map +1 -1
- package/lib/typescript/module/scroll/index.web.d.ts.map +1 -1
- package/lib/typescript/module/scroll/scrollable.web.d.ts +18 -5
- package/lib/typescript/module/scroll/scrollable.web.d.ts.map +1 -1
- package/lib/typescript/module/tabs/Tabs.d.ts +41 -1
- package/lib/typescript/module/tabs/Tabs.d.ts.map +1 -1
- package/lib/typescript/module/tabs/expo-router/RouterTabs.d.ts +80 -0
- package/lib/typescript/module/tabs/expo-router/RouterTabs.d.ts.map +1 -0
- package/lib/typescript/module/tabs/expo-router/index.d.ts +9 -0
- package/lib/typescript/module/tabs/expo-router/index.d.ts.map +1 -0
- package/lib/typescript/module/tabs/types.d.ts +48 -4
- package/lib/typescript/module/tabs/types.d.ts.map +1 -1
- package/package.json +15 -1
- package/src/__tests__/Tabs.test.tsx +187 -0
- package/src/__tests__/optional-peer-imports.test.ts +5 -0
- package/src/__tests__/scroll-web.test.tsx +255 -2
- package/src/scroll/index.web.tsx +55 -19
- package/src/scroll/scrollable.web.ts +30 -8
- package/src/tabs/Tabs.tsx +352 -77
- package/src/tabs/expo-router/RouterTabs.tsx +268 -0
- package/src/tabs/expo-router/index.ts +8 -0
- package/src/tabs/types.ts +48 -4
|
@@ -165,22 +165,51 @@ function useScrollRestoration(target, options) {
|
|
|
165
165
|
// than what the scroll listener already saved live.
|
|
166
166
|
let lastObservedOffset = null;
|
|
167
167
|
|
|
168
|
-
// The
|
|
169
|
-
// event (jsdom does not, so the
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
168
|
+
// The offset WE last wrote, which a real browser dispatches back as a
|
|
169
|
+
// `scroll` event (jsdom does not, so the tests for this emit it
|
|
170
|
+
// explicitly). Both writers arm it: the reset, and every frame of the
|
|
171
|
+
// restore loop. Persisting either records an offset the user never
|
|
172
|
+
// chose — the reset's 0 under a key another LIVE screen may share (the
|
|
173
|
+
// two-live-entries trade content keying makes, see `deriveScrollKey`),
|
|
174
|
+
// and the loop's intermediate value as a PARTIAL that outlives an
|
|
175
|
+
// interrupted restore.
|
|
176
|
+
//
|
|
177
|
+
// A `restoring` FLAG covering the loop's duration is the obvious
|
|
178
|
+
// alternative and is wrong. It could only be cleared by a takeover
|
|
179
|
+
// event, so a session whose scroll came from a source that fires none —
|
|
180
|
+
// `scrollIntoView` from another component, a focus-driven scroll — would
|
|
181
|
+
// suppress saves indefinitely and never record the user's position at
|
|
182
|
+
// all: an unbounded corruption traded for a bounded one. Arming a VALUE
|
|
183
|
+
// is bounded to one event per write and covers every way the loop can
|
|
184
|
+
// end (stuck, capped, aborted), because each frame re-arms.
|
|
175
185
|
let echoOffset = null;
|
|
186
|
+
|
|
187
|
+
// The largest offset reachable when we last PERSISTED one. A browser
|
|
188
|
+
// clamp is recognised against this rather than against the previous
|
|
189
|
+
// OBSERVATION, and that distinction is the whole mechanism: Chrome
|
|
190
|
+
// dispatches TWO `scroll` events for one clamp, so an
|
|
191
|
+
// observation-relative test sees the shrink on the first and nothing on
|
|
192
|
+
// the second, which then saves the clamped value anyway. Measured.
|
|
193
|
+
let maxOffsetAtLastSave = scroller.getMaxOffset();
|
|
176
194
|
const save = () => {
|
|
177
195
|
const offset = scroller.getOffset();
|
|
196
|
+
const maxOffset = scroller.getMaxOffset();
|
|
178
197
|
// Ignore a spurious 0 produced by the navigator collapsing a hidden
|
|
179
198
|
// background screen: while collapsed the container cannot scroll, so
|
|
180
199
|
// its `scrollTop` is forced to 0. Persisting it would clobber the good
|
|
181
200
|
// offset recorded by earlier live saves (problem A). A genuine
|
|
182
201
|
// scroll-to-top keeps the container scrollable and is saved normally.
|
|
183
|
-
if (offset === 0 &&
|
|
202
|
+
if (offset === 0 && maxOffset <= 0) return;
|
|
203
|
+
// A partial clamp: the reachable range SHRANK and the offset is sitting
|
|
204
|
+
// exactly at the new bottom. That is what the browser does to a tab
|
|
205
|
+
// whose document has been taken over by a shorter sibling — the two
|
|
206
|
+
// together are a signature a genuine scroll does not have, because
|
|
207
|
+
// reaching the bottom on your own does not shrink the page in the same
|
|
208
|
+
// breath. Suppressing keeps the pre-clamp offset, which on return
|
|
209
|
+
// simply clamps to the same place if the content really did shrink.
|
|
210
|
+
if (maxOffset < maxOffsetAtLastSave && Math.abs(offset - maxOffset) <= RESTORE_STICK_TOLERANCE_PX) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
184
213
|
if (offset === echoOffset) {
|
|
185
214
|
// Our own write coming back. Consume the arming so a real scroll to
|
|
186
215
|
// the same offset later is saved normally.
|
|
@@ -189,6 +218,7 @@ function useScrollRestoration(target, options) {
|
|
|
189
218
|
}
|
|
190
219
|
echoOffset = null;
|
|
191
220
|
lastObservedOffset = offset;
|
|
221
|
+
maxOffsetAtLastSave = maxOffset;
|
|
192
222
|
store.save(scrollKey, offset);
|
|
193
223
|
};
|
|
194
224
|
|
|
@@ -228,22 +258,26 @@ function useScrollRestoration(target, options) {
|
|
|
228
258
|
// single write while it is still collapsed would be clamped to 0 and
|
|
229
259
|
// never re-applied (problem B).
|
|
230
260
|
//
|
|
231
|
-
//
|
|
232
|
-
// `
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
// leaves the CLAMPED offset stored — which is the right thing to
|
|
237
|
-
// remember when the content genuinely shrank, since that is as far as
|
|
238
|
-
// the user can now scroll.
|
|
261
|
+
// Every write the loop makes is suppressed from the save path (see
|
|
262
|
+
// `echoOffset` below), so an interrupted restore leaves the ORIGINAL
|
|
263
|
+
// target stored rather than a partial. Nothing is lost on the success
|
|
264
|
+
// path: `targetOffset` came out of the store, so persisting it again
|
|
265
|
+
// would write back the same number.
|
|
239
266
|
let framesLeft = RESTORE_FRAME_CAP;
|
|
240
267
|
const applyOffset = () => {
|
|
241
268
|
rafId = null;
|
|
242
269
|
scroller.setOffset(targetOffset);
|
|
243
270
|
framesLeft -= 1;
|
|
271
|
+
// `getOffset` re-reads the value the browser actually took, which is
|
|
272
|
+
// clamped to the content height it has reached so far. Arm it as the
|
|
273
|
+
// echo to swallow: this write is about to come back as a `scroll`
|
|
274
|
+
// event, and persisting a PARTIAL offset we wrote ourselves is how a
|
|
275
|
+
// restore that is aborted or capped corrupts the stored position.
|
|
276
|
+
const landed = scroller.getOffset();
|
|
277
|
+
echoOffset = landed;
|
|
244
278
|
// Stop once the write took effect (content grew tall enough) or we
|
|
245
|
-
// exhaust the frame budget.
|
|
246
|
-
const reached = Math.abs(
|
|
279
|
+
// exhaust the frame budget.
|
|
280
|
+
const reached = Math.abs(landed - targetOffset) <= RESTORE_STICK_TOLERANCE_PX;
|
|
247
281
|
if (!reached && framesLeft > 0) {
|
|
248
282
|
rafId = requestAnimationFrame(applyOffset);
|
|
249
283
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_context","_scrollableWeb","_store","RESTORE_FRAME_CAP","RESTORE_STICK_TOLERANCE_PX","WEB_BINDING","onScroll","undefined","USER_TAKEOVER_EVENTS","useScrollRestoration","target","options","store","adapter","useScrollRestorationContext","contentId","useScreenContentId","enabled","scrollKey","deriveScrollKey","key","resetKeyRef","useRef","useScreenFocusEffect","useCallback","scroller","createScroller","element","window","resolveScrollEventTarget","lastObservedOffset","echoOffset","save","offset","getOffset","
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_scrollableWeb","_store","RESTORE_FRAME_CAP","RESTORE_STICK_TOLERANCE_PX","WEB_BINDING","onScroll","undefined","USER_TAKEOVER_EVENTS","useScrollRestoration","target","options","store","adapter","useScrollRestorationContext","contentId","useScreenContentId","enabled","scrollKey","deriveScrollKey","key","resetKeyRef","useRef","useScreenFocusEffect","useCallback","scroller","createScroller","element","window","resolveScrollEventTarget","lastObservedOffset","echoOffset","maxOffsetAtLastSave","getMaxOffset","save","offset","getOffset","maxOffset","Math","abs","targetOffset","read","isReset","has","alreadyReset","current","rafId","stopRestore","cancelAnimationFrame","setOffset","requestAnimationFrame","framesLeft","applyOffset","landed","reached","type","addEventListener","passive","removeEventListener","EventTarget","handle","getScrollableNode","node"],"sourceRoot":"../../../src","sources":["scroll/index.web.tsx"],"mappings":";;;;;;;;;;;;AAwCA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AA5CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,iBAAiB,GAAG,EAAE;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,0BAA0B,GAAG,CAAC;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAqC,GAAG;EAAEC,QAAQ,EAAEA,CAAA,KAAMC;AAAU,CAAC;;AAE3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,CAAC;;AAE9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAClCC,MAA+B,EAC/BC,OAAqC,EACX;EAC1B,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAAC,oCAA2B,EAAC,CAAC;EACxD,MAAMC,SAAS,GAAGF,OAAO,CAACG,kBAAkB,CAAC,CAAC;EAC9C,MAAMC,OAAO,GAAGN,OAAO,EAAEM,OAAO,IAA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EAAE,OAAO,IAAI;EAChC,IAAI,OAAOc,WAAW,KAAK,WAAW,IAAId,OAAO,YAAYc,WAAW,EAAE;IACxE,OAAOd,OAAO;EAChB;EACA,MAAMe,MAAM,GAAGf,OAAgD;EAC/D,IAAI,OAAOe,MAAM,CAACC,iBAAiB,KAAK,UAAU,EAAE;IAClD,MAAMC,IAAI,GAAGF,MAAM,CAACC,iBAAiB,CAAC,CAAC;IACvC,IAAI,OAAOF,WAAW,KAAK,WAAW,IAAIG,IAAI,YAAYH,WAAW,EAAE;MACrE,OAAOG,IAAI;IACb;EACF;EACA,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -48,7 +48,12 @@ function createScroller(target) {
|
|
|
48
48
|
setOffset: offset => {
|
|
49
49
|
if (typeof window !== 'undefined') window.scrollTo(0, offset);
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
getMaxOffset: () => {
|
|
52
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
return Math.max(0, document.documentElement.scrollHeight - window.innerHeight);
|
|
56
|
+
}
|
|
52
57
|
};
|
|
53
58
|
}
|
|
54
59
|
return {
|
|
@@ -60,9 +65,10 @@ function createScroller(target) {
|
|
|
60
65
|
const element = resolveElement(target);
|
|
61
66
|
if (element) element.scrollTop = offset;
|
|
62
67
|
},
|
|
63
|
-
|
|
68
|
+
getMaxOffset: () => {
|
|
64
69
|
const element = resolveElement(target);
|
|
65
|
-
|
|
70
|
+
if (!element) return 0;
|
|
71
|
+
return Math.max(0, element.scrollHeight - element.clientHeight);
|
|
66
72
|
}
|
|
67
73
|
};
|
|
68
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isElement","value","HTMLElement","hasGetScrollableNode","getScrollableNode","resolveElement","target","current","node","createScroller","getOffset","window","scrollY","setOffset","offset","scrollTo","
|
|
1
|
+
{"version":3,"names":["isElement","value","HTMLElement","hasGetScrollableNode","getScrollableNode","resolveElement","target","current","node","createScroller","getOffset","window","scrollY","setOffset","offset","scrollTo","getMaxOffset","document","Math","max","documentElement","scrollHeight","innerHeight","element","scrollTop","clientHeight"],"sourceRoot":"../../../src","sources":["scroll/scrollable.web.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;;AA+BA,SAASA,SAASA,CAACC,KAAc,EAAwB;EACvD,OAAO,OAAOC,WAAW,KAAK,WAAW,IAAID,KAAK,YAAYC,WAAW;AAC3E;AAEA,SAASC,oBAAoBA,CAC3BF,KAAc,EACkD;EAChE,OACE,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAAsBG,iBAAiB,KAAK,UAAU;AAEvE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAACC,MAA+B,EAAsB;EAC3E,IAAIA,MAAM,KAAK,QAAQ,EAAE,OAAO,IAAI;EAEpC,MAAMC,OAAO,GAAID,MAAM,CAA0BC,OAAO;EACxD,IAAIA,OAAO,IAAI,IAAI,EAAE,OAAO,IAAI;EAEhC,IAAIP,SAAS,CAACO,OAAO,CAAC,EAAE,OAAOA,OAAO;EAEtC,IAAIJ,oBAAoB,CAACI,OAAO,CAAC,EAAE;IACjC,MAAMC,IAAI,GAAGD,OAAO,CAACH,iBAAiB,CAAC,CAAC;IACxC,IAAIJ,SAAS,CAACQ,IAAI,CAAC,EAAE,OAAOA,IAAI;EAClC;EAEA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAACH,MAA+B,EAAoB;EAChF,IAAIA,MAAM,KAAK,QAAQ,EAAE;IACvB,OAAO;MACLI,SAAS,EAAEA,CAAA,KAAO,OAAOC,MAAM,KAAK,WAAW,GAAG,CAAC,GAAGA,MAAM,CAACC,OAAQ;MACrEC,SAAS,EAAGC,MAAM,IAAK;QACrB,IAAI,OAAOH,MAAM,KAAK,WAAW,EAAEA,MAAM,CAACI,QAAQ,CAAC,CAAC,EAAED,MAAM,CAAC;MAC/D,CAAC;MACDE,YAAY,EAAEA,CAAA,KAAM;QAClB,IAAI,OAAOL,MAAM,KAAK,WAAW,IAAI,OAAOM,QAAQ,KAAK,WAAW,EAAE;UACpE,OAAO,CAAC;QACV;QACA,OAAOC,IAAI,CAACC,GAAG,CACb,CAAC,EACDF,QAAQ,CAACG,eAAe,CAACC,YAAY,GAAGV,MAAM,CAACW,WACjD,CAAC;MACH;IACF,CAAC;EACH;EAEA,OAAO;IACLZ,SAAS,EAAEA,CAAA,KAAM;MACf,MAAMa,OAAO,GAAGlB,cAAc,CAACC,MAAM,CAAC;MACtC,OAAOiB,OAAO,GAAGA,OAAO,CAACC,SAAS,GAAG,CAAC;IACxC,CAAC;IACDX,SAAS,EAAGC,MAAM,IAAK;MACrB,MAAMS,OAAO,GAAGlB,cAAc,CAACC,MAAM,CAAC;MACtC,IAAIiB,OAAO,EAAEA,OAAO,CAACC,SAAS,GAAGV,MAAM;IACzC,CAAC;IACDE,YAAY,EAAEA,CAAA,KAAM;MAClB,MAAMO,OAAO,GAAGlB,cAAc,CAACC,MAAM,CAAC;MACtC,IAAI,CAACiB,OAAO,EAAE,OAAO,CAAC;MACtB,OAAOL,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEI,OAAO,CAACF,YAAY,GAAGE,OAAO,CAACE,YAAY,CAAC;IACjE;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -6,83 +6,227 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.TabsTrigger = exports.TabsContent = exports.Tabs = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
9
10
|
var _useTheme = require("../theme/use-theme.js");
|
|
10
11
|
var _usePressAnimation = require("../hooks/usePressAnimation.js");
|
|
11
12
|
var _tokens = require("../styles/tokens.js");
|
|
12
13
|
var _shadows = require("../design-tokens/shadows");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Underline travel. The same spring the floating `TabBar` highlight uses, so the
|
|
18
|
+
* two strips read as one motion language; stated here rather than imported
|
|
19
|
+
* because they are separate component families and a shared constant would tie
|
|
20
|
+
* their feel together permanently.
|
|
21
|
+
*/
|
|
22
|
+
const SLIDE_SPRING = {
|
|
23
|
+
duration: 420,
|
|
24
|
+
dampingRatio: 0.82
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Visibility, not travel — see {@link TabsContextValue.indicatorOpacity}. */
|
|
28
|
+
const HIGHLIGHT_FADE = {
|
|
29
|
+
duration: 160
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fraction of the distance to the neighbour a drag must cover before releasing
|
|
34
|
+
* commits. Below it the underline springs home and nothing navigates.
|
|
35
|
+
*/
|
|
36
|
+
const COMMIT_THRESHOLD = 0.4;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* How far the underline may stray past the first/last tab, and how heavily that
|
|
40
|
+
* travel is damped. A rubber-band is reserved for the edge, where "there is
|
|
41
|
+
* nothing there" is the true message; used anywhere else it would promise a
|
|
42
|
+
* neighbour that is about to arrive, which is the opposite of what happens.
|
|
43
|
+
*/
|
|
44
|
+
const EDGE_RUBBER_BAND_DAMPING = 0.25;
|
|
45
|
+
const EDGE_RUBBER_BAND_MAX = 32;
|
|
46
|
+
|
|
47
|
+
/** Above this the count renders as "99+", so a large tally cannot stretch a tab. */
|
|
48
|
+
const MAX_DISPLAYED_COUNT = 99;
|
|
49
|
+
function formatCount(count) {
|
|
50
|
+
return count > MAX_DISPLAYED_COUNT ? `${MAX_DISPLAYED_COUNT}+` : String(count);
|
|
51
|
+
}
|
|
52
|
+
const TabsContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The imperative surface a horizontal drag gesture drives the underline through.
|
|
56
|
+
*
|
|
57
|
+
* It lives here rather than in the gesture's own code because every quantity the
|
|
58
|
+
* drag needs — where the neighbouring trigger is, how wide it is, whether there
|
|
59
|
+
* IS a neighbour — is measured layout the strip already holds and nothing
|
|
60
|
+
* outside it can see. The gesture supplies one number, the finger's delta; the
|
|
61
|
+
* strip decides what that means.
|
|
62
|
+
*
|
|
63
|
+
* Obtained via a `ref` on `Tabs`. The gesture belongs in the LAYOUT beside the
|
|
64
|
+
* strip, never inside a tab screen — a gesture mounted in a screen is destroyed
|
|
65
|
+
* by the navigation it commits, mid-release.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
function useTabsContext(component) {
|
|
69
|
+
const ctx = (0, _react.useContext)(TabsContext);
|
|
70
|
+
if (!ctx) {
|
|
71
|
+
throw new Error(`${component} must be used within a Tabs`);
|
|
72
|
+
}
|
|
73
|
+
return ctx;
|
|
74
|
+
}
|
|
75
|
+
const TabsBarComponent = /*#__PURE__*/(0, _react.forwardRef)(function TabsBar({
|
|
23
76
|
value,
|
|
24
77
|
onValueChange,
|
|
78
|
+
hasSelection = true,
|
|
25
79
|
variant = 'underline',
|
|
26
80
|
fullWidth = false,
|
|
27
81
|
children,
|
|
28
82
|
style,
|
|
29
83
|
testID
|
|
30
|
-
})
|
|
84
|
+
}, dragRef) {
|
|
31
85
|
const theme = (0, _useTheme.useTheme)();
|
|
32
86
|
const isUnderline = variant === 'underline';
|
|
33
87
|
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
88
|
+
// One shared underline that translates + resizes between triggers. Triggers
|
|
89
|
+
// report their measured {x, width}; whoever owns the selection drives these
|
|
90
|
+
// shared values IMPERATIVELY, and `useAnimatedStyle` below only ever READS
|
|
91
|
+
// them. That split is what makes the animation work on web, where returning
|
|
92
|
+
// an animation from inside a mapper silently does nothing.
|
|
93
|
+
const indicatorX = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
94
|
+
const indicatorWidth = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
95
|
+
// Starts hidden: a strip whose active trigger has not been measured yet must
|
|
96
|
+
// not flash an underline at the origin on its first frame.
|
|
97
|
+
const indicatorOpacity = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
98
|
+
// Live drag, added to the settled position/width rather than replacing them,
|
|
99
|
+
// so a release can fold the delta into the base without a visible jump.
|
|
100
|
+
const dragOffset = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
101
|
+
const dragWidthDelta = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
39
102
|
const triggerLayoutsRef = (0, _react.useRef)({});
|
|
40
103
|
const indicatorPlacedRef = (0, _react.useRef)(false);
|
|
104
|
+
const scrollRef = (0, _react.useRef)(null);
|
|
105
|
+
const viewportWidthRef = (0, _react.useRef)(0);
|
|
106
|
+
// The value the underline currently belongs to, from EITHER path. A ref
|
|
107
|
+
// because the layout callback below must see the latest selection without
|
|
108
|
+
// being re-created — and therefore re-firing — on every selection change.
|
|
109
|
+
const selectedValueRef = (0, _react.useRef)(value);
|
|
41
110
|
const moveIndicator = (0, _react.useCallback)((target, animate) => {
|
|
42
111
|
if (animate) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
duration: 200,
|
|
46
|
-
easing: _reactNative.Easing.out(_reactNative.Easing.cubic),
|
|
47
|
-
useNativeDriver: false
|
|
48
|
-
}), _reactNative.Animated.timing(indicatorWidth, {
|
|
49
|
-
toValue: target.width,
|
|
50
|
-
duration: 200,
|
|
51
|
-
easing: _reactNative.Easing.out(_reactNative.Easing.cubic),
|
|
52
|
-
useNativeDriver: false
|
|
53
|
-
})]).start();
|
|
112
|
+
indicatorX.value = (0, _reactNativeReanimated.withSpring)(target.x, SLIDE_SPRING);
|
|
113
|
+
indicatorWidth.value = (0, _reactNativeReanimated.withSpring)(target.width, SLIDE_SPRING);
|
|
54
114
|
} else {
|
|
55
|
-
indicatorX.
|
|
56
|
-
indicatorWidth.
|
|
115
|
+
indicatorX.value = target.x;
|
|
116
|
+
indicatorWidth.value = target.width;
|
|
57
117
|
}
|
|
58
|
-
|
|
118
|
+
indicatorOpacity.value = (0, _reactNativeReanimated.withTiming)(1, HIGHLIGHT_FADE);
|
|
119
|
+
}, [indicatorX, indicatorWidth, indicatorOpacity]);
|
|
120
|
+
|
|
121
|
+
// Keep the active tab in view when the strip overflows its viewport. Centring
|
|
122
|
+
// is what makes a ROUTED strip usable: arriving at a tab that is scrolled out
|
|
123
|
+
// of sight — via a deep link, a Back, or simply a long tab set — must not
|
|
124
|
+
// look like an empty selection.
|
|
125
|
+
const revealTrigger = (0, _react.useCallback)((target, animate) => {
|
|
126
|
+
const viewport = viewportWidthRef.current;
|
|
127
|
+
if (fullWidth || viewport <= 0) return;
|
|
128
|
+
const centred = target.x + target.width / 2 - viewport / 2;
|
|
129
|
+
scrollRef.current?.scrollTo({
|
|
130
|
+
x: Math.max(0, centred),
|
|
131
|
+
animated: animate
|
|
132
|
+
});
|
|
133
|
+
}, [fullWidth]);
|
|
134
|
+
const applySelection = (0, _react.useCallback)(tabValue => {
|
|
135
|
+
const target = triggerLayoutsRef.current[tabValue];
|
|
136
|
+
// Not measured yet — `reportTriggerLayout` places it on arrival.
|
|
137
|
+
if (!target) return;
|
|
138
|
+
const animate = indicatorPlacedRef.current;
|
|
139
|
+
moveIndicator(target, animate);
|
|
140
|
+
revealTrigger(target, animate);
|
|
141
|
+
indicatorPlacedRef.current = true;
|
|
142
|
+
}, [moveIndicator, revealTrigger]);
|
|
59
143
|
const reportTriggerLayout = (0, _react.useCallback)((tabValue, layout) => {
|
|
60
144
|
triggerLayoutsRef.current[tabValue] = layout;
|
|
61
|
-
// Snap onto the active trigger the moment it
|
|
145
|
+
// Snap onto the active trigger the moment it is first measured (mount), or
|
|
62
146
|
// when its size changes — never slide in from the origin.
|
|
63
|
-
if (tabValue ===
|
|
147
|
+
if (tabValue === selectedValueRef.current) {
|
|
64
148
|
moveIndicator(layout, false);
|
|
149
|
+
revealTrigger(layout, false);
|
|
65
150
|
indicatorPlacedRef.current = true;
|
|
66
151
|
}
|
|
67
|
-
}, [
|
|
152
|
+
}, [moveIndicator, revealTrigger]);
|
|
153
|
+
const reportFocused = (0, _react.useCallback)(tabValue => {
|
|
154
|
+
selectedValueRef.current = tabValue;
|
|
155
|
+
applySelection(tabValue);
|
|
156
|
+
}, [applySelection]);
|
|
68
157
|
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
// (external-system sync)
|
|
158
|
+
// CONTROLLED path only: the bar owns the underline when `value` is provided.
|
|
159
|
+
// Syncing an imperative animation to a controlled prop is a legitimate effect
|
|
160
|
+
// (external-system sync). On the focus-driven path each trigger reports
|
|
161
|
+
// instead, so this stays out of the way and there is only ever one writer.
|
|
72
162
|
(0, _react.useEffect)(() => {
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
163
|
+
if (value === undefined) return;
|
|
164
|
+
selectedValueRef.current = value;
|
|
165
|
+
applySelection(value);
|
|
166
|
+
}, [value, applySelection]);
|
|
167
|
+
|
|
168
|
+
// Nothing is focused — fade out where it stands. Position is deliberately
|
|
169
|
+
// untouched: see `TabsProps.hasSelection`. Placing this AFTER the controlled
|
|
170
|
+
// effect is what lets a later re-selection snap back rather than travel,
|
|
171
|
+
// because `indicatorPlacedRef` is left alone here.
|
|
172
|
+
(0, _react.useEffect)(() => {
|
|
173
|
+
if (hasSelection) return;
|
|
174
|
+
indicatorOpacity.value = (0, _reactNativeReanimated.withTiming)(0, HIGHLIGHT_FADE);
|
|
175
|
+
}, [hasSelection, indicatorOpacity]);
|
|
176
|
+
(0, _react.useImperativeHandle)(dragRef, () => ({
|
|
177
|
+
drag(translationX) {
|
|
178
|
+
const current = selectedValueRef.current;
|
|
179
|
+
if (current === undefined) return null;
|
|
180
|
+
// Ordered by measured position, so "the neighbour" means the tab next
|
|
181
|
+
// to it ON SCREEN. Deriving it from child order instead would be wrong
|
|
182
|
+
// the moment a caller reorders or conditionally renders a trigger.
|
|
183
|
+
const ordered = Object.entries(triggerLayoutsRef.current).sort((a, b) => a[1].x - b[1].x);
|
|
184
|
+
const index = ordered.findIndex(([tabValue]) => tabValue === current);
|
|
185
|
+
const from = ordered[index]?.[1];
|
|
186
|
+
if (from === undefined) return null;
|
|
187
|
+
|
|
188
|
+
// Opposite the finger: dragging LEFT reveals the NEXT tab, which is to
|
|
189
|
+
// the right, so that is where the underline goes.
|
|
190
|
+
const travel = -translationX;
|
|
191
|
+
const neighbour = ordered[index + (travel > 0 ? 1 : -1)];
|
|
192
|
+
if (neighbour === undefined) {
|
|
193
|
+
// First or last tab. Resist, never commit — the rubber-band is the
|
|
194
|
+
// honest signal that there is nothing in that direction.
|
|
195
|
+
const damped = Math.min(Math.abs(travel) * EDGE_RUBBER_BAND_DAMPING, EDGE_RUBBER_BAND_MAX);
|
|
196
|
+
dragOffset.value = Math.sign(travel) * damped;
|
|
197
|
+
dragWidthDelta.value = 0;
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const [neighbourValue, to] = neighbour;
|
|
201
|
+
const distance = to.x - from.x;
|
|
202
|
+
// Clamped at the neighbour: the underline stops exactly where releasing
|
|
203
|
+
// would leave it, so it never promises travel the commit cannot deliver.
|
|
204
|
+
const progress = Math.min(Math.abs(travel) / Math.abs(distance), 1);
|
|
205
|
+
dragOffset.value = distance * progress;
|
|
206
|
+
dragWidthDelta.value = (to.width - from.width) * progress;
|
|
207
|
+
return progress >= COMMIT_THRESHOLD ? neighbourValue : null;
|
|
208
|
+
},
|
|
209
|
+
release(committed) {
|
|
210
|
+
if (committed === null) {
|
|
211
|
+
dragOffset.value = (0, _reactNativeReanimated.withSpring)(0, SLIDE_SPRING);
|
|
212
|
+
dragWidthDelta.value = (0, _reactNativeReanimated.withSpring)(0, SLIDE_SPRING);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// Fold, do not zero — see `TabsDragController.release`.
|
|
216
|
+
indicatorX.value += dragOffset.value;
|
|
217
|
+
indicatorWidth.value += dragWidthDelta.value;
|
|
218
|
+
dragOffset.value = 0;
|
|
219
|
+
dragWidthDelta.value = 0;
|
|
220
|
+
}
|
|
221
|
+
}), [dragOffset, dragWidthDelta, indicatorX, indicatorWidth]);
|
|
79
222
|
const contextValue = (0, _react.useMemo)(() => ({
|
|
80
|
-
value,
|
|
223
|
+
selectedValue: value,
|
|
81
224
|
onValueChange,
|
|
82
225
|
variant,
|
|
83
226
|
fullWidth,
|
|
84
|
-
reportTriggerLayout
|
|
85
|
-
|
|
227
|
+
reportTriggerLayout,
|
|
228
|
+
reportFocused
|
|
229
|
+
}), [value, onValueChange, variant, fullWidth, reportTriggerLayout, reportFocused]);
|
|
86
230
|
const containerStyle = (0, _react.useMemo)(() => {
|
|
87
231
|
const base = {
|
|
88
232
|
flexDirection: 'row',
|
|
@@ -107,20 +251,42 @@ const TabsBarComponent = ({
|
|
|
107
251
|
}
|
|
108
252
|
return base;
|
|
109
253
|
}, [variant, theme]);
|
|
110
|
-
|
|
254
|
+
|
|
255
|
+
// Deps: every shared value the mapper READS is listed. On web WITHOUT the
|
|
256
|
+
// react-native-worklets babel plugin — the production reality for Bloom's
|
|
257
|
+
// Vite consumers — reanimated cannot auto-detect a worklet's reads and drives
|
|
258
|
+
// the mapper off this array instead: omit one and the mapper runs ONCE and
|
|
259
|
+
// freezes at the first frame while the shared value keeps animating
|
|
260
|
+
// underneath, with no error anywhere. Native (plugin present) auto-tracks and
|
|
261
|
+
// ignores the extras, so listing them is correct on both platforms. Same rule
|
|
262
|
+
// as `TabBarBase` and `BottomSheetBase`. Do NOT strip these.
|
|
263
|
+
const indicatorStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
264
|
+
// The drag deltas ADD to the settled values rather than replacing them,
|
|
265
|
+
// which is what lets a release fold them into the base with no jump.
|
|
266
|
+
width: Math.max(indicatorWidth.value + dragWidthDelta.value, 0),
|
|
267
|
+
opacity: indicatorOpacity.value,
|
|
268
|
+
transform: [{
|
|
269
|
+
translateX: indicatorX.value + dragOffset.value
|
|
270
|
+
}]
|
|
271
|
+
}), [indicatorWidth, dragWidthDelta, indicatorOpacity, indicatorX, dragOffset]);
|
|
272
|
+
|
|
273
|
+
// The underline is a sibling of the triggers INSIDE the scrollable content,
|
|
274
|
+
// so the two share one coordinate space: a trigger's `onLayout` x is already
|
|
275
|
+
// relative to the container the underline is absolutely positioned in. That
|
|
276
|
+
// is why nothing here subtracts a scroll offset — an underline parked outside
|
|
277
|
+
// the scroller would have to, and would lag by a frame on every scroll event.
|
|
278
|
+
const indicator = isUnderline ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
111
279
|
pointerEvents: "none",
|
|
112
280
|
testID: testID ? `${testID}-indicator` : undefined,
|
|
113
|
-
style: {
|
|
281
|
+
style: [{
|
|
114
282
|
position: 'absolute',
|
|
115
283
|
left: 0,
|
|
116
284
|
bottom: 0,
|
|
117
285
|
height: 2,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}]
|
|
123
|
-
}
|
|
286
|
+
borderTopLeftRadius: 2,
|
|
287
|
+
borderTopRightRadius: 2,
|
|
288
|
+
backgroundColor: theme.colors.primary
|
|
289
|
+
}, indicatorStyle]
|
|
124
290
|
}) : null;
|
|
125
291
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(TabsContext.Provider, {
|
|
126
292
|
value: contextValue,
|
|
@@ -129,41 +295,66 @@ const TabsBarComponent = ({
|
|
|
129
295
|
testID: testID,
|
|
130
296
|
children: [children, indicator]
|
|
131
297
|
}) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.ScrollView, {
|
|
298
|
+
ref: scrollRef,
|
|
132
299
|
horizontal: true,
|
|
133
300
|
showsHorizontalScrollIndicator: false,
|
|
134
301
|
contentContainerStyle: [containerStyle, style],
|
|
302
|
+
onLayout: e => {
|
|
303
|
+
viewportWidthRef.current = e.nativeEvent.layout.width;
|
|
304
|
+
},
|
|
135
305
|
testID: testID,
|
|
136
306
|
children: [children, indicator]
|
|
137
307
|
})
|
|
138
308
|
});
|
|
139
|
-
};
|
|
309
|
+
});
|
|
140
310
|
const TabComponent = ({
|
|
141
311
|
value,
|
|
142
312
|
label,
|
|
143
313
|
icon,
|
|
314
|
+
count,
|
|
315
|
+
isFocused,
|
|
144
316
|
disabled = false,
|
|
317
|
+
onPress: onPressProp,
|
|
145
318
|
style,
|
|
146
319
|
textStyle
|
|
147
320
|
}) => {
|
|
148
321
|
const theme = (0, _useTheme.useTheme)();
|
|
149
322
|
const {
|
|
150
|
-
|
|
323
|
+
selectedValue,
|
|
151
324
|
onValueChange,
|
|
152
325
|
variant,
|
|
153
326
|
fullWidth,
|
|
154
|
-
reportTriggerLayout
|
|
155
|
-
|
|
156
|
-
|
|
327
|
+
reportTriggerLayout,
|
|
328
|
+
reportFocused
|
|
329
|
+
} = useTabsContext('TabsTrigger');
|
|
330
|
+
// The two paths meet here: an explicit `isFocused` (router adapter) wins;
|
|
331
|
+
// otherwise selection comes from the bar's controlled `value`.
|
|
332
|
+
const isSelected = isFocused ?? value === selectedValue;
|
|
157
333
|
const {
|
|
158
334
|
scaleAnim,
|
|
159
335
|
onPressIn,
|
|
160
336
|
onPressOut
|
|
161
337
|
} = (0, _usePressAnimation.usePressAnimation)(0.97);
|
|
338
|
+
const resolvedCount = count ?? 0;
|
|
339
|
+
const showCount = resolvedCount > 0;
|
|
340
|
+
|
|
341
|
+
// FOCUS-DRIVEN path only. This covers programmatic navigation too — a deep
|
|
342
|
+
// link, a browser Back, a back gesture — because nothing here asks HOW the
|
|
343
|
+
// change happened: the trigger simply re-renders focused and the underline
|
|
344
|
+
// follows. On the controlled path the bar drives the underline instead, so
|
|
345
|
+
// this stays out of the way to avoid two writers on one shared value.
|
|
346
|
+
(0, _react.useEffect)(() => {
|
|
347
|
+
if (isFocused !== true) return;
|
|
348
|
+
reportFocused(value);
|
|
349
|
+
}, [isFocused, value, reportFocused]);
|
|
162
350
|
const handlePress = (0, _react.useCallback)(() => {
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
351
|
+
if (disabled) return;
|
|
352
|
+
onPressProp?.();
|
|
353
|
+
// On the focus-driven path navigation is the caller's job (the router
|
|
354
|
+
// adapter's trigger performs it), so reporting a selection here as well
|
|
355
|
+
// would fight the router for the same underline.
|
|
356
|
+
if (isFocused === undefined) onValueChange?.(value);
|
|
357
|
+
}, [value, disabled, onValueChange, onPressProp, isFocused]);
|
|
167
358
|
const tabStyle = (0, _react.useMemo)(() => {
|
|
168
359
|
const base = {
|
|
169
360
|
flexDirection: 'row',
|
|
@@ -238,6 +429,7 @@ const TabComponent = ({
|
|
|
238
429
|
onPressOut: onPressOut,
|
|
239
430
|
disabled: disabled,
|
|
240
431
|
accessibilityRole: "tab",
|
|
432
|
+
accessibilityLabel: showCount ? `${label}, ${resolvedCount}` : label,
|
|
241
433
|
accessibilityState: {
|
|
242
434
|
selected: isSelected,
|
|
243
435
|
disabled
|
|
@@ -245,7 +437,15 @@ const TabComponent = ({
|
|
|
245
437
|
children: [icon, /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
246
438
|
style: [labelStyle, textStyle],
|
|
247
439
|
children: label
|
|
248
|
-
})
|
|
440
|
+
}), showCount ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
441
|
+
style: {
|
|
442
|
+
fontSize: 11,
|
|
443
|
+
fontWeight: '600',
|
|
444
|
+
color: theme.colors.textTertiary
|
|
445
|
+
},
|
|
446
|
+
numberOfLines: 1,
|
|
447
|
+
children: formatCount(resolvedCount)
|
|
448
|
+
}) : null]
|
|
249
449
|
})
|
|
250
450
|
});
|
|
251
451
|
};
|
|
@@ -255,8 +455,8 @@ const TabPanelComponent = ({
|
|
|
255
455
|
style
|
|
256
456
|
}) => {
|
|
257
457
|
const {
|
|
258
|
-
|
|
259
|
-
} = (
|
|
458
|
+
selectedValue
|
|
459
|
+
} = useTabsContext('TabsContent');
|
|
260
460
|
if (value !== selectedValue) return null;
|
|
261
461
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
262
462
|
style: style,
|