@onekeyfe/react-native-pager-view 6.7.0-6 → 6.7.0-61
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 +159 -115
- package/android/build.gradle +1 -0
- package/android/src/androidTest/AndroidManifest.xml +7 -0
- package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +476 -0
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +233 -43
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +596 -27
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +40 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerScrollAwayInsets.kt +19 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
- package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +8 -2
- package/android/src/main/java/com/reactnativepagerview/event/NativeHeaderPressEvent.kt +8 -0
- package/android/src/test/java/com/reactnativepagerview/NativeScrollerScrollAwayInsetsTest.kt +40 -0
- package/docs/SPEC.md +716 -10
- package/ios/RNCCollapsiblePagerViewComponentView.mm +2246 -97
- package/ios/RNCNativeScrollerComponentView.h +2 -0
- package/ios/RNCNativeScrollerComponentView.mm +42 -0
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +723 -1
- package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +1116 -0
- package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +74 -9
- package/ios/tests/RNCCollapsiblePagerRefreshControlTests.mm +50 -0
- package/lib/module/CollapsiblePagerView.js +75 -11
- package/lib/module/CollapsiblePagerView.web.js +653 -8
- package/lib/module/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/lib/module/NativeScroller.web.js +3 -0
- package/lib/module/NativeScrollerNativeComponent.ts +42 -46
- package/lib/module/PagerViewNativeComponent.ts +20 -25
- package/lib/module/WebCollapsiblePagerPage.js +7 -2
- package/lib/typescript/src/CollapsiblePagerView.d.ts +62 -4
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +56 -2
- package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +54 -38
- package/lib/typescript/src/NativeScroller.d.ts +5 -3
- package/lib/typescript/src/NativeScroller.web.d.ts +1 -1
- package/lib/typescript/src/NativeScrollerNativeComponent.d.ts +47 -48
- package/lib/typescript/src/PagerView.d.ts +1 -1
- package/lib/typescript/src/PagerView.web.d.ts +1 -1
- package/lib/typescript/src/PagerViewNativeComponent.d.ts +20 -21
- package/lib/typescript/src/WebCollapsiblePagerPage.d.ts +1 -1
- package/lib/typescript/src/usePagerView.d.ts +2 -2
- package/lib/typescript/src/utils.d.ts +2 -2
- package/package.json +20 -7
- package/react-native-pager-view.podspec +1 -0
- package/src/CollapsiblePagerView.tsx +208 -12
- package/src/CollapsiblePagerView.web.tsx +587 -7
- package/src/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/src/NativeScroller.tsx +14 -4
- package/src/NativeScroller.web.tsx +15 -1
- package/src/NativeScrollerNativeComponent.ts +42 -46
- package/src/PagerViewNativeComponent.ts +20 -25
- package/src/WebCollapsiblePagerPage.tsx +7 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import React from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { createNamedIcon } from "@onekeyfe/react-native-image/icon/dom";
|
|
5
|
+
import { I18nManager, Platform, processColor, StyleSheet, View } from "react-native";
|
|
5
6
|
import { WebCollapsiblePagerPage } from "./WebCollapsiblePagerPage.js";
|
|
6
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
8
|
const COLLAPSE_ANIMATION_NAME = "ok-collapsible-pager-collapse";
|
|
8
9
|
const COLLAPSE_STYLE_ID = "ok-collapsible-pager-styles";
|
|
9
10
|
const PAGER_HEADER_INSET = "--ok-collapsible-pager-header-inset";
|
|
@@ -48,6 +49,13 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
48
49
|
};
|
|
49
50
|
root = null;
|
|
50
51
|
track = null;
|
|
52
|
+
tabProgress = null;
|
|
53
|
+
tabProgressFrame = null;
|
|
54
|
+
tabProgressGeneration = 0;
|
|
55
|
+
tabButtons = new Map();
|
|
56
|
+
tabList = null;
|
|
57
|
+
tabButtonRefs = new Map();
|
|
58
|
+
tabPill = null;
|
|
51
59
|
headerSlot = null;
|
|
52
60
|
stickySlot = null;
|
|
53
61
|
cssTimelineSupported = false;
|
|
@@ -80,6 +88,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
80
88
|
configureFrame = null;
|
|
81
89
|
pendingTopFrame = null;
|
|
82
90
|
transitionTimer = null;
|
|
91
|
+
transitionGeneration = 0;
|
|
83
92
|
pageScrollState = "idle";
|
|
84
93
|
configuredScrollElement = null;
|
|
85
94
|
timelineName = `--ok-collapsible-pager-${++collapsiblePagerWebInstance}`;
|
|
@@ -115,6 +124,9 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
115
124
|
this.scheduleScrollConfiguration();
|
|
116
125
|
this.syncFallbackHeader();
|
|
117
126
|
this.notifyMountedPagesChanged();
|
|
127
|
+
this.syncToolbar();
|
|
128
|
+
this.tabProgress = this.state.selectedPage;
|
|
129
|
+
this.syncTabColors();
|
|
118
130
|
this.emitDiagnostics("mounted");
|
|
119
131
|
}
|
|
120
132
|
componentDidUpdate(previousProps, _previousState, routeSnapshot) {
|
|
@@ -166,12 +178,17 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
166
178
|
this.scheduleScrollConfiguration();
|
|
167
179
|
this.syncFallbackHeader();
|
|
168
180
|
this.notifyMountedPagesChanged();
|
|
181
|
+
this.syncToolbar();
|
|
182
|
+
if (previousProps.isActive === false && this.props.isActive !== false) this.readTabProgress();
|
|
183
|
+
if (this.props.isActive === false || !this.tabColorWeights()) this.cancelTabProgressFrame();
|
|
184
|
+
this.syncTabColors();
|
|
169
185
|
}
|
|
170
186
|
componentWillUnmount() {
|
|
171
187
|
// Activity can disconnect effects before the inactive update commits.
|
|
172
188
|
const routeTarget = this.captureRouteTarget(this.props);
|
|
173
189
|
if (routeTarget) this.setRouteTarget(routeTarget);
|
|
174
190
|
this.disposed = true;
|
|
191
|
+
this.setToolbarSlot(null);
|
|
175
192
|
this.selectionRestoreToken += 1;
|
|
176
193
|
this.cancelPendingTopFrame();
|
|
177
194
|
this.savePageOffset(this.state.selectedPage);
|
|
@@ -214,8 +231,11 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
214
231
|
};
|
|
215
232
|
observeChrome() {
|
|
216
233
|
this.chromeObserver = new ResizeObserver(this.scheduleChromeMeasurement);
|
|
234
|
+
if (this.root) this.chromeObserver.observe(this.root);
|
|
217
235
|
if (this.headerContent) this.chromeObserver.observe(this.headerContent);
|
|
218
236
|
if (this.stickyContent) this.chromeObserver.observe(this.stickyContent);
|
|
237
|
+
if (this.tabList) this.chromeObserver.observe(this.tabList);
|
|
238
|
+
for (const button of this.tabButtons.values()) this.chromeObserver.observe(button);
|
|
219
239
|
this.scheduleChromeMeasurement();
|
|
220
240
|
}
|
|
221
241
|
scheduleChromeMeasurement = () => {
|
|
@@ -232,6 +252,8 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
232
252
|
this.measuredStickyHeight = nextSticky;
|
|
233
253
|
this.headerMeasured = Boolean(header?.isConnected);
|
|
234
254
|
this.stickyMeasured = Boolean(sticky?.isConnected);
|
|
255
|
+
this.syncToolbar();
|
|
256
|
+
this.syncTabColors();
|
|
235
257
|
if (headerChanged || stickyChanged) {
|
|
236
258
|
this.forceUpdate();
|
|
237
259
|
this.scheduleScrollConfiguration();
|
|
@@ -335,6 +357,15 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
335
357
|
scrollToPageTop = options => {
|
|
336
358
|
this.scrollCurrentPageToTop(0, options?.animated ?? true);
|
|
337
359
|
};
|
|
360
|
+
scrollHeaderBy = delta => {
|
|
361
|
+
if (!Number.isFinite(delta)) return;
|
|
362
|
+
const offset = Math.min(this.headerHeight, Math.max(0, this.sharedHeaderOffset + delta));
|
|
363
|
+
this.scrollCurrentPageToTop(offset, false);
|
|
364
|
+
};
|
|
365
|
+
scrollHeaderToOffset = offset => {
|
|
366
|
+
if (!Number.isFinite(offset)) return;
|
|
367
|
+
this.scrollCurrentPageToTop(Math.min(this.headerHeight, Math.max(0, offset)), false);
|
|
368
|
+
};
|
|
338
369
|
scrollToStickyTop = options => {
|
|
339
370
|
this.scrollCurrentPageToTop(this.headerHeight, options?.animated ?? true);
|
|
340
371
|
};
|
|
@@ -386,13 +417,13 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
386
417
|
this.pendingTopFrame = null;
|
|
387
418
|
if (!element.isConnected || this.horizontalTouch || this.transitionTimer !== null || this.pageScrollElement(this.state.selectedPage) !== element || this.pages().map(pageKey)[this.state.selectedPage] !== key) return;
|
|
388
419
|
this.pageOffsets.set(key, 0);
|
|
389
|
-
this.sharedHeaderOffset = offset;
|
|
420
|
+
this.sharedHeaderOffset = Math.min(this.headerHeight, Math.max(0, offset));
|
|
390
421
|
this.bodyAlignment = {
|
|
391
422
|
element,
|
|
392
423
|
key
|
|
393
424
|
};
|
|
394
425
|
scrollElementTo(element, {
|
|
395
|
-
top:
|
|
426
|
+
top: this.sharedHeaderOffset,
|
|
396
427
|
behavior: animated ? "smooth" : "instant"
|
|
397
428
|
});
|
|
398
429
|
this.syncFallbackHeader();
|
|
@@ -433,29 +464,214 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
433
464
|
}));
|
|
434
465
|
}
|
|
435
466
|
finishPageTransition = () => {
|
|
467
|
+
this.transitionGeneration += 1;
|
|
436
468
|
if (this.transitionTimer !== null) {
|
|
437
469
|
clearTimeout(this.transitionTimer);
|
|
438
470
|
this.transitionTimer = null;
|
|
439
471
|
}
|
|
472
|
+
this.readTabProgress();
|
|
473
|
+
this.cancelTabProgressFrame();
|
|
474
|
+
this.syncTabColors();
|
|
440
475
|
this.emitPageScrollState("idle");
|
|
476
|
+
this.syncToolbar();
|
|
441
477
|
};
|
|
442
478
|
beginPageTransition() {
|
|
479
|
+
this.suspendToolbar();
|
|
443
480
|
if (this.transitionTimer !== null) clearTimeout(this.transitionTimer);
|
|
481
|
+
const generation = ++this.transitionGeneration;
|
|
444
482
|
this.emitPageScrollState("settling");
|
|
445
|
-
this.transitionTimer = setTimeout(
|
|
483
|
+
this.transitionTimer = setTimeout(() => {
|
|
484
|
+
if (generation === this.transitionGeneration) this.finishPageTransition();
|
|
485
|
+
}, 320);
|
|
446
486
|
}
|
|
447
487
|
onTrackTransitionEnd = event => {
|
|
448
488
|
if (event.target === this.track && event.propertyName === "transform") {
|
|
489
|
+
this.readTabProgress();
|
|
490
|
+
if (this.tabColorWeights() && this.tabProgress !== null && Math.abs(this.tabProgress - this.state.selectedPage) > 0.001) return;
|
|
449
491
|
this.finishPageTransition();
|
|
450
492
|
}
|
|
451
493
|
};
|
|
452
494
|
setTrack = node => {
|
|
453
495
|
const track = webElement(node);
|
|
454
496
|
if (track === this.track) return;
|
|
497
|
+
this.cancelTabProgressFrame();
|
|
455
498
|
this.track?.removeEventListener("transitionend", this.onTrackTransitionEnd);
|
|
456
499
|
this.track = track;
|
|
457
500
|
this.track?.addEventListener("transitionend", this.onTrackTransitionEnd);
|
|
458
501
|
};
|
|
502
|
+
cancelTabProgressFrame() {
|
|
503
|
+
this.tabProgressGeneration += 1;
|
|
504
|
+
if (this.tabProgressFrame !== null) cancelAnimationFrame(this.tabProgressFrame);
|
|
505
|
+
this.tabProgressFrame = null;
|
|
506
|
+
}
|
|
507
|
+
readTabProgress() {
|
|
508
|
+
const track = this.track;
|
|
509
|
+
const width = this.root?.getBoundingClientRect().width ?? 0;
|
|
510
|
+
if (!track?.isConnected || width <= 0) return null;
|
|
511
|
+
const transform = track.ownerDocument.defaultView?.getComputedStyle(track).transform;
|
|
512
|
+
const matrix = transform?.match(/^matrix(3d)?\(([^)]+)\)$/);
|
|
513
|
+
const offset = matrix ? Number(matrix[2].split(",")[matrix[1] ? 12 : 4]) : transform === "none" ? 0 : NaN;
|
|
514
|
+
if (!Number.isFinite(offset)) return null;
|
|
515
|
+
this.tabProgress = Math.min(Math.max(0, -offset / width), Math.max(0, this.pages().length - 1));
|
|
516
|
+
return this.tabProgress;
|
|
517
|
+
}
|
|
518
|
+
startTabProgressFrames() {
|
|
519
|
+
this.cancelTabProgressFrame();
|
|
520
|
+
if (!this.tabColorWeights() || typeof requestAnimationFrame !== "function") return;
|
|
521
|
+
const track = this.track;
|
|
522
|
+
const root = this.root;
|
|
523
|
+
const width = root?.getBoundingClientRect().width ?? 0;
|
|
524
|
+
if (!track?.isConnected || !root?.isConnected || width <= 0 || this.props.isActive === false) return;
|
|
525
|
+
const generation = this.tabProgressGeneration;
|
|
526
|
+
const selection = this.selectionRestoreToken;
|
|
527
|
+
const keys = JSON.stringify(this.pages().map(pageKey));
|
|
528
|
+
const owner = this.pageScrollElement(this.state.selectedPage);
|
|
529
|
+
const sample = () => {
|
|
530
|
+
if (generation !== this.tabProgressGeneration || this.disposed) return;
|
|
531
|
+
this.tabProgressFrame = null;
|
|
532
|
+
if (this.track !== track || this.root !== root || !track.isConnected || !root.isConnected || this.props.isActive === false || selection !== this.selectionRestoreToken || keys !== JSON.stringify(this.pages().map(pageKey)) || owner !== this.pageScrollElement(this.state.selectedPage) || width !== root.getBoundingClientRect().width || !this.tabColorWeights()) {
|
|
533
|
+
this.cancelTabProgressFrame();
|
|
534
|
+
this.readTabProgress();
|
|
535
|
+
this.syncTabColors();
|
|
536
|
+
if (this.transitionTimer !== null) this.startTabProgressFrames();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
this.readTabProgress();
|
|
540
|
+
this.syncTabColors();
|
|
541
|
+
if (this.transitionTimer !== null) this.tabProgressFrame = requestAnimationFrame(sample);
|
|
542
|
+
};
|
|
543
|
+
sample();
|
|
544
|
+
}
|
|
545
|
+
tabColorWeights() {
|
|
546
|
+
const config = this.props.nativeTabBar;
|
|
547
|
+
const variant = config?.style?.variant;
|
|
548
|
+
if (!config?.controlled || variant !== "text" && variant !== "pill" || this.tabProgress === null) return null;
|
|
549
|
+
// A pill that does not animate also snaps label colors to the selection.
|
|
550
|
+
if (variant === "pill" && config.style?.indicatorAnimationEnabled === false) return null;
|
|
551
|
+
const keys = [];
|
|
552
|
+
React.Children.forEach(this.props.children, child => {
|
|
553
|
+
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
554
|
+
});
|
|
555
|
+
const itemKeys = config.items.map(item => item.key);
|
|
556
|
+
if (!keys.length || !keys.includes(config.selectedKey ?? "") || new Set(keys).size !== keys.length || new Set(itemKeys).size !== itemKeys.length || keys.some(key => !itemKeys.includes(key))) return null;
|
|
557
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
558
|
+
const source = Math.floor(progress);
|
|
559
|
+
const destination = Math.min(source + 1, keys.length - 1);
|
|
560
|
+
const fraction = progress - source;
|
|
561
|
+
return new Map(keys.map((key, index) => [key, index === source ? 1 - fraction : index === destination ? fraction : 0]));
|
|
562
|
+
}
|
|
563
|
+
tabFontOwnerKey(weights) {
|
|
564
|
+
const config = this.props.nativeTabBar;
|
|
565
|
+
const semantic = config?.controlled ? config.selectedKey : config?.items[this.state.selectedPage]?.key;
|
|
566
|
+
if (!weights || this.tabProgress === null) return semantic;
|
|
567
|
+
const keys = Array.from(weights.keys());
|
|
568
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
569
|
+
return keys[Math.floor(progress + 0.5)];
|
|
570
|
+
}
|
|
571
|
+
tabColor(selected, weight) {
|
|
572
|
+
const style = this.props.nativeTabBar?.style;
|
|
573
|
+
const active = style?.activeTextColor ?? "#000000";
|
|
574
|
+
const inactive = style?.inactiveTextColor ?? "#666666";
|
|
575
|
+
if (weight === undefined) return String(selected ? active : inactive);
|
|
576
|
+
if (weight <= 0) return String(inactive);
|
|
577
|
+
if (weight >= 1) return String(active);
|
|
578
|
+
const first = processColor(inactive);
|
|
579
|
+
const last = processColor(active);
|
|
580
|
+
if (typeof first !== "number" || typeof last !== "number") return String(selected ? active : inactive);
|
|
581
|
+
const channel = shift => (first >>> shift & 255) * (1 - weight) + (last >>> shift & 255) * weight;
|
|
582
|
+
return `rgba(${Math.round(channel(16))}, ${Math.round(channel(8))}, ${Math.round(channel(0))}, ${(channel(24) / 255).toFixed(4)})`;
|
|
583
|
+
}
|
|
584
|
+
syncTabColors() {
|
|
585
|
+
const weights = this.tabColorWeights();
|
|
586
|
+
const config = this.props.nativeTabBar;
|
|
587
|
+
if (!config) return;
|
|
588
|
+
const selectedKey = config.controlled ? config.selectedKey : config.items[this.state.selectedPage]?.key;
|
|
589
|
+
const fontOwnerKey = this.tabFontOwnerKey(weights);
|
|
590
|
+
for (const [key, button] of this.tabButtons) {
|
|
591
|
+
const fontSelected = key === fontOwnerKey;
|
|
592
|
+
button.style.color = this.tabColor(key === selectedKey, weights ? weights.get(key) ?? 0 : undefined);
|
|
593
|
+
button.style.fontWeight = config.style?.variant === "text" && fontSelected ? "600" : "500";
|
|
594
|
+
const fontFamily = (fontSelected ? config.style?.activeFontFamily ?? config.style?.fontFamily : config.style?.fontFamily) ?? "";
|
|
595
|
+
if (config.controlled && config.style?.variant === "text") {
|
|
596
|
+
button.style.fontFamily = config.style?.fontFamily ?? "";
|
|
597
|
+
const label = button.querySelector(".ok-pager-tab-label");
|
|
598
|
+
if (label) label.style.fontFamily = fontFamily;
|
|
599
|
+
} else button.style.fontFamily = fontFamily;
|
|
600
|
+
}
|
|
601
|
+
this.syncTabPill(weights, selectedKey);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// Positions the pill from the live button boxes on every sync. Nothing is
|
|
605
|
+
// cached per index, so a tab that only moved (same size, new position) still
|
|
606
|
+
// gets its own width and offset.
|
|
607
|
+
syncTabPill(weights, selectedKey) {
|
|
608
|
+
const pill = this.tabPill;
|
|
609
|
+
if (!pill) return;
|
|
610
|
+
let fromKey = selectedKey;
|
|
611
|
+
let toKey = selectedKey;
|
|
612
|
+
let fraction = 0;
|
|
613
|
+
if (weights && this.tabProgress !== null) {
|
|
614
|
+
const keys = Array.from(weights.keys());
|
|
615
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
616
|
+
const source = Math.floor(progress);
|
|
617
|
+
fromKey = keys[source];
|
|
618
|
+
toKey = keys[Math.min(source + 1, keys.length - 1)];
|
|
619
|
+
fraction = progress - source;
|
|
620
|
+
}
|
|
621
|
+
const from = fromKey === undefined ? undefined : this.tabButtons.get(fromKey);
|
|
622
|
+
const to = toKey === undefined ? undefined : this.tabButtons.get(toKey);
|
|
623
|
+
if (!from || !to || !from.isConnected || !to.isConnected || from.offsetWidth <= 0) {
|
|
624
|
+
pill.style.visibility = "hidden";
|
|
625
|
+
pill.removeAttribute("data-placed");
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
// Leading edge leads, trailing edge lags, like the JS pill this replaces.
|
|
629
|
+
const leading = 1 - (1 - fraction) * (1 - fraction);
|
|
630
|
+
const trailing = fraction * fraction;
|
|
631
|
+
const forward = to.offsetLeft >= from.offsetLeft;
|
|
632
|
+
const leftFraction = forward ? trailing : leading;
|
|
633
|
+
const rightFraction = forward ? leading : trailing;
|
|
634
|
+
const fromRight = from.offsetLeft + from.offsetWidth;
|
|
635
|
+
const toRight = to.offsetLeft + to.offsetWidth;
|
|
636
|
+
const left = from.offsetLeft + (to.offsetLeft - from.offsetLeft) * leftFraction;
|
|
637
|
+
const right = fromRight + (toRight - fromRight) * rightFraction;
|
|
638
|
+
const animationEnabled = this.props.nativeTabBar?.style?.indicatorAnimationEnabled !== false;
|
|
639
|
+
const animate = animationEnabled && pill.hasAttribute("data-placed") && this.tabProgressFrame === null && fraction === 0;
|
|
640
|
+
pill.style.transition = animate ? "transform 220ms cubic-bezier(0.2, 0, 0, 1), width 220ms cubic-bezier(0.2, 0, 0, 1)" : "none";
|
|
641
|
+
pill.style.top = `${from.offsetTop}px`;
|
|
642
|
+
pill.style.height = `${from.offsetHeight}px`;
|
|
643
|
+
pill.style.width = `${Math.max(0, right - left)}px`;
|
|
644
|
+
pill.style.transform = `translateX(${left}px)`;
|
|
645
|
+
pill.style.visibility = "visible";
|
|
646
|
+
pill.setAttribute("data-placed", "");
|
|
647
|
+
}
|
|
648
|
+
setTabList = node => {
|
|
649
|
+
if (node === this.tabList) return;
|
|
650
|
+
if (this.tabList) this.chromeObserver?.unobserve(this.tabList);
|
|
651
|
+
this.tabList = node;
|
|
652
|
+
if (node) this.chromeObserver?.observe(node);
|
|
653
|
+
};
|
|
654
|
+
setTabPill = node => {
|
|
655
|
+
this.tabPill = node;
|
|
656
|
+
if (node) this.syncTabColors();
|
|
657
|
+
};
|
|
658
|
+
tabButtonRef(key) {
|
|
659
|
+
let ref = this.tabButtonRefs.get(key);
|
|
660
|
+
if (!ref) {
|
|
661
|
+
ref = button => this.setTabButton(key, button);
|
|
662
|
+
this.tabButtonRefs.set(key, ref);
|
|
663
|
+
}
|
|
664
|
+
return ref;
|
|
665
|
+
}
|
|
666
|
+
setTabButton(key, button) {
|
|
667
|
+
const previous = this.tabButtons.get(key);
|
|
668
|
+
if (previous === button) return;
|
|
669
|
+
if (previous) this.chromeObserver?.unobserve(previous);
|
|
670
|
+
if (button) {
|
|
671
|
+
this.tabButtons.set(key, button);
|
|
672
|
+
this.chromeObserver?.observe(button);
|
|
673
|
+
} else this.tabButtons.delete(key);
|
|
674
|
+
}
|
|
459
675
|
pageScrollElement(index) {
|
|
460
676
|
const pageHost = this.pageHosts.get(index);
|
|
461
677
|
return pageHost?.querySelector("[data-collapsible-pager-scroll]") ?? pageHost?.querySelector(".ok-native-list-viewport") ?? pageHost;
|
|
@@ -470,7 +686,9 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
470
686
|
this.root?.removeEventListener("touchend", this.onOverlayTouchEnd);
|
|
471
687
|
this.root?.removeEventListener("touchcancel", this.onOverlayTouchEnd);
|
|
472
688
|
this.overlayTouch = null;
|
|
689
|
+
if (this.root) this.chromeObserver?.unobserve(this.root);
|
|
473
690
|
this.root = root;
|
|
691
|
+
if (root) this.chromeObserver?.observe(root);else this.suspendToolbar();
|
|
474
692
|
root?.addEventListener("ok-collapsible-pager-scroll-key-changed", this.onScrollOwnerIdentityChanged);
|
|
475
693
|
root?.addEventListener("wheel", this.onOverlayWheel, {
|
|
476
694
|
passive: false
|
|
@@ -740,11 +958,15 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
740
958
|
if (this.routeTarget && this.routeTarget.key !== expectedKey) this.setRouteTarget(null);
|
|
741
959
|
this.cancelPendingTopFrame();
|
|
742
960
|
this.savePageOffset(this.state.selectedPage);
|
|
743
|
-
if (animated) this.beginPageTransition();else
|
|
961
|
+
if (animated) this.beginPageTransition();else {
|
|
962
|
+
this.finishPageTransition();
|
|
963
|
+
this.tabProgress = position;
|
|
964
|
+
}
|
|
744
965
|
this.setState({
|
|
745
966
|
selectedPage: position,
|
|
746
967
|
animateTransition: animated
|
|
747
968
|
}, () => {
|
|
969
|
+
if (animated) this.startTabProgressFrames();
|
|
748
970
|
this.scheduleScrollConfiguration();
|
|
749
971
|
const restore = () => {
|
|
750
972
|
if (this.selectionRestoreToken !== selectionToken || this.state.selectedPage !== position || this.pages().map(pageKey)[position] !== expectedKey || !this.pageScrollElement(position)?.isConnected) return;
|
|
@@ -815,6 +1037,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
815
1037
|
this.cancelPendingTopFrame();
|
|
816
1038
|
this.horizontalTouch = true;
|
|
817
1039
|
this.emitPageScrollState("dragging");
|
|
1040
|
+
this.suspendToolbar();
|
|
818
1041
|
}
|
|
819
1042
|
};
|
|
820
1043
|
onTouchEnd = event => {
|
|
@@ -847,9 +1070,428 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
847
1070
|
this.horizontalTouch = false;
|
|
848
1071
|
if (wasHorizontal) this.finishPageTransition();
|
|
849
1072
|
};
|
|
1073
|
+
toolbarSlot = null;
|
|
1074
|
+
toolbarButton = null;
|
|
1075
|
+
toolbarIconIdentity = "";
|
|
1076
|
+
toolbarLoadedIcon = null;
|
|
1077
|
+
toolbarPendingIdentity = "";
|
|
1078
|
+
toolbarReadyIcon = null;
|
|
1079
|
+
toolbarFailedIdentity = "";
|
|
1080
|
+
toolbarAnimation = null;
|
|
1081
|
+
toolbarPresence = false;
|
|
1082
|
+
toolbarPresenceInterrupted = false;
|
|
1083
|
+
toolbarImage = null;
|
|
1084
|
+
toolbarGeneration = 0;
|
|
1085
|
+
ownsSettledToolbar() {
|
|
1086
|
+
return this.props.nativeTabBar?.controlled === true && this.props.nativeTabBar.toolbar !== undefined;
|
|
1087
|
+
}
|
|
1088
|
+
toolbarCanCommit() {
|
|
1089
|
+
if (!this.ownsSettledToolbar()) return true;
|
|
1090
|
+
if (this.disposed || this.props.isActive === false || this.horizontalTouch || this.transitionTimer !== null || this.pageScrollState !== "idle" || !this.root?.isConnected) return false;
|
|
1091
|
+
const actual = this.readTabProgress();
|
|
1092
|
+
if (actual === null || Math.abs(actual - this.state.selectedPage) > 0.001) return false;
|
|
1093
|
+
const config = this.props.nativeTabBar;
|
|
1094
|
+
const keys = [];
|
|
1095
|
+
React.Children.forEach(this.props.children, child => {
|
|
1096
|
+
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
1097
|
+
});
|
|
1098
|
+
const itemKeys = config.items.map(item => item.key);
|
|
1099
|
+
const valid = keys.length > 0 && new Set(keys).size === keys.length && new Set(itemKeys).size === itemKeys.length && keys.every(key => itemKeys.includes(key));
|
|
1100
|
+
return !valid || !keys.includes(config.selectedKey ?? "") || keys[this.state.selectedPage] === config.selectedKey;
|
|
1101
|
+
}
|
|
1102
|
+
cancelToolbarPending() {
|
|
1103
|
+
if (this.toolbarPendingIdentity || this.toolbarImage || this.toolbarReadyIcon) this.toolbarGeneration += 1;
|
|
1104
|
+
if (this.toolbarImage) this.toolbarImage.onload = this.toolbarImage.onerror = null;
|
|
1105
|
+
this.toolbarImage = null;
|
|
1106
|
+
this.toolbarPendingIdentity = "";
|
|
1107
|
+
this.toolbarReadyIcon = null;
|
|
1108
|
+
}
|
|
1109
|
+
setToolbarInteractive(enabled) {
|
|
1110
|
+
const button = this.toolbarButton;
|
|
1111
|
+
if (!button) return;
|
|
1112
|
+
if (!enabled) {
|
|
1113
|
+
if (button.ownerDocument.activeElement === button) button.blur();
|
|
1114
|
+
if (this.toolbarTouchKey !== undefined) this.toolbarTouchKey = null;
|
|
1115
|
+
}
|
|
1116
|
+
button.disabled = !enabled;
|
|
1117
|
+
button.style.pointerEvents = enabled ? "auto" : "none";
|
|
1118
|
+
button.tabIndex = enabled ? 0 : -1;
|
|
1119
|
+
button.setAttribute("aria-hidden", String(!enabled));
|
|
1120
|
+
}
|
|
1121
|
+
suspendToolbar() {
|
|
1122
|
+
if (!this.ownsSettledToolbar()) return;
|
|
1123
|
+
this.setToolbarInteractive(false);
|
|
1124
|
+
this.cancelToolbarPending();
|
|
1125
|
+
if (this.toolbarAnimation && this.toolbarButton) {
|
|
1126
|
+
const opacity = this.toolbarButton.ownerDocument.defaultView?.getComputedStyle(this.toolbarButton).opacity;
|
|
1127
|
+
this.toolbarAnimation.cancel();
|
|
1128
|
+
this.toolbarAnimation = null;
|
|
1129
|
+
this.toolbarButton.style.opacity = opacity || this.toolbarButton.style.opacity;
|
|
1130
|
+
this.toolbarPresenceInterrupted = true;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
setToolbarSlot = slot => {
|
|
1134
|
+
if (this.toolbarSlot === slot) return;
|
|
1135
|
+
this.toolbarAnimation?.cancel();
|
|
1136
|
+
this.toolbarAnimation = null;
|
|
1137
|
+
this.cancelToolbarPending();
|
|
1138
|
+
this.toolbarGeneration += 1;
|
|
1139
|
+
this.toolbarButton?.remove();
|
|
1140
|
+
this.toolbarButton = null;
|
|
1141
|
+
this.toolbarOwnerKey = undefined;
|
|
1142
|
+
this.toolbarOwnerEntry = undefined;
|
|
1143
|
+
this.toolbarIconIdentity = "";
|
|
1144
|
+
this.toolbarLoadedIcon = null;
|
|
1145
|
+
this.toolbarFailedIdentity = "";
|
|
1146
|
+
this.toolbarPresence = false;
|
|
1147
|
+
this.toolbarPresenceInterrupted = false;
|
|
1148
|
+
this.toolbarTouchKey = null;
|
|
1149
|
+
this.toolbarSlot = slot;
|
|
1150
|
+
if (slot) this.syncToolbar();
|
|
1151
|
+
};
|
|
1152
|
+
animateToolbar(visible) {
|
|
1153
|
+
const button = this.toolbarButton;
|
|
1154
|
+
if (!button || this.toolbarPresence === visible && !this.toolbarPresenceInterrupted) return;
|
|
1155
|
+
this.toolbarPresenceInterrupted = false;
|
|
1156
|
+
this.toolbarPresence = visible;
|
|
1157
|
+
const current = button.ownerDocument.defaultView?.getComputedStyle(button).opacity ?? button.style.opacity;
|
|
1158
|
+
this.toolbarAnimation?.cancel();
|
|
1159
|
+
this.toolbarAnimation = null;
|
|
1160
|
+
button.style.opacity = visible ? "1" : "0";
|
|
1161
|
+
const finish = () => {
|
|
1162
|
+
button.hidden = !visible;
|
|
1163
|
+
if (!visible && !this.toolbarOwnerKey && this.toolbarButton === button) {
|
|
1164
|
+
button.remove();
|
|
1165
|
+
this.toolbarButton = null;
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
if (typeof button.animate !== "function") {
|
|
1169
|
+
finish();
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
button.hidden = false;
|
|
1173
|
+
const animation = button.animate([{
|
|
1174
|
+
opacity: current || "0"
|
|
1175
|
+
}, {
|
|
1176
|
+
opacity: visible ? "1" : "0"
|
|
1177
|
+
}], {
|
|
1178
|
+
duration: 100,
|
|
1179
|
+
fill: "forwards"
|
|
1180
|
+
});
|
|
1181
|
+
this.toolbarAnimation = animation;
|
|
1182
|
+
animation.onfinish = () => {
|
|
1183
|
+
if (this.toolbarAnimation !== animation || this.toolbarButton !== button || this.toolbarPresence !== visible) return;
|
|
1184
|
+
animation.cancel();
|
|
1185
|
+
this.toolbarAnimation = null;
|
|
1186
|
+
finish();
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
hideToolbar(failed) {
|
|
1190
|
+
this.setToolbarInteractive(false);
|
|
1191
|
+
this.toolbarOwnerKey = undefined;
|
|
1192
|
+
this.toolbarOwnerEntry = undefined;
|
|
1193
|
+
this.toolbarButton?.removeAttribute("data-testid");
|
|
1194
|
+
this.toolbarButton?.removeAttribute("aria-label");
|
|
1195
|
+
if (failed) this.toolbarButton?.replaceChildren();
|
|
1196
|
+
this.animateToolbar(false);
|
|
1197
|
+
}
|
|
1198
|
+
commitToolbar(key, entry, icon, identity) {
|
|
1199
|
+
const button = this.toolbarButton;
|
|
1200
|
+
if (!button || !this.toolbarCanCommit()) return;
|
|
1201
|
+
if (this.toolbarOwnerKey !== key && this.toolbarTouchKey !== undefined) this.toolbarTouchKey = null;
|
|
1202
|
+
const size = Math.min(128, Math.max(1, entry.size ?? 38));
|
|
1203
|
+
const iconSize = Math.min(size, Math.max(1, entry.iconSize ?? 24));
|
|
1204
|
+
const contentWidth = Math.min(size, Math.max(0, entry.contentWidth ?? 24));
|
|
1205
|
+
const trailingInset = Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1206
|
+
if (button.firstChild !== icon) button.replaceChildren(icon);
|
|
1207
|
+
Object.assign(button.style, {
|
|
1208
|
+
position: "absolute",
|
|
1209
|
+
width: `${size}px`,
|
|
1210
|
+
height: `${size}px`,
|
|
1211
|
+
borderRadius: "50%",
|
|
1212
|
+
top: "50%",
|
|
1213
|
+
transform: "translateY(-50%)",
|
|
1214
|
+
insetInlineEnd: `${trailingInset - (size - contentWidth) / 2}px`,
|
|
1215
|
+
padding: `${(size - iconSize) / 2}px`,
|
|
1216
|
+
color: entry.iconColor ?? "#000000"
|
|
1217
|
+
});
|
|
1218
|
+
const base = entry.selected ? entry.selectedBackgroundColor ?? "transparent" : "transparent";
|
|
1219
|
+
button.style.setProperty("--pager-toolbar-base", base);
|
|
1220
|
+
button.style.setProperty("--pager-toolbar-hover", entry.hoverBackgroundColor ?? base);
|
|
1221
|
+
button.style.setProperty("--pager-toolbar-pressed", entry.pressedBackgroundColor ?? base);
|
|
1222
|
+
button.setAttribute("aria-label", entry.accessibilityLabel ?? "");
|
|
1223
|
+
if (entry.testID) button.setAttribute("data-testid", entry.testID);else button.removeAttribute("data-testid");
|
|
1224
|
+
this.toolbarOwnerKey = key;
|
|
1225
|
+
this.toolbarOwnerEntry = {
|
|
1226
|
+
...entry
|
|
1227
|
+
};
|
|
1228
|
+
this.toolbarIconIdentity = identity;
|
|
1229
|
+
this.toolbarLoadedIcon = icon;
|
|
1230
|
+
this.toolbarPendingIdentity = "";
|
|
1231
|
+
this.toolbarReadyIcon = null;
|
|
1232
|
+
this.toolbarImage = null;
|
|
1233
|
+
this.animateToolbar(true);
|
|
1234
|
+
this.setToolbarInteractive(true);
|
|
1235
|
+
}
|
|
1236
|
+
syncToolbar() {
|
|
1237
|
+
const slot = this.toolbarSlot;
|
|
1238
|
+
if (!slot) return;
|
|
1239
|
+
if (!this.toolbarCanCommit()) {
|
|
1240
|
+
this.suspendToolbar();
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
const config = this.props.nativeTabBar;
|
|
1244
|
+
const key = config?.controlled ? config.selectedKey : config?.items[this.state.selectedPage]?.key;
|
|
1245
|
+
const entry = key ? config?.toolbar?.[key] : undefined;
|
|
1246
|
+
if (!entry?.iconName || !key) {
|
|
1247
|
+
this.cancelToolbarPending();
|
|
1248
|
+
this.hideToolbar(false);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
let button = this.toolbarButton;
|
|
1252
|
+
if (!button) {
|
|
1253
|
+
button = slot.ownerDocument.createElement("button");
|
|
1254
|
+
button.type = "button";
|
|
1255
|
+
button.className = "ok-pager-toolbar";
|
|
1256
|
+
button.style.opacity = "0";
|
|
1257
|
+
button.hidden = true;
|
|
1258
|
+
button.disabled = true;
|
|
1259
|
+
button.addEventListener("pointerdown", () => {
|
|
1260
|
+
this.toolbarTouchKey = button.disabled ? null : this.toolbarOwnerKey ?? null;
|
|
1261
|
+
});
|
|
1262
|
+
button.addEventListener("pointercancel", () => {
|
|
1263
|
+
this.toolbarTouchKey = null;
|
|
1264
|
+
});
|
|
1265
|
+
button.onclick = event => {
|
|
1266
|
+
if (this.toolbarButton !== event.currentTarget) return;
|
|
1267
|
+
const pointer = event.detail !== 0;
|
|
1268
|
+
const touched = this.toolbarTouchKey;
|
|
1269
|
+
if (pointer) this.toolbarTouchKey = undefined;
|
|
1270
|
+
const current = this.props.nativeTabBar;
|
|
1271
|
+
const semantic = current?.controlled ? current.selectedKey : current?.items[this.state.selectedPage]?.key;
|
|
1272
|
+
const owner = this.toolbarOwnerKey;
|
|
1273
|
+
if (button.disabled || !this.toolbarCanCommit() || !owner || owner !== semantic || !this.toolbarOwnerEntry || pointer && touched !== owner) return;
|
|
1274
|
+
const rect = button.getBoundingClientRect();
|
|
1275
|
+
this.props.onNativeToolbarPress?.({
|
|
1276
|
+
nativeEvent: {
|
|
1277
|
+
key: owner,
|
|
1278
|
+
anchorRect: {
|
|
1279
|
+
x: rect.x,
|
|
1280
|
+
y: rect.y,
|
|
1281
|
+
width: rect.width,
|
|
1282
|
+
height: rect.height
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
};
|
|
1287
|
+
slot.appendChild(button);
|
|
1288
|
+
this.toolbarButton = button;
|
|
1289
|
+
this.toolbarPresence = false;
|
|
1290
|
+
}
|
|
1291
|
+
const size = Math.min(128, Math.max(1, entry.size ?? 38));
|
|
1292
|
+
const iconSize = Math.min(size, Math.max(1, entry.iconSize ?? 24));
|
|
1293
|
+
const identity = `${entry.iconName}|${entry.iconColor ?? "#000000"}|${iconSize}`;
|
|
1294
|
+
if (identity === this.toolbarIconIdentity && this.toolbarLoadedIcon) {
|
|
1295
|
+
this.cancelToolbarPending();
|
|
1296
|
+
this.commitToolbar(key, entry, this.toolbarLoadedIcon, identity);
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
if (identity === this.toolbarPendingIdentity) {
|
|
1300
|
+
if (this.toolbarReadyIcon) this.commitToolbar(key, entry, this.toolbarReadyIcon, identity);
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
this.cancelToolbarPending();
|
|
1304
|
+
this.setToolbarInteractive(false);
|
|
1305
|
+
this.toolbarPendingIdentity = identity;
|
|
1306
|
+
if (identity === this.toolbarFailedIdentity) {
|
|
1307
|
+
this.hideToolbar(true);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const generation = ++this.toolbarGeneration;
|
|
1311
|
+
const icon = createNamedIcon(button.ownerDocument, entry.iconName);
|
|
1312
|
+
icon.setAttribute("width", String(iconSize));
|
|
1313
|
+
icon.setAttribute("height", String(iconSize));
|
|
1314
|
+
const use = icon.querySelector("use");
|
|
1315
|
+
const fail = () => {
|
|
1316
|
+
if (this.toolbarGeneration !== generation || this.toolbarPendingIdentity !== identity) return;
|
|
1317
|
+
this.toolbarImage = null;
|
|
1318
|
+
this.toolbarFailedIdentity = identity;
|
|
1319
|
+
this.hideToolbar(true);
|
|
1320
|
+
};
|
|
1321
|
+
if (!use) {
|
|
1322
|
+
fail();
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
const ready = () => {
|
|
1326
|
+
if (this.disposed || this.toolbarGeneration !== generation || this.toolbarPendingIdentity !== identity) return;
|
|
1327
|
+
this.toolbarImage = null;
|
|
1328
|
+
this.toolbarReadyIcon = icon;
|
|
1329
|
+
this.syncToolbar();
|
|
1330
|
+
};
|
|
1331
|
+
const href = use.getAttribute("href") ?? use.getAttribute("xlink:href") ?? "";
|
|
1332
|
+
const view = button.ownerDocument.defaultView;
|
|
1333
|
+
if (view?.Image && href.split("#")[0]) {
|
|
1334
|
+
const image = new view.Image();
|
|
1335
|
+
this.toolbarImage = image;
|
|
1336
|
+
image.onload = ready;
|
|
1337
|
+
image.onerror = fail;
|
|
1338
|
+
image.src = href.split("#")[0];
|
|
1339
|
+
} else ready();
|
|
1340
|
+
}
|
|
1341
|
+
renderNativeTabBar() {
|
|
1342
|
+
const config = this.props.nativeTabBar;
|
|
1343
|
+
if (!config?.items.length || config.style?.variant !== "text" && config.controlled !== true && config.toolbar === undefined) return null;
|
|
1344
|
+
const style = config.style;
|
|
1345
|
+
const variant = style?.variant ?? "underline";
|
|
1346
|
+
const selectedKey = config.controlled ? config.selectedKey : config.items[this.state.selectedPage]?.key;
|
|
1347
|
+
const toolbarEntries = config.toolbar === undefined ? undefined : Object.values(config.toolbar);
|
|
1348
|
+
const reservedWidth = toolbarEntries === undefined ? 0 : toolbarEntries.length === 0 ? 44 : Math.max(...toolbarEntries.map(entry => {
|
|
1349
|
+
const size = Math.min(128, Math.max(1, entry.size ?? 38));
|
|
1350
|
+
return Math.min(size, Math.max(0, entry.contentWidth ?? 24)) + Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1351
|
+
}));
|
|
1352
|
+
const segmented = variant === "segmented";
|
|
1353
|
+
const pill = variant === "pill";
|
|
1354
|
+
const reserveTextFaces = config.controlled && variant === "text";
|
|
1355
|
+
const itemPadding = style?.itemPaddingHorizontal ?? (variant === "text" ? 10 : pill ? 14 : 8);
|
|
1356
|
+
const cssColor = value => value === undefined ? "transparent" : String(value);
|
|
1357
|
+
for (const key of this.tabButtonRefs.keys()) {
|
|
1358
|
+
if (!config.items.some(item => item.key === key)) this.tabButtonRefs.delete(key);
|
|
1359
|
+
}
|
|
1360
|
+
const colorWeights = this.tabColorWeights();
|
|
1361
|
+
const fontOwnerKey = this.tabFontOwnerKey(colorWeights);
|
|
1362
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1363
|
+
className: "ok-pager-tab-bar",
|
|
1364
|
+
dir: this.props.layoutDirection === "rtl" || (this.props.layoutDirection ?? "locale") === "locale" && I18nManager.isRTL ? "rtl" : "ltr",
|
|
1365
|
+
"data-variant": variant,
|
|
1366
|
+
style: {
|
|
1367
|
+
display: "flex",
|
|
1368
|
+
alignItems: "center",
|
|
1369
|
+
position: "relative",
|
|
1370
|
+
height: style?.height ?? 44,
|
|
1371
|
+
backgroundColor: String(style?.backgroundColor ?? "transparent"),
|
|
1372
|
+
minWidth: 0,
|
|
1373
|
+
["--pager-tab-hover"]: cssColor(style?.itemHoverBackgroundColor),
|
|
1374
|
+
["--pager-tab-pressed"]: cssColor(style?.itemPressedBackgroundColor)
|
|
1375
|
+
}
|
|
1376
|
+
}, /*#__PURE__*/React.createElement("style", null, `.ok-pager-tab{box-sizing:border-box;appearance:none;border:0;background:transparent;cursor:default;white-space:nowrap;flex-shrink:0;line-height:normal}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab{position:relative;z-index:1;border-radius:999px}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:hover{background:var(--pager-tab-hover)}.ok-pager-tab-bar[data-variant=pill] .ok-pager-tab[aria-selected=false]:active{background:var(--pager-tab-pressed)}.ok-pager-tablist{scrollbar-width:none}.ok-pager-tablist::-webkit-scrollbar{display:none}.ok-pager-toolbar{box-sizing:border-box;appearance:none;border:1px solid transparent;cursor:default;display:flex;align-items:center;justify-content:center;background:var(--pager-toolbar-base)}.ok-pager-toolbar:hover:enabled{background:var(--pager-toolbar-hover)}.ok-pager-toolbar:active:enabled{background:var(--pager-toolbar-pressed)}`), /*#__PURE__*/React.createElement("div", {
|
|
1377
|
+
className: "ok-pager-tab-row",
|
|
1378
|
+
style: {
|
|
1379
|
+
display: "flex",
|
|
1380
|
+
alignItems: "center",
|
|
1381
|
+
height: "100%",
|
|
1382
|
+
flex: 1,
|
|
1383
|
+
minWidth: 0,
|
|
1384
|
+
maxWidth: style?.contentMaxWidth,
|
|
1385
|
+
margin: style?.contentMaxWidth === undefined ? undefined : "0 auto"
|
|
1386
|
+
}
|
|
1387
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1388
|
+
role: "tablist",
|
|
1389
|
+
className: "ok-pager-tablist",
|
|
1390
|
+
ref: this.setTabList,
|
|
1391
|
+
style: {
|
|
1392
|
+
display: "flex",
|
|
1393
|
+
overflowX: segmented ? "hidden" : "auto",
|
|
1394
|
+
flex: 1,
|
|
1395
|
+
position: "relative",
|
|
1396
|
+
alignItems: "center",
|
|
1397
|
+
padding: `${style?.contentPaddingVertical ?? 0}px ${style?.contentPaddingHorizontal ?? 20}px`,
|
|
1398
|
+
gap: style?.itemSpacing ?? 8
|
|
1399
|
+
}
|
|
1400
|
+
}, pill ? /*#__PURE__*/React.createElement("div", {
|
|
1401
|
+
key: "ok-pager-tab-pill",
|
|
1402
|
+
ref: this.setTabPill,
|
|
1403
|
+
className: "ok-pager-tab-pill",
|
|
1404
|
+
"aria-hidden": true,
|
|
1405
|
+
style: {
|
|
1406
|
+
position: "absolute",
|
|
1407
|
+
left: 0,
|
|
1408
|
+
top: 0,
|
|
1409
|
+
width: 0,
|
|
1410
|
+
height: 0,
|
|
1411
|
+
borderRadius: 999,
|
|
1412
|
+
pointerEvents: "none",
|
|
1413
|
+
visibility: "hidden",
|
|
1414
|
+
backgroundColor: String(style?.indicatorColor ?? "#000000"),
|
|
1415
|
+
willChange: "transform, width"
|
|
1416
|
+
}
|
|
1417
|
+
}) : null, ...config.items.map((item, position) => {
|
|
1418
|
+
const selected = item.key === selectedKey;
|
|
1419
|
+
const fontSelected = item.key === fontOwnerKey;
|
|
1420
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
1421
|
+
key: item.key,
|
|
1422
|
+
role: "tab",
|
|
1423
|
+
type: "button",
|
|
1424
|
+
className: "ok-pager-tab",
|
|
1425
|
+
"aria-selected": selected,
|
|
1426
|
+
ref: this.tabButtonRef(item.key),
|
|
1427
|
+
"aria-label": item.accessibilityLabel ?? item.title,
|
|
1428
|
+
"data-testid": item.testID,
|
|
1429
|
+
style: {
|
|
1430
|
+
padding: `6px ${itemPadding}px`,
|
|
1431
|
+
minWidth: 44,
|
|
1432
|
+
height: (style?.height ?? 44) - 2 * (style?.contentPaddingVertical ?? 0),
|
|
1433
|
+
fontSize: style?.fontSize ?? (variant === "text" ? 18 : 16),
|
|
1434
|
+
fontWeight: variant === "text" && fontSelected ? 600 : 500,
|
|
1435
|
+
fontFamily: reserveTextFaces ? style?.fontFamily : fontSelected ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily,
|
|
1436
|
+
display: reserveTextFaces ? "inline-grid" : undefined,
|
|
1437
|
+
gridTemplateAreas: reserveTextFaces ? '"label"' : undefined,
|
|
1438
|
+
alignItems: reserveTextFaces ? "center" : undefined,
|
|
1439
|
+
color: this.tabColor(selected, colorWeights ? colorWeights.get(item.key) ?? 0 : undefined),
|
|
1440
|
+
flex: segmented ? 1 : undefined,
|
|
1441
|
+
borderRadius: segmented || pill ? 999 : 0,
|
|
1442
|
+
// Pill items leave the background to CSS so hover / pressed apply.
|
|
1443
|
+
backgroundColor: pill ? undefined : segmented && selected ? String(style?.indicatorColor ?? "transparent") : "transparent",
|
|
1444
|
+
borderBottom: variant === "underline" && selected ? `${style?.indicatorHeight ?? 2}px solid ${String(style?.indicatorColor ?? "#000000")}` : undefined
|
|
1445
|
+
},
|
|
1446
|
+
onClick: () => {
|
|
1447
|
+
if (!config.controlled) {
|
|
1448
|
+
const animated = this.props.nativeTabPressAnimationEnabled ?? Math.abs(position - this.state.selectedPage) <= 1;
|
|
1449
|
+
if (animated) this.setPage(position);else this.setPageWithoutAnimation(position);
|
|
1450
|
+
}
|
|
1451
|
+
this.props.onNativeTabPress?.({
|
|
1452
|
+
nativeEvent: {
|
|
1453
|
+
position,
|
|
1454
|
+
key: item.key
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
}, reserveTextFaces ? [/*#__PURE__*/React.createElement("span", {
|
|
1459
|
+
key: "label",
|
|
1460
|
+
className: "ok-pager-tab-label",
|
|
1461
|
+
style: {
|
|
1462
|
+
gridArea: "label",
|
|
1463
|
+
fontFamily: fontSelected ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily
|
|
1464
|
+
}
|
|
1465
|
+
}, item.title), ...[false, true].map(active => /*#__PURE__*/React.createElement("span", {
|
|
1466
|
+
key: active ? "active-width" : "normal-width",
|
|
1467
|
+
"aria-hidden": true,
|
|
1468
|
+
style: {
|
|
1469
|
+
gridArea: "label",
|
|
1470
|
+
visibility: "hidden",
|
|
1471
|
+
pointerEvents: "none",
|
|
1472
|
+
userSelect: "none",
|
|
1473
|
+
fontWeight: active ? 600 : 500,
|
|
1474
|
+
fontFamily: active ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily
|
|
1475
|
+
}
|
|
1476
|
+
}, item.title))] : item.title);
|
|
1477
|
+
})), config.toolbar !== undefined ? /*#__PURE__*/React.createElement("div", {
|
|
1478
|
+
ref: this.setToolbarSlot,
|
|
1479
|
+
className: "ok-pager-toolbar-slot",
|
|
1480
|
+
style: {
|
|
1481
|
+
flexShrink: 0,
|
|
1482
|
+
width: reservedWidth,
|
|
1483
|
+
height: "100%",
|
|
1484
|
+
position: "relative"
|
|
1485
|
+
}
|
|
1486
|
+
}) : null));
|
|
1487
|
+
}
|
|
850
1488
|
render() {
|
|
851
1489
|
const {
|
|
852
1490
|
children: _children,
|
|
1491
|
+
nativeTabBar: _nativeTabBar,
|
|
1492
|
+
nativeTabPressAnimationEnabled: _nativeTabPressAnimationEnabled,
|
|
1493
|
+
onNativeTabPress: _onNativeTabPress,
|
|
1494
|
+
onNativeToolbarPress: _onNativeToolbarPress,
|
|
853
1495
|
header,
|
|
854
1496
|
stickyHeader,
|
|
855
1497
|
topOverlay: _topOverlay,
|
|
@@ -858,6 +1500,7 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
858
1500
|
externalTopOverlayTag: _externalTopOverlayTag,
|
|
859
1501
|
headerHeight: _headerHeight,
|
|
860
1502
|
stickyHeaderHeight: _stickyHeaderHeight,
|
|
1503
|
+
stickyHeaderHeights: _stickyHeaderHeights,
|
|
861
1504
|
isActive: _isActive,
|
|
862
1505
|
pageRetentionDistance: _pageRetentionDistance,
|
|
863
1506
|
layoutDirection: _layoutDirection,
|
|
@@ -918,9 +1561,11 @@ export class CollapsiblePagerView extends React.PureComponent {
|
|
|
918
1561
|
top: this.headerHeight,
|
|
919
1562
|
height: this.stickyHeaderHeight
|
|
920
1563
|
}, collapseAnimation],
|
|
921
|
-
children: this.hasExplicitStickyHeaderHeight ?
|
|
1564
|
+
children: this.hasExplicitStickyHeaderHeight ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
1565
|
+
children: [this.renderNativeTabBar(), stickyHeader]
|
|
1566
|
+
}) : /*#__PURE__*/_jsxs(View, {
|
|
922
1567
|
ref: this.setStickyContent,
|
|
923
|
-
children: stickyHeader
|
|
1568
|
+
children: [this.renderNativeTabBar(), stickyHeader]
|
|
924
1569
|
})
|
|
925
1570
|
}), /*#__PURE__*/_jsx(View, {
|
|
926
1571
|
ref: this.setTrack,
|