@onekeyfe/react-native-pager-view 6.7.0-alpha.475 → 6.8.0-3
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 -136
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +21 -7
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +86 -14
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +1 -1
- package/docs/SPEC.md +124 -1
- package/ios/RNCCollapsiblePagerViewComponentView.mm +356 -19
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +166 -5
- package/lib/module/CollapsiblePagerView.js +6 -1
- package/lib/module/CollapsiblePagerView.web.js +132 -11
- package/lib/typescript/src/CollapsiblePagerView.d.ts +21 -1
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +8 -0
- package/package.json +1 -1
- package/src/CollapsiblePagerView.tsx +30 -1
- package/src/CollapsiblePagerView.web.tsx +110 -9
|
@@ -200,6 +200,9 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
200
200
|
private tabProgressFrame: number | null = null;
|
|
201
201
|
private tabProgressGeneration = 0;
|
|
202
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;
|
|
203
206
|
private headerSlot: HTMLElement | null = null;
|
|
204
207
|
private stickySlot: HTMLElement | null = null;
|
|
205
208
|
private cssTimelineSupported = false;
|
|
@@ -435,6 +438,8 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
435
438
|
if (this.root) this.chromeObserver.observe(this.root);
|
|
436
439
|
if (this.headerContent) this.chromeObserver.observe(this.headerContent);
|
|
437
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);
|
|
438
443
|
this.scheduleChromeMeasurement();
|
|
439
444
|
}
|
|
440
445
|
|
|
@@ -855,7 +860,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
855
860
|
|
|
856
861
|
private tabColorWeights() {
|
|
857
862
|
const config = this.props.nativeTabBar;
|
|
858
|
-
|
|
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;
|
|
859
867
|
const keys: string[] = [];
|
|
860
868
|
React.Children.forEach(this.props.children, child => {
|
|
861
869
|
if (child !== null && child !== undefined && typeof child !== "boolean") keys.push(pageKey(child, keys.length));
|
|
@@ -910,6 +918,83 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
910
918
|
if (label) label.style.fontFamily = fontFamily;
|
|
911
919
|
} else button.style.fontFamily = fontFamily;
|
|
912
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);
|
|
913
998
|
}
|
|
914
999
|
|
|
915
1000
|
private pageScrollElement(index: number) {
|
|
@@ -1743,26 +1828,41 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1743
1828
|
return Math.min(size, Math.max(0, entry.contentWidth ?? 24)) + Math.min(128, Math.max(0, entry.trailingInset ?? 20));
|
|
1744
1829
|
}));
|
|
1745
1830
|
const segmented = variant === "segmented";
|
|
1831
|
+
const pill = variant === "pill";
|
|
1746
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
|
+
}
|
|
1747
1838
|
const colorWeights = this.tabColorWeights();
|
|
1748
1839
|
const fontOwnerKey = this.tabFontOwnerKey(colorWeights);
|
|
1749
1840
|
return React.createElement("div", {
|
|
1750
1841
|
className: "ok-pager-tab-bar",
|
|
1751
1842
|
dir: this.props.layoutDirection === "rtl" || ((this.props.layoutDirection ?? "locale") === "locale" && I18nManager.isRTL) ? "rtl" : "ltr",
|
|
1843
|
+
"data-variant": variant,
|
|
1752
1844
|
style: { display: "flex", alignItems: "center", position: "relative", height: style?.height ?? 44,
|
|
1753
|
-
backgroundColor: String(style?.backgroundColor ?? "transparent"), minWidth: 0
|
|
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) },
|
|
1754
1848
|
},
|
|
1755
|
-
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-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)}`),
|
|
1756
|
-
React.createElement("div", {
|
|
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",
|
|
1757
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,
|
|
1758
1858
|
...config.items.map((item, position) => {
|
|
1759
1859
|
const selected = item.key === selectedKey;
|
|
1760
1860
|
const fontSelected = item.key === fontOwnerKey;
|
|
1761
1861
|
return React.createElement("button", {
|
|
1762
1862
|
key: item.key, role: "tab", type: "button", className: "ok-pager-tab", "aria-selected": selected,
|
|
1763
|
-
ref:
|
|
1863
|
+
ref: this.tabButtonRef(item.key),
|
|
1764
1864
|
"aria-label": item.accessibilityLabel ?? item.title, "data-testid": item.testID,
|
|
1765
|
-
style: { padding:
|
|
1865
|
+
style: { padding: `6px ${itemPadding}px`, minWidth: 44, height: (style?.height ?? 44) - 2 * (style?.contentPaddingVertical ?? 0),
|
|
1766
1866
|
fontSize: style?.fontSize ?? (variant === "text" ? 18 : 16),
|
|
1767
1867
|
fontWeight: variant === "text" && fontSelected ? 600 : 500,
|
|
1768
1868
|
fontFamily: reserveTextFaces ? style?.fontFamily : fontSelected ? style?.activeFontFamily ?? style?.fontFamily : style?.fontFamily,
|
|
@@ -1770,8 +1870,9 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1770
1870
|
gridTemplateAreas: reserveTextFaces ? '"label"' : undefined,
|
|
1771
1871
|
alignItems: reserveTextFaces ? "center" : undefined,
|
|
1772
1872
|
color: this.tabColor(selected, colorWeights ? colorWeights.get(item.key) ?? 0 : undefined),
|
|
1773
|
-
flex: segmented ? 1 : undefined, borderRadius: segmented ? 999 : 0,
|
|
1774
|
-
|
|
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",
|
|
1775
1876
|
borderBottom: variant === "underline" && selected ? `${style?.indicatorHeight ?? 2}px solid ${String(style?.indicatorColor ?? "#000000")}` : undefined },
|
|
1776
1877
|
onClick: () => {
|
|
1777
1878
|
if (!config.controlled) {
|
|
@@ -1792,7 +1893,7 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
1792
1893
|
}, item.title)),
|
|
1793
1894
|
] : item.title);
|
|
1794
1895
|
})),
|
|
1795
|
-
config.toolbar !== undefined ? React.createElement("div", { ref: this.setToolbarSlot, className: "ok-pager-toolbar-slot", style: { flexShrink: 0, width: reservedWidth, height: "100%", position: "relative" } }) : null);
|
|
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));
|
|
1796
1897
|
}
|
|
1797
1898
|
|
|
1798
1899
|
render() {
|