@onekeyfe/react-native-pager-view 6.7.0-5 → 6.7.0-50

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.
Files changed (49) hide show
  1. package/README.md +159 -115
  2. package/android/build.gradle +1 -0
  3. package/android/src/androidTest/AndroidManifest.xml +7 -0
  4. package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +476 -0
  5. package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +233 -43
  6. package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +596 -27
  7. package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +40 -0
  8. package/android/src/main/java/com/reactnativepagerview/NativeScrollerScrollAwayInsets.kt +19 -0
  9. package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
  10. package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +8 -2
  11. package/android/src/main/java/com/reactnativepagerview/event/NativeHeaderPressEvent.kt +8 -0
  12. package/android/src/test/java/com/reactnativepagerview/NativeScrollerScrollAwayInsetsTest.kt +40 -0
  13. package/docs/SPEC.md +694 -10
  14. package/ios/RNCCollapsiblePagerViewComponentView.mm +2225 -94
  15. package/ios/RNCNativeScrollerComponentView.h +2 -0
  16. package/ios/RNCNativeScrollerComponentView.mm +42 -0
  17. package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +586 -1
  18. package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +1116 -0
  19. package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +74 -9
  20. package/ios/tests/RNCCollapsiblePagerRefreshControlTests.mm +50 -0
  21. package/lib/module/CollapsiblePagerView.js +75 -11
  22. package/lib/module/CollapsiblePagerView.web.js +653 -8
  23. package/lib/module/CollapsiblePagerViewNativeComponent.ts +57 -42
  24. package/lib/module/NativeScroller.web.js +3 -0
  25. package/lib/module/NativeScrollerNativeComponent.ts +42 -46
  26. package/lib/module/PagerViewNativeComponent.ts +20 -25
  27. package/lib/module/WebCollapsiblePagerPage.js +7 -2
  28. package/lib/typescript/src/CollapsiblePagerView.d.ts +62 -4
  29. package/lib/typescript/src/CollapsiblePagerView.web.d.ts +56 -2
  30. package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +54 -38
  31. package/lib/typescript/src/NativeScroller.d.ts +5 -3
  32. package/lib/typescript/src/NativeScroller.web.d.ts +1 -1
  33. package/lib/typescript/src/NativeScrollerNativeComponent.d.ts +47 -48
  34. package/lib/typescript/src/PagerView.d.ts +1 -1
  35. package/lib/typescript/src/PagerView.web.d.ts +1 -1
  36. package/lib/typescript/src/PagerViewNativeComponent.d.ts +20 -21
  37. package/lib/typescript/src/WebCollapsiblePagerPage.d.ts +1 -1
  38. package/lib/typescript/src/usePagerView.d.ts +2 -2
  39. package/lib/typescript/src/utils.d.ts +2 -2
  40. package/package.json +20 -7
  41. package/react-native-pager-view.podspec +1 -0
  42. package/src/CollapsiblePagerView.tsx +208 -12
  43. package/src/CollapsiblePagerView.web.tsx +587 -7
  44. package/src/CollapsiblePagerViewNativeComponent.ts +57 -42
  45. package/src/NativeScroller.tsx +14 -4
  46. package/src/NativeScroller.web.tsx +15 -1
  47. package/src/NativeScrollerNativeComponent.ts +42 -46
  48. package/src/PagerViewNativeComponent.ts +20 -25
  49. package/src/WebCollapsiblePagerPage.tsx +7 -2
package/README.md CHANGED
@@ -1,5 +1,158 @@
1
+ <div align="center">
2
+
1
3
  # @onekeyfe/react-native-pager-view
2
4
 
5
+ **OneKey's Fabric fork of `react-native-pager-view`: swipeable pages, a collapsible shared header and a native vertical scroller.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-pager-view?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-pager-view)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-pager-view?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Android](https://img.shields.io/badge/Android-3DDC84?logo=android&logoColor=white)
11
+ ![Web](https://img.shields.io/badge/Web-4285F4?logo=googlechrome&logoColor=white)
12
+ ![Fabric](https://img.shields.io/badge/Fabric-4D6BFE)
13
+
14
+ </div>
15
+
16
+ PagerView flips horizontally or vertically between keyed child pages, rendered by
17
+ a Fabric native view on iOS and Android and by a DOM fallback on Web. This fork
18
+ adds `CollapsiblePagerView` — a header that collapses into a pinned sticky bar
19
+ while pages keep their own offsets and retention window — and `NativeScroller`, a
20
+ non-virtualized vertical scroller that joins that collapse. Upstream remains the
21
+ reference for the original pager behavior.
22
+
23
+ ## Features
24
+
25
+ - **Native paging** — horizontal/vertical pages with `setPage`,
26
+ `setPageWithoutAnimation`, `setScrollEnabled` and page events.
27
+ - **Collapsible shared header** — native scroll coordination on mobile and CSS
28
+ scroll timelines on Web via `WebCollapsiblePagerView`.
29
+ - **Bounded page retention** — the selected page and configured neighbours stay
30
+ mounted while distant subtrees are unmounted and restored at their offset.
31
+ - **Native tab bar** — underline, segmented, text and pill variants, toolbar
32
+ slots and controlled selection.
33
+
34
+ ## Installation
35
+
36
+ ```sh
37
+ yarn add @onekeyfe/react-native-pager-view \
38
+ @onekeyfe/react-native-image \
39
+ @onekeyfe/react-native-native-logger
40
+ ```
41
+
42
+ Peer dependencies: `react`, `react-native`, `@onekeyfe/react-native-image` (Web
43
+ icon helper) and `@onekeyfe/react-native-native-logger` (Android logging). Install
44
+ the app's iOS pods and rebuild the native binary; JavaScript-only does not
45
+ register the views:
46
+
47
+ ```sh
48
+ cd ios && pod install
49
+ ```
50
+
51
+ Android links through autolinking; deployment floors are iOS 15.1 and Android
52
+ API 24.
53
+
54
+ ## Usage
55
+
56
+ ```tsx
57
+ import PagerView, {
58
+ type PagerViewOnPageSelectedEvent,
59
+ } from '@onekeyfe/react-native-pager-view';
60
+ import { Text, View } from 'react-native';
61
+
62
+ <PagerView
63
+ style={{ flex: 1 }}
64
+ initialPage={0}
65
+ onPageSelected={(event: PagerViewOnPageSelectedEvent) => {
66
+ console.log('selected page', event.nativeEvent.position);
67
+ }}
68
+ >
69
+ <View key="welcome" style={{ flex: 1 }}>
70
+ <Text>Welcome</Text>
71
+ </View>
72
+ <View key="wallet" style={{ flex: 1 }}>
73
+ <Text>Wallet</Text>
74
+ </View>
75
+ </PagerView>
76
+ ```
77
+
78
+ The application owns page keys, content and any JS header chrome; the pager owns
79
+ page placement and gestures. Every child must be a keyed `<View>`.
80
+
81
+ ## API
82
+
83
+ ### Exports
84
+
85
+ | Export | Platforms | Description |
86
+ | --- | :-: | --- |
87
+ | `PagerView` (default) | iOS, Android, Web | Swipeable page container; native page host on mobile, DOM fallback on Web. |
88
+ | `CollapsiblePagerView` | iOS, Android, Web | Collapsible header + sticky bar wrapper. |
89
+ | `WebCollapsiblePagerView`, `useWebCollapsiblePagerPage()` | Web | Explicit Web collapse root that measures omitted heights, and the selected page's scroll owner. |
90
+ | `NativeScroller` | iOS, Android, Web | Non-virtualized vertical scroller; the Web export is a `ScrollView` implementation. |
91
+ | `usePagerView({ pagesAmount })` | iOS, Android, Web | Animated pager progress, scroll state and add/remove page helpers. |
92
+ | `ScrollEdgeEffect` | iOS | `hard` / `soft` values for iOS 26 top scroll-edge effects. |
93
+
94
+ ### `PagerView` props
95
+
96
+ | Prop | Type | Default | Platforms | Description |
97
+ | --- | --- | --- | :-: | --- |
98
+ | `initialPage`, `scrollEnabled`, `orientation` | `number`, `boolean`, `'horizontal' \| 'vertical'` | `0`, `true`, `'horizontal'` | all | First page, swipe enablement and paging axis. |
99
+ | `overdrag`, `pageMargin`, `layoutDirection` | `boolean`, `number`, `'ltr' \| 'rtl' \| 'locale'` | `false`, `0`, `'ltr'` | all | Past-edge movement, gap between pages and LTR/RTL order. |
100
+ | `nestedScrollEnabled` | `boolean` | `false` | iOS | Coordinates gestures with a parent pager at sub-tab boundaries. |
101
+ | `scrollSensitivity`, `keyboardDismissMode`, `offscreenPageLimit` | platform props | `2`, `none`, native | Android | Gesture sensitivity (`2`–`8`), keyboard dismissal and offscreen pages. |
102
+ | `onPageScroll`, `onPageSelected`, `onPageScrollStateChanged` | event callbacks | — | all | `{ position, offset }`, `{ position }` and `idle`/`dragging`/`settling`. |
103
+
104
+ The ref exposes `setPage`, `setPageWithoutAnimation` and `setScrollEnabled`.
105
+
106
+ ### `CollapsiblePagerView` props
107
+
108
+ | Prop | Type | Platforms | Description |
109
+ | --- | --- | :-: | --- |
110
+ | `header`, `stickyHeader`, `headerHeight`, `stickyHeaderHeight` | `ReactNode`, `number` | all | Collapsible content, the bar pinned after collapse and their measured heights. |
111
+ | `pageRetentionDistance` | `number` | all | Pages retained on each side of the selection. Defaults to `1`. |
112
+ | `nativeTabBar` | config object | iOS, Android, Web | Items, `controlled`/`selectedKey`, toolbar map and style variant. |
113
+ | `nativeTabPressAnimationEnabled` | `boolean` | iOS, Android | Per-press animation policy; see Caveats. |
114
+ | `onMountedPagesChanged`, `onCollapsibleStateChanged` | event callbacks | all | Mount state and settled diagnostics. |
115
+ | `topOverlay`, `topScrollEdgeEffect` | `ReactNode`, `'hard' \| 'soft'` | iOS 26+ | Fixed overlay above the header and UIKit's scroll-edge effect. |
116
+
117
+ The ref exposes `scrollHeaderBy(delta)` and `scrollHeaderToOffset(offset)` to move
118
+ the active page's collapse position.
119
+
120
+ ## Platform support
121
+
122
+ | Capability | iOS | Android | Web |
123
+ | --- | :-: | :-: | :-: |
124
+ | `PagerView` paging, events and imperative commands | ✅ | ✅ | ✅ DOM fallback |
125
+ | `CollapsiblePagerView` shared-header collapse | ✅ native | ✅ native | ✅ CSS scroll timelines |
126
+ | Page retention `pageRetentionDistance` | ✅ | ✅ | ✅ |
127
+ | Native tab bar (underline/segmented/text/pill) | ✅ | ✅ | ✅ text/pill |
128
+ | `NativeScroller` non-virtualized scroller | ✅ | ✅ | ⚠️ `ScrollView` implementation |
129
+ | iOS 26 top overlay / scroll-edge effect | ✅ | — | — |
130
+
131
+ ## Caveats
132
+
133
+ > [!IMPORTANT]
134
+ > Keep page child keys stable. Retention unmounts distant pages but keeps their
135
+ > slots and offsets; changing a key resets that page's retained state.
136
+
137
+ > [!WARNING]
138
+ > Omitting `nativeTabPressAnimationEnabled` animates adjacent tab presses and
139
+ > jumps for non-adjacent pages. Earlier versions animated every press — pass
140
+ > `true` to restore that behavior.
141
+
142
+ > [!NOTE]
143
+ > `NativeScroller` is not a virtualized list. Horizontal scrolling, sticky rows,
144
+ > snapping, zoom, automatic keyboard insets and the full ScrollView responder
145
+ > API are not provided.
146
+
147
+ ## References
148
+
149
+ - [Scroll and collapse contract](docs/SPEC.md)
150
+ - Example pages: [pager](../../example/react-native/pages/PagerViewTestPage.tsx) and [collapsible pager](../../example/react-native/pages/MarketNativePagerExamplePage.tsx)
151
+ - [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-pager-view)
152
+ - [Changelog](../../CHANGELOG.md)
153
+
154
+ ## Upstream attribution
155
+
3
156
  First, a sincere thank-you to Callstack and the
4
157
  `react-native-pager-view` maintainers for their excellent work 🙏
5
158
 
@@ -16,124 +169,15 @@ unable to keep this work in patch form.
16
169
  As the gap grew, we ultimately forked `react-native-pager-view` to keep
17
170
  development and delivery stable.
18
171
 
19
- ## Upstream Project
20
-
21
- - Repository: [callstack/react-native-pager-view](https://github.com/callstack/react-native-pager-view)
172
+ - Upstream repository:
173
+ [callstack/react-native-pager-view](https://github.com/callstack/react-native-pager-view)
22
174
  - License: MIT
23
-
24
- ## Notes
25
-
26
175
  - This fork includes OneKey-specific adaptations for our product requirements.
27
- - If you are looking for original behavior and full documentation, please refer
28
- to the upstream repository.
29
-
30
- ## Collapsible pager
31
-
32
- `CollapsiblePagerView` is an opt-in container. The default `PagerView` export
33
- keeps its existing page lifetime and native implementation.
34
-
35
- ```tsx
36
- <CollapsiblePagerView
37
- header={<Header />}
38
- stickyHeader={<Tabs />}
39
- headerHeight={measuredHeaderHeight}
40
- stickyHeaderHeight={measuredTabsHeight}
41
- pageRetentionDistance={1}
42
- onMountedPagesChanged={({ mountedPages }) => {
43
- // Selected page plus one neighbour on each side by default.
44
- }}
45
- onCollapsibleStateChanged={({ nativeEvent }) => {
46
- // Settled diagnostics: headerOffset, native/attached page counts, etc.
47
- }}
48
- >
49
- {pages.map((page) => (
50
- <View key={page.key}>{page.content}</View>
51
- ))}
52
- </CollapsiblePagerView>
53
- ```
54
-
55
- Page keys must remain stable. The selected page and configured neighbours stay
56
- mounted for preheating; distant page slots remain in the pager while their
57
- React/native heavy subtrees are unmounted. iOS and Android retain a per-key
58
- scroll offset and preserve the shared header collapse when pages change. A
59
- NativeList can additionally restore its own stable item-key anchor when it is
60
- remounted; the pager does not replace that list-level anchor protocol or its
61
- cell reuse.
62
-
63
- On iOS the component observes the current `UIScrollView` content offset without
64
- replacing its delegate. Android coordinates nested scroll with the active
65
- `RecyclerView`. Web uses the active NativeList viewport automatically; another
66
- Web scroll child can opt in by exposing a DOM element with
67
- `data-collapsible-pager-scroll`. CSS scroll timelines drive header/sticky
68
- movement, so React is not updated on each vertical scroll frame.
69
-
70
- On Web, `WebCollapsiblePagerView` is an explicit root export of the existing Web
71
- pager. It measures Header and sticky content when their heights are omitted.
72
- `isActive` describes route visibility; the pager preserves a pending scroll
73
- target across a short or temporarily hidden page and retries when real content
74
- geometry becomes ready. `useWebCollapsiblePagerPage()` exposes the selected
75
- page's scroll owner, visible metrics, content registration and pending target
76
- to descendants. These Web-only APIs require a DOM when mounted. Native callers
77
- continue to use `CollapsiblePagerView`.
78
-
79
- On iOS and Android, `nativeTabBar` renders the tab bar natively and
80
- `onNativeTabPress` reports presses. By default, adjacent tab presses animate and
81
- non-adjacent presses jump directly to the target without passing intermediate
82
- pages. Set `nativeTabPressAnimationEnabled={true}` to always animate, or `false`
83
- to always jump. Swipe gestures and imperative page commands are unchanged.
84
-
85
- > **Behavior change:** earlier versions animated every native tab press when
86
- > `nativeTabPressAnimationEnabled` was omitted. Pass
87
- > `nativeTabPressAnimationEnabled={true}` to keep that behavior.
176
+ - For original behavior and full documentation, refer to the upstream repository.
88
177
 
89
178
  Thank you again to Callstack and everyone who contributes to
90
179
  `react-native-pager-view` 💙
91
180
 
92
- The native ancestor-scroll contribution protocol is specified in [docs/SPEC.md](docs/SPEC.md).
93
-
94
- ## NativeScroller compatibility
95
-
96
- The independent iOS/Android `NativeScroller` has passing native builds and
97
- focused simulator checks. The complete acceptance matrix remains open; see
98
- [docs/SPEC.md](docs/SPEC.md) for the verified cases and limits. It is a
99
- non-virtualized vertical scroller with one internal React content View. Fabric/Yoga lays out React children and content padding; size
100
- changes are sent to native through layout props, not a JavaScript scroll loop.
101
- Shared Fabric native state tracks local scroll displacement and ancestor header
102
- travel separately, without per-frame JavaScript coordination. Descendant hit
103
- testing and `measureInWindow` use that state; device acceptance must compare the
104
- reported coordinates with visible React content after scrolling and page return.
105
- The automatic flexGrow minimum uses a native-reported usable content height,
106
- with static pager reservations accounted for once. This internal size event is
107
- not public API and does not run on scroll frames. Before it arrives the automatic
108
- minimum is zero; a larger explicit numeric minHeight remains authoritative.
109
- Refresh insets and content-dependent bottom fill do not change this minimum.
110
- Web continues using its existing ScrollView implementation.
111
-
112
- The supported ScrollView subset is `contentContainerStyle` (including padding,
113
- height, numeric minHeight and flexGrow), `onContentSizeChange`, `scrollEnabled`,
114
- `nestedScrollEnabled`, indicators, `bounces`, `alwaysBounceVertical`,
115
- `contentInset`, keyboard dismissal/persist-tap modes, `scrollEventThrottle`, and
116
- the scroll/drag/momentum callbacks. Standard View props remain available.
117
- `decelerationRate` applies on iOS; Android uses AndroidX's native fling physics.
118
- `bounces`/`alwaysBounceVertical` and refresh tint/title are iOS controls; Android
119
- uses refresh colors/background/size and does not expose a bounce policy here.
120
- Tap-to-dismiss uses RN 0.86's JavaScript TextInput registry to preserve taps on
121
- another input and child-handled presses; keyboard behavior requires device checks.
122
- Horizontal scrolling, sticky rows, snapping, zoom, automatic keyboard insets and
123
- the full ScrollView responder API are not provided.
124
-
125
- Pass a standard `<RefreshControl refreshing={value} onRefresh={callback} />` as
126
- `refreshControl`. Its enabled, tint/colors, background, offset, title/title color
127
- and size props map to the component's native refresh controller; the RN refresh
128
- element is not mounted. Refreshing remains controlled even if the callback does
129
- not change the value. Arbitrary custom refresh components are not supported.
130
-
131
- `NativeScrollerRef` exposes `scrollTo`, `scrollToEnd`, `flashScrollIndicators`,
132
- host measurement/focus methods, `getNativeScrollRef` and `getScrollableNode`.
133
- `pagerScrollKey` remains the stable primary-scroller identity. Native command
134
- events use the ScrollView event shape; UIKit/AndroidX continue owning gestures
135
- and momentum. Animated commands whose clamped target differs from the current
136
- position emit a momentum begin/end pair; a no-op emits no new pair. A new command,
137
- new touch, content-root replacement or detach ends the previous active sequence.
138
- The focused JS tests verify wrapper routing, not native scrolling,
139
- Yoga rendering, keyboard interaction or refresh placement on a device.
181
+ ## License
182
+
183
+ MIT. See [LICENSE](LICENSE).
@@ -227,6 +227,7 @@ dependencies {
227
227
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
228
228
  implementation 'androidx.viewpager2:viewpager2:1.1.0'
229
229
  implementation project(":onekeyfe_react-native-native-logger")
230
+ implementation project(":onekeyfe_react-native-image")
230
231
  }
231
232
 
232
233
  if (isNewArchitectureEnabled()) {
@@ -0,0 +1,7 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <application android:supportsRtl="true">
3
+ <activity
4
+ android:name="com.reactnativepagerview.CollapsiblePagerHitTestActivity"
5
+ android:exported="false" />
6
+ </application>
7
+ </manifest>