@onekeyfe/react-native-pager-view 6.7.0-4 → 6.7.0-40
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 +21 -0
- 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 +700 -10
- package/ios/RNCCollapsiblePagerViewComponentView.mm +2221 -94
- package/ios/RNCNativeScrollerComponentView.h +2 -0
- package/ios/RNCNativeScrollerComponentView.mm +42 -0
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +562 -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/module/index.native.js +9 -0
- 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/index.native.d.ts +13 -0
- package/lib/typescript/src/usePagerView.d.ts +2 -2
- package/lib/typescript/src/utils.d.ts +2 -2
- package/package.json +22 -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
- package/src/index.native.tsx +30 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ScrollEdgeEffect } from "./ScrollEdgeEffect";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { createNamedIcon } from "@onekeyfe/react-native-image/icon/dom";
|
|
4
|
+
import type { CollapsiblePagerNativeTabBarConfig, CollapsiblePagerToolbarItem, CollapsiblePagerToolbarPress, CollapsiblePagerViewOnNativeTabPressEvent } from "./CollapsiblePagerView";
|
|
5
|
+
export type { CollapsiblePagerNativeTabBarConfig, CollapsiblePagerNativeTabBarItem, CollapsiblePagerNativeTabBarStyle, CollapsiblePagerToolbarItem, CollapsiblePagerToolbarPress } from "./CollapsiblePagerView";
|
|
6
|
+
import { I18nManager, Platform, processColor, StyleSheet, View } from "react-native";
|
|
4
7
|
import type * as ReactNative from "react-native";
|
|
5
8
|
|
|
6
9
|
import { WebCollapsiblePagerPage } from "./WebCollapsiblePagerPage";
|
|
@@ -66,10 +69,15 @@ export interface CollapsiblePagerViewProps
|
|
|
66
69
|
| "retainedPages"
|
|
67
70
|
| "layoutDirection"
|
|
68
71
|
> {
|
|
72
|
+
nativeTabBar?: CollapsiblePagerNativeTabBarConfig;
|
|
73
|
+
nativeTabPressAnimationEnabled?: boolean;
|
|
74
|
+
onNativeTabPress?: (event: CollapsiblePagerViewOnNativeTabPressEvent) => void;
|
|
75
|
+
onNativeToolbarPress?: (event: ReactNative.NativeSyntheticEvent<CollapsiblePagerToolbarPress>) => void;
|
|
69
76
|
header: React.ReactNode;
|
|
70
77
|
stickyHeader: React.ReactNode;
|
|
71
78
|
headerHeight?: number;
|
|
72
79
|
stickyHeaderHeight?: number;
|
|
80
|
+
stickyHeaderHeights?: readonly number[];
|
|
73
81
|
isActive?: boolean;
|
|
74
82
|
topOverlay?: React.ReactNode;
|
|
75
83
|
topScrollEdgeEffect?: `${ScrollEdgeEffect}`;
|
|
@@ -188,6 +196,13 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
188
196
|
|
|
189
197
|
private root: HTMLElement | null = null;
|
|
190
198
|
private track: HTMLElement | null = null;
|
|
199
|
+
private tabProgress: number | null = null;
|
|
200
|
+
private tabProgressFrame: number | null = null;
|
|
201
|
+
private tabProgressGeneration = 0;
|
|
202
|
+
private tabButtons = new Map<string, HTMLButtonElement>();
|
|
203
|
+
private tabList: HTMLElement | null = null;
|
|
204
|
+
private tabButtonRefs = new Map<string, (button: HTMLButtonElement | null) => void>();
|
|
205
|
+
private tabPill: HTMLElement | null = null;
|
|
191
206
|
private headerSlot: HTMLElement | null = null;
|
|
192
207
|
private stickySlot: HTMLElement | null = null;
|
|
193
208
|
private cssTimelineSupported = false;
|
|
@@ -236,6 +251,7 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
236
251
|
key: string;
|
|
237
252
|
}> | null = null;
|
|
238
253
|
private transitionTimer: ReturnType<typeof setTimeout> | null = null;
|
|
254
|
+
private transitionGeneration = 0;
|
|
239
255
|
private pageScrollState: OnPageScrollStateChangedEventData["pageScrollState"] =
|
|
240
256
|
"idle";
|
|
241
257
|
private configuredScrollElement: ConfiguredScrollElement | null = null;
|
|
@@ -290,6 +306,9 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
290
306
|
this.scheduleScrollConfiguration();
|
|
291
307
|
this.syncFallbackHeader();
|
|
292
308
|
this.notifyMountedPagesChanged();
|
|
309
|
+
this.syncToolbar();
|
|
310
|
+
this.tabProgress = this.state.selectedPage;
|
|
311
|
+
this.syncTabColors();
|
|
293
312
|
this.emitDiagnostics("mounted");
|
|
294
313
|
}
|
|
295
314
|
|
|
@@ -359,6 +378,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
359
378
|
this.scheduleScrollConfiguration();
|
|
360
379
|
this.syncFallbackHeader();
|
|
361
380
|
this.notifyMountedPagesChanged();
|
|
381
|
+
this.syncToolbar();
|
|
382
|
+
if (previousProps.isActive === false && this.props.isActive !== false) this.readTabProgress();
|
|
383
|
+
if (this.props.isActive === false || !this.tabColorWeights()) this.cancelTabProgressFrame();
|
|
384
|
+
this.syncTabColors();
|
|
362
385
|
}
|
|
363
386
|
|
|
364
387
|
componentWillUnmount() {
|
|
@@ -366,6 +389,7 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
366
389
|
const routeTarget = this.captureRouteTarget(this.props);
|
|
367
390
|
if (routeTarget) this.setRouteTarget(routeTarget);
|
|
368
391
|
this.disposed = true;
|
|
392
|
+
this.setToolbarSlot(null);
|
|
369
393
|
this.selectionRestoreToken += 1;
|
|
370
394
|
this.cancelPendingTopFrame();
|
|
371
395
|
this.savePageOffset(this.state.selectedPage);
|
|
@@ -411,8 +435,11 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
411
435
|
|
|
412
436
|
private observeChrome() {
|
|
413
437
|
this.chromeObserver = new ResizeObserver(this.scheduleChromeMeasurement);
|
|
438
|
+
if (this.root) this.chromeObserver.observe(this.root);
|
|
414
439
|
if (this.headerContent) this.chromeObserver.observe(this.headerContent);
|
|
415
440
|
if (this.stickyContent) this.chromeObserver.observe(this.stickyContent);
|
|
441
|
+
if (this.tabList) this.chromeObserver.observe(this.tabList);
|
|
442
|
+
for (const button of this.tabButtons.values()) this.chromeObserver.observe(button);
|
|
416
443
|
this.scheduleChromeMeasurement();
|
|
417
444
|
}
|
|
418
445
|
|
|
@@ -439,6 +466,8 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
439
466
|
this.measuredStickyHeight = nextSticky;
|
|
440
467
|
this.headerMeasured = Boolean(header?.isConnected);
|
|
441
468
|
this.stickyMeasured = Boolean(sticky?.isConnected);
|
|
469
|
+
this.syncToolbar();
|
|
470
|
+
this.syncTabColors();
|
|
442
471
|
if (headerChanged || stickyChanged) {
|
|
443
472
|
this.forceUpdate();
|
|
444
473
|
this.scheduleScrollConfiguration();
|
|
@@ -580,6 +609,23 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
580
609
|
this.scrollCurrentPageToTop(0, options?.animated ?? true);
|
|
581
610
|
};
|
|
582
611
|
|
|
612
|
+
public scrollHeaderBy = (delta: number) => {
|
|
613
|
+
if (!Number.isFinite(delta)) return;
|
|
614
|
+
const offset = Math.min(
|
|
615
|
+
this.headerHeight,
|
|
616
|
+
Math.max(0, this.sharedHeaderOffset + delta)
|
|
617
|
+
);
|
|
618
|
+
this.scrollCurrentPageToTop(offset, false);
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
public scrollHeaderToOffset = (offset: number) => {
|
|
622
|
+
if (!Number.isFinite(offset)) return;
|
|
623
|
+
this.scrollCurrentPageToTop(
|
|
624
|
+
Math.min(this.headerHeight, Math.max(0, offset)),
|
|
625
|
+
false
|
|
626
|
+
);
|
|
627
|
+
};
|
|
628
|
+
|
|
583
629
|
public scrollToStickyTop = (options?: Readonly<{ animated?: boolean }>) => {
|
|
584
630
|
this.scrollCurrentPageToTop(
|
|
585
631
|
this.headerHeight,
|
|
@@ -674,10 +720,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
674
720
|
)
|
|
675
721
|
return;
|
|
676
722
|
this.pageOffsets.set(key, 0);
|
|
677
|
-
this.sharedHeaderOffset = offset;
|
|
723
|
+
this.sharedHeaderOffset = Math.min(this.headerHeight, Math.max(0, offset));
|
|
678
724
|
this.bodyAlignment = { element, key };
|
|
679
725
|
scrollElementTo(element, {
|
|
680
|
-
top:
|
|
726
|
+
top: this.sharedHeaderOffset,
|
|
681
727
|
behavior: animated ? "smooth" : "instant",
|
|
682
728
|
});
|
|
683
729
|
this.syncFallbackHeader();
|
|
@@ -724,21 +770,32 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
724
770
|
}
|
|
725
771
|
|
|
726
772
|
private finishPageTransition = () => {
|
|
773
|
+
this.transitionGeneration += 1;
|
|
727
774
|
if (this.transitionTimer !== null) {
|
|
728
775
|
clearTimeout(this.transitionTimer);
|
|
729
776
|
this.transitionTimer = null;
|
|
730
777
|
}
|
|
778
|
+
this.readTabProgress();
|
|
779
|
+
this.cancelTabProgressFrame();
|
|
780
|
+
this.syncTabColors();
|
|
731
781
|
this.emitPageScrollState("idle");
|
|
782
|
+
this.syncToolbar();
|
|
732
783
|
};
|
|
733
784
|
|
|
734
785
|
private beginPageTransition() {
|
|
786
|
+
this.suspendToolbar();
|
|
735
787
|
if (this.transitionTimer !== null) clearTimeout(this.transitionTimer);
|
|
788
|
+
const generation = ++this.transitionGeneration;
|
|
736
789
|
this.emitPageScrollState("settling");
|
|
737
|
-
this.transitionTimer = setTimeout(
|
|
790
|
+
this.transitionTimer = setTimeout(() => {
|
|
791
|
+
if (generation === this.transitionGeneration) this.finishPageTransition();
|
|
792
|
+
}, 320);
|
|
738
793
|
}
|
|
739
794
|
|
|
740
795
|
private onTrackTransitionEnd = (event: TransitionEvent) => {
|
|
741
796
|
if (event.target === this.track && event.propertyName === "transform") {
|
|
797
|
+
this.readTabProgress();
|
|
798
|
+
if (this.tabColorWeights() && this.tabProgress !== null && Math.abs(this.tabProgress - this.state.selectedPage) > 0.001) return;
|
|
742
799
|
this.finishPageTransition();
|
|
743
800
|
}
|
|
744
801
|
};
|
|
@@ -746,11 +803,200 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
746
803
|
private setTrack = (node: unknown) => {
|
|
747
804
|
const track = webElement(node);
|
|
748
805
|
if (track === this.track) return;
|
|
806
|
+
this.cancelTabProgressFrame();
|
|
749
807
|
this.track?.removeEventListener("transitionend", this.onTrackTransitionEnd);
|
|
750
808
|
this.track = track;
|
|
751
809
|
this.track?.addEventListener("transitionend", this.onTrackTransitionEnd);
|
|
752
810
|
};
|
|
753
811
|
|
|
812
|
+
private cancelTabProgressFrame() {
|
|
813
|
+
this.tabProgressGeneration += 1;
|
|
814
|
+
if (this.tabProgressFrame !== null) cancelAnimationFrame(this.tabProgressFrame);
|
|
815
|
+
this.tabProgressFrame = null;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
private readTabProgress() {
|
|
819
|
+
const track = this.track;
|
|
820
|
+
const width = this.root?.getBoundingClientRect().width ?? 0;
|
|
821
|
+
if (!track?.isConnected || width <= 0) return null;
|
|
822
|
+
const transform = track.ownerDocument.defaultView?.getComputedStyle(track).transform;
|
|
823
|
+
const matrix = transform?.match(/^matrix(3d)?\(([^)]+)\)$/);
|
|
824
|
+
const offset = matrix ? Number(matrix[2].split(",")[matrix[1] ? 12 : 4]) : transform === "none" ? 0 : NaN;
|
|
825
|
+
if (!Number.isFinite(offset)) return null;
|
|
826
|
+
this.tabProgress = Math.min(Math.max(0, -offset / width), Math.max(0, this.pages().length - 1));
|
|
827
|
+
return this.tabProgress;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
private startTabProgressFrames() {
|
|
831
|
+
this.cancelTabProgressFrame();
|
|
832
|
+
if (!this.tabColorWeights() || typeof requestAnimationFrame !== "function") return;
|
|
833
|
+
const track = this.track;
|
|
834
|
+
const root = this.root;
|
|
835
|
+
const width = root?.getBoundingClientRect().width ?? 0;
|
|
836
|
+
if (!track?.isConnected || !root?.isConnected || width <= 0 || this.props.isActive === false) return;
|
|
837
|
+
const generation = this.tabProgressGeneration;
|
|
838
|
+
const selection = this.selectionRestoreToken;
|
|
839
|
+
const keys = JSON.stringify(this.pages().map(pageKey));
|
|
840
|
+
const owner = this.pageScrollElement(this.state.selectedPage);
|
|
841
|
+
const sample = () => {
|
|
842
|
+
if (generation !== this.tabProgressGeneration || this.disposed) return;
|
|
843
|
+
this.tabProgressFrame = null;
|
|
844
|
+
if (this.track !== track || this.root !== root || !track.isConnected || !root.isConnected ||
|
|
845
|
+
this.props.isActive === false || selection !== this.selectionRestoreToken ||
|
|
846
|
+
keys !== JSON.stringify(this.pages().map(pageKey)) || owner !== this.pageScrollElement(this.state.selectedPage) ||
|
|
847
|
+
width !== root.getBoundingClientRect().width || !this.tabColorWeights()) {
|
|
848
|
+
this.cancelTabProgressFrame();
|
|
849
|
+
this.readTabProgress();
|
|
850
|
+
this.syncTabColors();
|
|
851
|
+
if (this.transitionTimer !== null) this.startTabProgressFrames();
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
this.readTabProgress();
|
|
855
|
+
this.syncTabColors();
|
|
856
|
+
if (this.transitionTimer !== null) this.tabProgressFrame = requestAnimationFrame(sample);
|
|
857
|
+
};
|
|
858
|
+
sample();
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
private tabColorWeights() {
|
|
862
|
+
const config = this.props.nativeTabBar;
|
|
863
|
+
const variant = config?.style?.variant;
|
|
864
|
+
if (!config?.controlled || (variant !== "text" && variant !== "pill") || this.tabProgress === null) return null;
|
|
865
|
+
// A pill that does not animate also snaps label colors to the selection.
|
|
866
|
+
if (variant === "pill" && config.style?.indicatorAnimationEnabled === false) return null;
|
|
867
|
+
const keys: string[] = [];
|
|
868
|
+
React.Children.forEach(this.props.children, child => {
|
|
869
|
+
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
870
|
+
});
|
|
871
|
+
const itemKeys = config.items.map(item => item.key);
|
|
872
|
+
if (!keys.length || !keys.includes(config.selectedKey ?? "") || new Set(keys).size !== keys.length ||
|
|
873
|
+
new Set(itemKeys).size !== itemKeys.length || keys.some(key => !itemKeys.includes(key))) return null;
|
|
874
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
875
|
+
const source = Math.floor(progress);
|
|
876
|
+
const destination = Math.min(source + 1, keys.length - 1);
|
|
877
|
+
const fraction = progress - source;
|
|
878
|
+
return new Map(keys.map((key, index) => [key, index === source ? 1 - fraction : index === destination ? fraction : 0]));
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
private tabFontOwnerKey(weights: Map<string, number> | null) {
|
|
882
|
+
const config = this.props.nativeTabBar;
|
|
883
|
+
const semantic = config?.controlled ? config.selectedKey : config?.items[this.state.selectedPage]?.key;
|
|
884
|
+
if (!weights || this.tabProgress === null) return semantic;
|
|
885
|
+
const keys = Array.from(weights.keys());
|
|
886
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
887
|
+
return keys[Math.floor(progress + 0.5)];
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
private tabColor(selected: boolean, weight: number | undefined) {
|
|
891
|
+
const style = this.props.nativeTabBar?.style;
|
|
892
|
+
const active = style?.activeTextColor ?? "#000000";
|
|
893
|
+
const inactive = style?.inactiveTextColor ?? "#666666";
|
|
894
|
+
if (weight === undefined) return String(selected ? active : inactive);
|
|
895
|
+
if (weight <= 0) return String(inactive);
|
|
896
|
+
if (weight >= 1) return String(active);
|
|
897
|
+
const first = processColor(inactive);
|
|
898
|
+
const last = processColor(active);
|
|
899
|
+
if (typeof first !== "number" || typeof last !== "number") return String(selected ? active : inactive);
|
|
900
|
+
const channel = (shift: number) => ((first >>> shift) & 255) * (1 - weight) + ((last >>> shift) & 255) * weight;
|
|
901
|
+
return `rgba(${Math.round(channel(16))}, ${Math.round(channel(8))}, ${Math.round(channel(0))}, ${(channel(24) / 255).toFixed(4)})`;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
private syncTabColors() {
|
|
905
|
+
const weights = this.tabColorWeights();
|
|
906
|
+
const config = this.props.nativeTabBar;
|
|
907
|
+
if (!config) return;
|
|
908
|
+
const selectedKey = config.controlled ? config.selectedKey : config.items[this.state.selectedPage]?.key;
|
|
909
|
+
const fontOwnerKey = this.tabFontOwnerKey(weights);
|
|
910
|
+
for (const [key, button] of this.tabButtons) {
|
|
911
|
+
const fontSelected = key === fontOwnerKey;
|
|
912
|
+
button.style.color = this.tabColor(key === selectedKey, weights ? weights.get(key) ?? 0 : undefined);
|
|
913
|
+
button.style.fontWeight = config.style?.variant === "text" && fontSelected ? "600" : "500";
|
|
914
|
+
const fontFamily = (fontSelected ? config.style?.activeFontFamily ?? config.style?.fontFamily : config.style?.fontFamily) ?? "";
|
|
915
|
+
if (config.controlled && config.style?.variant === "text") {
|
|
916
|
+
button.style.fontFamily = config.style?.fontFamily ?? "";
|
|
917
|
+
const label = button.querySelector<HTMLElement>(".ok-pager-tab-label");
|
|
918
|
+
if (label) label.style.fontFamily = fontFamily;
|
|
919
|
+
} else button.style.fontFamily = fontFamily;
|
|
920
|
+
}
|
|
921
|
+
this.syncTabPill(weights, selectedKey);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Positions the pill from the live button boxes on every sync. Nothing is
|
|
925
|
+
// cached per index, so a tab that only moved (same size, new position) still
|
|
926
|
+
// gets its own width and offset.
|
|
927
|
+
private syncTabPill(weights: Map<string, number> | null, selectedKey: string | undefined) {
|
|
928
|
+
const pill = this.tabPill;
|
|
929
|
+
if (!pill) return;
|
|
930
|
+
let fromKey = selectedKey;
|
|
931
|
+
let toKey = selectedKey;
|
|
932
|
+
let fraction = 0;
|
|
933
|
+
if (weights && this.tabProgress !== null) {
|
|
934
|
+
const keys = Array.from(weights.keys());
|
|
935
|
+
const progress = Math.min(Math.max(0, this.tabProgress), keys.length - 1);
|
|
936
|
+
const source = Math.floor(progress);
|
|
937
|
+
fromKey = keys[source];
|
|
938
|
+
toKey = keys[Math.min(source + 1, keys.length - 1)];
|
|
939
|
+
fraction = progress - source;
|
|
940
|
+
}
|
|
941
|
+
const from = fromKey === undefined ? undefined : this.tabButtons.get(fromKey);
|
|
942
|
+
const to = toKey === undefined ? undefined : this.tabButtons.get(toKey);
|
|
943
|
+
if (!from || !to || !from.isConnected || !to.isConnected || from.offsetWidth <= 0) {
|
|
944
|
+
pill.style.visibility = "hidden";
|
|
945
|
+
pill.removeAttribute("data-placed");
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
// Leading edge leads, trailing edge lags, like the JS pill this replaces.
|
|
949
|
+
const leading = 1 - (1 - fraction) * (1 - fraction);
|
|
950
|
+
const trailing = fraction * fraction;
|
|
951
|
+
const forward = to.offsetLeft >= from.offsetLeft;
|
|
952
|
+
const leftFraction = forward ? trailing : leading;
|
|
953
|
+
const rightFraction = forward ? leading : trailing;
|
|
954
|
+
const fromRight = from.offsetLeft + from.offsetWidth;
|
|
955
|
+
const toRight = to.offsetLeft + to.offsetWidth;
|
|
956
|
+
const left = from.offsetLeft + (to.offsetLeft - from.offsetLeft) * leftFraction;
|
|
957
|
+
const right = fromRight + (toRight - fromRight) * rightFraction;
|
|
958
|
+
const animationEnabled = this.props.nativeTabBar?.style?.indicatorAnimationEnabled !== false;
|
|
959
|
+
const animate = animationEnabled && pill.hasAttribute("data-placed") && this.tabProgressFrame === null && fraction === 0;
|
|
960
|
+
pill.style.transition = animate ? "transform 220ms cubic-bezier(0.2, 0, 0, 1), width 220ms cubic-bezier(0.2, 0, 0, 1)" : "none";
|
|
961
|
+
pill.style.top = `${from.offsetTop}px`;
|
|
962
|
+
pill.style.height = `${from.offsetHeight}px`;
|
|
963
|
+
pill.style.width = `${Math.max(0, right - left)}px`;
|
|
964
|
+
pill.style.transform = `translateX(${left}px)`;
|
|
965
|
+
pill.style.visibility = "visible";
|
|
966
|
+
pill.setAttribute("data-placed", "");
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
private setTabList = (node: HTMLDivElement | null) => {
|
|
970
|
+
if (node === this.tabList) return;
|
|
971
|
+
if (this.tabList) this.chromeObserver?.unobserve(this.tabList);
|
|
972
|
+
this.tabList = node;
|
|
973
|
+
if (node) this.chromeObserver?.observe(node);
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
private setTabPill = (node: HTMLDivElement | null) => {
|
|
977
|
+
this.tabPill = node;
|
|
978
|
+
if (node) this.syncTabColors();
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
private tabButtonRef(key: string) {
|
|
982
|
+
let ref = this.tabButtonRefs.get(key);
|
|
983
|
+
if (!ref) {
|
|
984
|
+
ref = (button: HTMLButtonElement | null) => this.setTabButton(key, button);
|
|
985
|
+
this.tabButtonRefs.set(key, ref);
|
|
986
|
+
}
|
|
987
|
+
return ref;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
private setTabButton(key: string, button: HTMLButtonElement | null) {
|
|
991
|
+
const previous = this.tabButtons.get(key);
|
|
992
|
+
if (previous === button) return;
|
|
993
|
+
if (previous) this.chromeObserver?.unobserve(previous);
|
|
994
|
+
if (button) {
|
|
995
|
+
this.tabButtons.set(key, button);
|
|
996
|
+
this.chromeObserver?.observe(button);
|
|
997
|
+
} else this.tabButtons.delete(key);
|
|
998
|
+
}
|
|
999
|
+
|
|
754
1000
|
private pageScrollElement(index: number) {
|
|
755
1001
|
const pageHost = this.pageHosts.get(index);
|
|
756
1002
|
return (
|
|
@@ -773,7 +1019,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
773
1019
|
this.root?.removeEventListener("touchend", this.onOverlayTouchEnd);
|
|
774
1020
|
this.root?.removeEventListener("touchcancel", this.onOverlayTouchEnd);
|
|
775
1021
|
this.overlayTouch = null;
|
|
1022
|
+
if (this.root) this.chromeObserver?.unobserve(this.root);
|
|
776
1023
|
this.root = root;
|
|
1024
|
+
if (root) this.chromeObserver?.observe(root);
|
|
1025
|
+
else this.suspendToolbar();
|
|
777
1026
|
root?.addEventListener(
|
|
778
1027
|
"ok-collapsible-pager-scroll-key-changed",
|
|
779
1028
|
this.onScrollOwnerIdentityChanged
|
|
@@ -1174,10 +1423,14 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1174
1423
|
this.savePageOffset(this.state.selectedPage);
|
|
1175
1424
|
|
|
1176
1425
|
if (animated) this.beginPageTransition();
|
|
1177
|
-
else
|
|
1426
|
+
else {
|
|
1427
|
+
this.finishPageTransition();
|
|
1428
|
+
this.tabProgress = position;
|
|
1429
|
+
}
|
|
1178
1430
|
this.setState(
|
|
1179
1431
|
{ selectedPage: position, animateTransition: animated },
|
|
1180
1432
|
() => {
|
|
1433
|
+
if (animated) this.startTabProgressFrames();
|
|
1181
1434
|
this.scheduleScrollConfiguration();
|
|
1182
1435
|
const restore = () => {
|
|
1183
1436
|
if (
|
|
@@ -1277,6 +1530,7 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1277
1530
|
this.cancelPendingTopFrame();
|
|
1278
1531
|
this.horizontalTouch = true;
|
|
1279
1532
|
this.emitPageScrollState("dragging");
|
|
1533
|
+
this.suspendToolbar();
|
|
1280
1534
|
}
|
|
1281
1535
|
};
|
|
1282
1536
|
|
|
@@ -1321,9 +1575,334 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1321
1575
|
if (wasHorizontal) this.finishPageTransition();
|
|
1322
1576
|
};
|
|
1323
1577
|
|
|
1578
|
+
private toolbarSlot: HTMLDivElement | null = null;
|
|
1579
|
+
private toolbarButton: HTMLButtonElement | null = null;
|
|
1580
|
+
private toolbarOwnerKey: string | undefined;
|
|
1581
|
+
private toolbarOwnerEntry: CollapsiblePagerToolbarItem | undefined;
|
|
1582
|
+
private toolbarIconIdentity = "";
|
|
1583
|
+
private toolbarLoadedIcon: SVGSVGElement | null = null;
|
|
1584
|
+
private toolbarPendingIdentity = "";
|
|
1585
|
+
private toolbarReadyIcon: SVGSVGElement | null = null;
|
|
1586
|
+
private toolbarFailedIdentity = "";
|
|
1587
|
+
private toolbarAnimation: Animation | null = null;
|
|
1588
|
+
private toolbarPresence = false;
|
|
1589
|
+
private toolbarPresenceInterrupted = false;
|
|
1590
|
+
private toolbarImage: HTMLImageElement | null = null;
|
|
1591
|
+
private toolbarGeneration = 0;
|
|
1592
|
+
private toolbarTouchKey: string | null | undefined;
|
|
1593
|
+
|
|
1594
|
+
private ownsSettledToolbar() {
|
|
1595
|
+
return this.props.nativeTabBar?.controlled === true && this.props.nativeTabBar.toolbar !== undefined;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
private toolbarCanCommit() {
|
|
1599
|
+
if (!this.ownsSettledToolbar()) return true;
|
|
1600
|
+
if (this.disposed || this.props.isActive === false || this.horizontalTouch ||
|
|
1601
|
+
this.transitionTimer !== null || this.pageScrollState !== "idle" || !this.root?.isConnected) return false;
|
|
1602
|
+
const actual = this.readTabProgress();
|
|
1603
|
+
if (actual === null || Math.abs(actual - this.state.selectedPage) > 0.001) return false;
|
|
1604
|
+
const config = this.props.nativeTabBar!;
|
|
1605
|
+
const keys: string[] = [];
|
|
1606
|
+
React.Children.forEach(this.props.children, child => {
|
|
1607
|
+
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
1608
|
+
});
|
|
1609
|
+
const itemKeys = config.items.map(item => item.key);
|
|
1610
|
+
const valid = keys.length > 0 && new Set(keys).size === keys.length &&
|
|
1611
|
+
new Set(itemKeys).size === itemKeys.length && keys.every(key => itemKeys.includes(key));
|
|
1612
|
+
return !valid || !keys.includes(config.selectedKey ?? "") || keys[this.state.selectedPage] === config.selectedKey;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
private cancelToolbarPending() {
|
|
1616
|
+
if (this.toolbarPendingIdentity || this.toolbarImage || this.toolbarReadyIcon) this.toolbarGeneration += 1;
|
|
1617
|
+
if (this.toolbarImage) this.toolbarImage.onload = this.toolbarImage.onerror = null;
|
|
1618
|
+
this.toolbarImage = null;
|
|
1619
|
+
this.toolbarPendingIdentity = "";
|
|
1620
|
+
this.toolbarReadyIcon = null;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
private setToolbarInteractive(enabled: boolean) {
|
|
1624
|
+
const button = this.toolbarButton;
|
|
1625
|
+
if (!button) return;
|
|
1626
|
+
if (!enabled) {
|
|
1627
|
+
if (button.ownerDocument.activeElement === button) button.blur();
|
|
1628
|
+
if (this.toolbarTouchKey !== undefined) this.toolbarTouchKey = null;
|
|
1629
|
+
}
|
|
1630
|
+
button.disabled = !enabled;
|
|
1631
|
+
button.style.pointerEvents = enabled ? "auto" : "none";
|
|
1632
|
+
button.tabIndex = enabled ? 0 : -1;
|
|
1633
|
+
button.setAttribute("aria-hidden", String(!enabled));
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
private suspendToolbar() {
|
|
1637
|
+
if (!this.ownsSettledToolbar()) return;
|
|
1638
|
+
this.setToolbarInteractive(false);
|
|
1639
|
+
this.cancelToolbarPending();
|
|
1640
|
+
if (this.toolbarAnimation && this.toolbarButton) {
|
|
1641
|
+
const opacity = this.toolbarButton.ownerDocument.defaultView?.getComputedStyle(this.toolbarButton).opacity;
|
|
1642
|
+
this.toolbarAnimation.cancel();
|
|
1643
|
+
this.toolbarAnimation = null;
|
|
1644
|
+
this.toolbarButton.style.opacity = opacity || this.toolbarButton.style.opacity;
|
|
1645
|
+
this.toolbarPresenceInterrupted = true;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
private setToolbarSlot = (slot: HTMLDivElement | null) => {
|
|
1650
|
+
if (this.toolbarSlot === slot) return;
|
|
1651
|
+
this.toolbarAnimation?.cancel();
|
|
1652
|
+
this.toolbarAnimation = null;
|
|
1653
|
+
this.cancelToolbarPending();
|
|
1654
|
+
this.toolbarGeneration += 1;
|
|
1655
|
+
this.toolbarButton?.remove();
|
|
1656
|
+
this.toolbarButton = null;
|
|
1657
|
+
this.toolbarOwnerKey = undefined;
|
|
1658
|
+
this.toolbarOwnerEntry = undefined;
|
|
1659
|
+
this.toolbarIconIdentity = "";
|
|
1660
|
+
this.toolbarLoadedIcon = null;
|
|
1661
|
+
this.toolbarFailedIdentity = "";
|
|
1662
|
+
this.toolbarPresence = false;
|
|
1663
|
+
this.toolbarPresenceInterrupted = false;
|
|
1664
|
+
this.toolbarTouchKey = null;
|
|
1665
|
+
this.toolbarSlot = slot;
|
|
1666
|
+
if (slot) this.syncToolbar();
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
private animateToolbar(visible: boolean) {
|
|
1670
|
+
const button = this.toolbarButton;
|
|
1671
|
+
if (!button || (this.toolbarPresence === visible && !this.toolbarPresenceInterrupted)) return;
|
|
1672
|
+
this.toolbarPresenceInterrupted = false;
|
|
1673
|
+
this.toolbarPresence = visible;
|
|
1674
|
+
const current = button.ownerDocument.defaultView?.getComputedStyle(button).opacity ?? button.style.opacity;
|
|
1675
|
+
this.toolbarAnimation?.cancel();
|
|
1676
|
+
this.toolbarAnimation = null;
|
|
1677
|
+
button.style.opacity = visible ? "1" : "0";
|
|
1678
|
+
const finish = () => {
|
|
1679
|
+
button.hidden = !visible;
|
|
1680
|
+
if (!visible && !this.toolbarOwnerKey && this.toolbarButton === button) {
|
|
1681
|
+
button.remove();
|
|
1682
|
+
this.toolbarButton = null;
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
if (typeof button.animate !== "function") { finish(); return; }
|
|
1686
|
+
button.hidden = false;
|
|
1687
|
+
const animation = button.animate([{ opacity: current || "0" }, { opacity: visible ? "1" : "0" }], { duration: 100, fill: "forwards" });
|
|
1688
|
+
this.toolbarAnimation = animation;
|
|
1689
|
+
animation.onfinish = () => {
|
|
1690
|
+
if (this.toolbarAnimation !== animation || this.toolbarButton !== button || this.toolbarPresence !== visible) return;
|
|
1691
|
+
animation.cancel();
|
|
1692
|
+
this.toolbarAnimation = null;
|
|
1693
|
+
finish();
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
private hideToolbar(failed: boolean) {
|
|
1698
|
+
this.setToolbarInteractive(false);
|
|
1699
|
+
this.toolbarOwnerKey = undefined;
|
|
1700
|
+
this.toolbarOwnerEntry = undefined;
|
|
1701
|
+
this.toolbarButton?.removeAttribute("data-testid");
|
|
1702
|
+
this.toolbarButton?.removeAttribute("aria-label");
|
|
1703
|
+
if (failed) this.toolbarButton?.replaceChildren();
|
|
1704
|
+
this.animateToolbar(false);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
private commitToolbar(key: string, entry: CollapsiblePagerToolbarItem, icon: SVGSVGElement, identity: string) {
|
|
1708
|
+
const button = this.toolbarButton;
|
|
1709
|
+
if (!button || !this.toolbarCanCommit()) return;
|
|
1710
|
+
if (this.toolbarOwnerKey !== key && this.toolbarTouchKey !== undefined) this.toolbarTouchKey = null;
|
|
1711
|
+
const size = Math.min(128, Math.max(1, entry.size ?? 38));
|
|
1712
|
+
const iconSize = Math.min(size, Math.max(1, entry.iconSize ?? 24));
|
|
1713
|
+
const contentWidth = Math.min(size, Math.max(0, entry.contentWidth ?? 24));
|
|
1714
|
+
const trailingInset = Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1715
|
+
if (button.firstChild !== icon) button.replaceChildren(icon);
|
|
1716
|
+
Object.assign(button.style, { position: "absolute", width: `${size}px`, height: `${size}px`, borderRadius: "50%", top: "50%", transform: "translateY(-50%)",
|
|
1717
|
+
insetInlineEnd: `${trailingInset - (size - contentWidth) / 2}px`, padding: `${(size - iconSize) / 2}px`, color: entry.iconColor ?? "#000000" });
|
|
1718
|
+
const base = entry.selected ? entry.selectedBackgroundColor ?? "transparent" : "transparent";
|
|
1719
|
+
button.style.setProperty("--pager-toolbar-base", base);
|
|
1720
|
+
button.style.setProperty("--pager-toolbar-hover", entry.hoverBackgroundColor ?? base);
|
|
1721
|
+
button.style.setProperty("--pager-toolbar-pressed", entry.pressedBackgroundColor ?? base);
|
|
1722
|
+
button.setAttribute("aria-label", entry.accessibilityLabel ?? "");
|
|
1723
|
+
if (entry.testID) button.setAttribute("data-testid", entry.testID); else button.removeAttribute("data-testid");
|
|
1724
|
+
this.toolbarOwnerKey = key;
|
|
1725
|
+
this.toolbarOwnerEntry = { ...entry };
|
|
1726
|
+
this.toolbarIconIdentity = identity;
|
|
1727
|
+
this.toolbarLoadedIcon = icon;
|
|
1728
|
+
this.toolbarPendingIdentity = "";
|
|
1729
|
+
this.toolbarReadyIcon = null;
|
|
1730
|
+
this.toolbarImage = null;
|
|
1731
|
+
this.animateToolbar(true);
|
|
1732
|
+
this.setToolbarInteractive(true);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
private syncToolbar() {
|
|
1736
|
+
const slot = this.toolbarSlot;
|
|
1737
|
+
if (!slot) return;
|
|
1738
|
+
if (!this.toolbarCanCommit()) { this.suspendToolbar(); return; }
|
|
1739
|
+
const config = this.props.nativeTabBar;
|
|
1740
|
+
const key = config?.controlled ? config.selectedKey : config?.items[this.state.selectedPage]?.key;
|
|
1741
|
+
const entry = key ? config?.toolbar?.[key] : undefined;
|
|
1742
|
+
if (!entry?.iconName || !key) {
|
|
1743
|
+
this.cancelToolbarPending();
|
|
1744
|
+
this.hideToolbar(false);
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
let button = this.toolbarButton;
|
|
1748
|
+
if (!button) {
|
|
1749
|
+
button = slot.ownerDocument.createElement("button");
|
|
1750
|
+
button.type = "button";
|
|
1751
|
+
button.className = "ok-pager-toolbar";
|
|
1752
|
+
button.style.opacity = "0";
|
|
1753
|
+
button.hidden = true;
|
|
1754
|
+
button.disabled = true;
|
|
1755
|
+
button.addEventListener("pointerdown", () => { this.toolbarTouchKey = button!.disabled ? null : this.toolbarOwnerKey ?? null; });
|
|
1756
|
+
button.addEventListener("pointercancel", () => { this.toolbarTouchKey = null; });
|
|
1757
|
+
button.onclick = event => {
|
|
1758
|
+
if (this.toolbarButton !== event.currentTarget) return;
|
|
1759
|
+
const pointer = event.detail !== 0;
|
|
1760
|
+
const touched = this.toolbarTouchKey;
|
|
1761
|
+
if (pointer) this.toolbarTouchKey = undefined;
|
|
1762
|
+
const current = this.props.nativeTabBar;
|
|
1763
|
+
const semantic = current?.controlled ? current.selectedKey : current?.items[this.state.selectedPage]?.key;
|
|
1764
|
+
const owner = this.toolbarOwnerKey;
|
|
1765
|
+
if (button!.disabled || !this.toolbarCanCommit() || !owner || owner !== semantic ||
|
|
1766
|
+
!this.toolbarOwnerEntry || (pointer && touched !== owner)) return;
|
|
1767
|
+
const rect = button!.getBoundingClientRect();
|
|
1768
|
+
this.props.onNativeToolbarPress?.({ nativeEvent: { key: owner,
|
|
1769
|
+
anchorRect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height } } } as ReactNative.NativeSyntheticEvent<CollapsiblePagerToolbarPress>);
|
|
1770
|
+
};
|
|
1771
|
+
slot.appendChild(button);
|
|
1772
|
+
this.toolbarButton = button;
|
|
1773
|
+
this.toolbarPresence = false;
|
|
1774
|
+
}
|
|
1775
|
+
const size = Math.min(128, Math.max(1, entry.size ?? 38));
|
|
1776
|
+
const iconSize = Math.min(size, Math.max(1, entry.iconSize ?? 24));
|
|
1777
|
+
const identity = `${entry.iconName}|${entry.iconColor ?? "#000000"}|${iconSize}`;
|
|
1778
|
+
if (identity === this.toolbarIconIdentity && this.toolbarLoadedIcon) {
|
|
1779
|
+
this.cancelToolbarPending();
|
|
1780
|
+
this.commitToolbar(key, entry, this.toolbarLoadedIcon, identity);
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
if (identity === this.toolbarPendingIdentity) {
|
|
1784
|
+
if (this.toolbarReadyIcon) this.commitToolbar(key, entry, this.toolbarReadyIcon, identity);
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
this.cancelToolbarPending();
|
|
1788
|
+
this.setToolbarInteractive(false);
|
|
1789
|
+
this.toolbarPendingIdentity = identity;
|
|
1790
|
+
if (identity === this.toolbarFailedIdentity) { this.hideToolbar(true); return; }
|
|
1791
|
+
const generation = ++this.toolbarGeneration;
|
|
1792
|
+
const icon = createNamedIcon(button.ownerDocument, entry.iconName);
|
|
1793
|
+
icon.setAttribute("width", String(iconSize)); icon.setAttribute("height", String(iconSize));
|
|
1794
|
+
const use = icon.querySelector("use");
|
|
1795
|
+
const fail = () => {
|
|
1796
|
+
if (this.toolbarGeneration !== generation || this.toolbarPendingIdentity !== identity) return;
|
|
1797
|
+
this.toolbarImage = null;
|
|
1798
|
+
this.toolbarFailedIdentity = identity;
|
|
1799
|
+
this.hideToolbar(true);
|
|
1800
|
+
};
|
|
1801
|
+
if (!use) { fail(); return; }
|
|
1802
|
+
const ready = () => {
|
|
1803
|
+
if (this.disposed || this.toolbarGeneration !== generation || this.toolbarPendingIdentity !== identity) return;
|
|
1804
|
+
this.toolbarImage = null;
|
|
1805
|
+
this.toolbarReadyIcon = icon;
|
|
1806
|
+
this.syncToolbar();
|
|
1807
|
+
};
|
|
1808
|
+
const href = use.getAttribute("href") ?? use.getAttribute("xlink:href") ?? "";
|
|
1809
|
+
const view = button.ownerDocument.defaultView;
|
|
1810
|
+
if (view?.Image && href.split("#")[0]) {
|
|
1811
|
+
const image = new view.Image();
|
|
1812
|
+
this.toolbarImage = image;
|
|
1813
|
+
image.onload = ready;
|
|
1814
|
+
image.onerror = fail;
|
|
1815
|
+
image.src = href.split("#")[0];
|
|
1816
|
+
} else ready();
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
private renderNativeTabBar() {
|
|
1820
|
+
const config = this.props.nativeTabBar;
|
|
1821
|
+
if (!config?.items.length || (config.style?.variant !== "text" && config.controlled !== true && config.toolbar === undefined)) return null;
|
|
1822
|
+
const style = config.style;
|
|
1823
|
+
const variant = style?.variant ?? "underline";
|
|
1824
|
+
const selectedKey = config.controlled ? config.selectedKey : config.items[this.state.selectedPage]?.key;
|
|
1825
|
+
const toolbarEntries = config.toolbar === undefined ? undefined : Object.values(config.toolbar);
|
|
1826
|
+
const reservedWidth = toolbarEntries === undefined ? 0 : toolbarEntries.length === 0 ? 44 : Math.max(...toolbarEntries.map(entry => {
|
|
1827
|
+
const size = Math.min(128, Math.max(1, entry.size ?? 38));
|
|
1828
|
+
return Math.min(size, Math.max(0, entry.contentWidth ?? 24)) + Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1829
|
+
}));
|
|
1830
|
+
const segmented = variant === "segmented";
|
|
1831
|
+
const pill = variant === "pill";
|
|
1832
|
+
const reserveTextFaces = config.controlled && variant === "text";
|
|
1833
|
+
const itemPadding = style?.itemPaddingHorizontal ?? (variant === "text" ? 10 : pill ? 14 : 8);
|
|
1834
|
+
const cssColor = (value: ReactNative.ColorValue | undefined) => value === undefined ? "transparent" : String(value);
|
|
1835
|
+
for (const key of this.tabButtonRefs.keys()) {
|
|
1836
|
+
if (!config.items.some(item => item.key === key)) this.tabButtonRefs.delete(key);
|
|
1837
|
+
}
|
|
1838
|
+
const colorWeights = this.tabColorWeights();
|
|
1839
|
+
const fontOwnerKey = this.tabFontOwnerKey(colorWeights);
|
|
1840
|
+
return React.createElement("div", {
|
|
1841
|
+
className: "ok-pager-tab-bar",
|
|
1842
|
+
dir: this.props.layoutDirection === "rtl" || ((this.props.layoutDirection ?? "locale") === "locale" && I18nManager.isRTL) ? "rtl" : "ltr",
|
|
1843
|
+
"data-variant": variant,
|
|
1844
|
+
style: { display: "flex", alignItems: "center", position: "relative", height: style?.height ?? 44,
|
|
1845
|
+
backgroundColor: String(style?.backgroundColor ?? "transparent"), minWidth: 0,
|
|
1846
|
+
["--pager-tab-hover" as string]: cssColor(style?.itemHoverBackgroundColor),
|
|
1847
|
+
["--pager-tab-pressed" as string]: cssColor(style?.itemPressedBackgroundColor) },
|
|
1848
|
+
},
|
|
1849
|
+
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)}`),
|
|
1850
|
+
React.createElement("div", { className: "ok-pager-tab-row", style: { display: "flex", alignItems: "center", height: "100%", flex: 1, minWidth: 0,
|
|
1851
|
+
maxWidth: style?.contentMaxWidth, margin: style?.contentMaxWidth === undefined ? undefined : "0 auto" } },
|
|
1852
|
+
React.createElement("div", { role: "tablist", className: "ok-pager-tablist", ref: this.setTabList, style: { display: "flex", overflowX: segmented ? "hidden" : "auto", flex: 1,
|
|
1853
|
+
position: "relative", alignItems: "center",
|
|
1854
|
+
padding: `${style?.contentPaddingVertical ?? 0}px ${style?.contentPaddingHorizontal ?? 20}px`, gap: style?.itemSpacing ?? 8 } },
|
|
1855
|
+
pill ? React.createElement("div", { key: "ok-pager-tab-pill", ref: this.setTabPill, className: "ok-pager-tab-pill", "aria-hidden": true,
|
|
1856
|
+
style: { position: "absolute", left: 0, top: 0, width: 0, height: 0, borderRadius: 999, pointerEvents: "none", visibility: "hidden",
|
|
1857
|
+
backgroundColor: String(style?.indicatorColor ?? "#000000"), willChange: "transform, width" } }) : null,
|
|
1858
|
+
...config.items.map((item, position) => {
|
|
1859
|
+
const selected = item.key === selectedKey;
|
|
1860
|
+
const fontSelected = item.key === fontOwnerKey;
|
|
1861
|
+
return React.createElement("button", {
|
|
1862
|
+
key: item.key, role: "tab", type: "button", className: "ok-pager-tab", "aria-selected": selected,
|
|
1863
|
+
ref: this.tabButtonRef(item.key),
|
|
1864
|
+
"aria-label": item.accessibilityLabel ?? item.title, "data-testid": item.testID,
|
|
1865
|
+
style: { padding: `6px ${itemPadding}px`, minWidth: 44, height: (style?.height ?? 44) - 2 * (style?.contentPaddingVertical ?? 0),
|
|
1866
|
+
fontSize: style?.fontSize ?? (variant === "text" ? 18 : 16),
|
|
1867
|
+
fontWeight: variant === "text" && fontSelected ? 600 : 500,
|
|
1868
|
+
fontFamily: reserveTextFaces ? style?.fontFamily : fontSelected ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily,
|
|
1869
|
+
display: reserveTextFaces ? "inline-grid" : undefined,
|
|
1870
|
+
gridTemplateAreas: reserveTextFaces ? '"label"' : undefined,
|
|
1871
|
+
alignItems: reserveTextFaces ? "center" : undefined,
|
|
1872
|
+
color: this.tabColor(selected, colorWeights ? colorWeights.get(item.key) ?? 0 : undefined),
|
|
1873
|
+
flex: segmented ? 1 : undefined, borderRadius: segmented || pill ? 999 : 0,
|
|
1874
|
+
// Pill items leave the background to CSS so hover / pressed apply.
|
|
1875
|
+
backgroundColor: pill ? undefined : segmented && selected ? String(style?.indicatorColor ?? "transparent") : "transparent",
|
|
1876
|
+
borderBottom: variant === "underline" && selected ? `${style?.indicatorHeight ?? 2}px solid ${String(style?.indicatorColor ?? "#000000")}` : undefined },
|
|
1877
|
+
onClick: () => {
|
|
1878
|
+
if (!config.controlled) {
|
|
1879
|
+
const animated = this.props.nativeTabPressAnimationEnabled ?? Math.abs(position - this.state.selectedPage) <= 1;
|
|
1880
|
+
if (animated) this.setPage(position); else this.setPageWithoutAnimation(position);
|
|
1881
|
+
}
|
|
1882
|
+
this.props.onNativeTabPress?.({ nativeEvent: { position, key: item.key } } as CollapsiblePagerViewOnNativeTabPressEvent);
|
|
1883
|
+
},
|
|
1884
|
+
}, reserveTextFaces ? [
|
|
1885
|
+
React.createElement("span", { key: "label", className: "ok-pager-tab-label", style: {
|
|
1886
|
+
gridArea: "label", fontFamily: fontSelected ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily,
|
|
1887
|
+
} }, item.title),
|
|
1888
|
+
...[false, true].map(active => React.createElement("span", {
|
|
1889
|
+
key: active ? "active-width" : "normal-width", "aria-hidden": true,
|
|
1890
|
+
style: { gridArea: "label", visibility: "hidden", pointerEvents: "none", userSelect: "none",
|
|
1891
|
+
fontWeight: active ? 600 : 500,
|
|
1892
|
+
fontFamily: active ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily },
|
|
1893
|
+
}, item.title)),
|
|
1894
|
+
] : item.title);
|
|
1895
|
+
})),
|
|
1896
|
+
config.toolbar !== undefined ? React.createElement("div", { ref: this.setToolbarSlot, className: "ok-pager-toolbar-slot", style: { flexShrink: 0, width: reservedWidth, height: "100%", position: "relative" } }) : null));
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1324
1899
|
render() {
|
|
1325
1900
|
const {
|
|
1326
1901
|
children: _children,
|
|
1902
|
+
nativeTabBar: _nativeTabBar,
|
|
1903
|
+
nativeTabPressAnimationEnabled: _nativeTabPressAnimationEnabled,
|
|
1904
|
+
onNativeTabPress: _onNativeTabPress,
|
|
1905
|
+
onNativeToolbarPress: _onNativeToolbarPress,
|
|
1327
1906
|
header,
|
|
1328
1907
|
stickyHeader,
|
|
1329
1908
|
topOverlay: _topOverlay,
|
|
@@ -1332,6 +1911,7 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1332
1911
|
externalTopOverlayTag: _externalTopOverlayTag,
|
|
1333
1912
|
headerHeight: _headerHeight,
|
|
1334
1913
|
stickyHeaderHeight: _stickyHeaderHeight,
|
|
1914
|
+
stickyHeaderHeights: _stickyHeaderHeights,
|
|
1335
1915
|
isActive: _isActive,
|
|
1336
1916
|
pageRetentionDistance: _pageRetentionDistance,
|
|
1337
1917
|
layoutDirection: _layoutDirection,
|
|
@@ -1419,8 +1999,8 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1419
1999
|
collapseAnimation,
|
|
1420
2000
|
]}
|
|
1421
2001
|
>
|
|
1422
|
-
{this.hasExplicitStickyHeaderHeight ? stickyHeader : (
|
|
1423
|
-
<View ref={this.setStickyContent}>{stickyHeader}</View>
|
|
2002
|
+
{this.hasExplicitStickyHeaderHeight ? <>{this.renderNativeTabBar()}{stickyHeader}</> : (
|
|
2003
|
+
<View ref={this.setStickyContent}>{this.renderNativeTabBar()}{stickyHeader}</View>
|
|
1424
2004
|
)}
|
|
1425
2005
|
</View>
|
|
1426
2006
|
<View
|