@onekeyfe/react-native-pager-view 3.0.119 → 3.0.121

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.
@@ -2,6 +2,7 @@ package com.reactnativepagerview
2
2
 
3
3
  import android.view.View
4
4
  import android.view.ViewGroup
5
+ import android.graphics.Color
5
6
  import androidx.viewpager2.widget.ViewPager2
6
7
  import com.facebook.react.bridge.ReadableArray
7
8
  import com.facebook.react.common.MapBuilder
@@ -18,6 +19,7 @@ import com.reactnativepagerview.event.CollapsibleStateChangedEvent
18
19
  import com.reactnativepagerview.event.PageScrollEvent
19
20
  import com.reactnativepagerview.event.PageScrollStateChangedEvent
20
21
  import com.reactnativepagerview.event.PageSelectedEvent
22
+ import com.reactnativepagerview.event.NativeHeaderPressEvent
21
23
  import org.json.JSONArray
22
24
  import kotlin.math.roundToInt
23
25
 
@@ -41,13 +43,16 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
41
43
  )
42
44
  host.pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
43
45
  override fun onPageScrolled(position: Int, offset: Float, offsetPixels: Int) {
46
+ host.updateNativeTabProgress(position, offset)
44
47
  dispatch(reactContext, host, PageScrollEvent(host.id, position, offset))
45
48
  }
46
49
 
47
50
  override fun onPageSelected(position: Int) {
48
51
  host.selectPage(position)
52
+ host.updateNativeTabProgress(position, 0f)
49
53
  dispatch(reactContext, host, PageSelectedEvent(host.id, position))
50
54
  dispatchDiagnostics(reactContext, host, "page-selected")
55
+ host.logPagerState("page-selected")
51
56
  }
52
57
 
53
58
  override fun onPageScrollStateChanged(state: Int) {
@@ -60,9 +65,34 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
60
65
  dispatch(reactContext, host, PageScrollStateChangedEvent(host.id, value))
61
66
  if (state == ViewPager2.SCROLL_STATE_IDLE) {
62
67
  dispatchDiagnostics(reactContext, host, "pager-idle")
68
+ host.logPagerState("idle")
63
69
  }
64
70
  }
65
71
  })
72
+ host.onNativeTabPress = { position, key ->
73
+ dispatch(
74
+ reactContext,
75
+ host,
76
+ NativeHeaderPressEvent(
77
+ host.id,
78
+ position,
79
+ key,
80
+ NativeHeaderPressEvent.TAB_EVENT_NAME,
81
+ ),
82
+ )
83
+ }
84
+ host.onNativeSubHeaderPress = { position, key ->
85
+ dispatch(
86
+ reactContext,
87
+ host,
88
+ NativeHeaderPressEvent(
89
+ host.id,
90
+ position,
91
+ key,
92
+ NativeHeaderPressEvent.SUB_HEADER_EVENT_NAME,
93
+ ),
94
+ )
95
+ }
66
96
  host.onHeaderOffsetChanged = {
67
97
  if (!host.pager.isFakeDragging && host.pager.scrollState == ViewPager2.SCROLL_STATE_IDLE) {
68
98
  dispatchDiagnostics(reactContext, host, "vertical-idle")
@@ -123,11 +153,11 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
123
153
 
124
154
  @ReactProp(name = "layoutDirection")
125
155
  override fun setLayoutDirection(view: CollapsiblePagerHost?, value: String?) {
126
- view?.pager?.layoutDirection = if (value == "rtl") {
156
+ view?.setPagerLayoutDirection(if (value == "rtl") {
127
157
  View.LAYOUT_DIRECTION_RTL
128
158
  } else {
129
159
  View.LAYOUT_DIRECTION_LTR
130
- }
160
+ })
131
161
  }
132
162
 
133
163
  @ReactProp(name = "initialPage", defaultInt = 0)
@@ -151,11 +181,12 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
151
181
  // OneKey patch: CollapsiblePagerHost always coordinates nested pagers on Android.
152
182
  }
153
183
 
154
- // The smooth shared-header ownership is implemented on iOS first.
155
184
  override fun setNativeSmoothHeaderScrollEnabled(
156
185
  view: CollapsiblePagerHost?,
157
186
  value: Boolean,
158
- ) = Unit
187
+ ) {
188
+ view?.nativeSmoothHeaderScrollEnabled = value
189
+ }
159
190
 
160
191
  // OneKey patch: round Yoga header dimensions to the nearest physical pixel.
161
192
  @ReactProp(name = "headerHeight", defaultInt = 0)
@@ -179,41 +210,91 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
179
210
  view?.retainedPages = value ?: "[]"
180
211
  }
181
212
 
182
- // The optional native tab bar is implemented on iOS first. These no-op
183
- // setters preserve the shared Fabric contract without changing Android UI.
184
- override fun setNativeTabBarItems(view: CollapsiblePagerHost?, value: String?) = Unit
213
+ override fun setNativeTabBarItems(view: CollapsiblePagerHost?, value: String?) {
214
+ view?.updateNativeTabBarItems(value)
215
+ }
185
216
 
186
- override fun setNativeTabBarHeight(view: CollapsiblePagerHost?, value: Double) = Unit
217
+ override fun setNativeTabBarHeight(view: CollapsiblePagerHost?, value: Double) {
218
+ view ?: return
219
+ view.nativeTabBarHeight = value
220
+ view.applyNativeHeaderStyle()
221
+ }
187
222
 
188
223
  override fun setNativeTabBarContentPaddingHorizontal(
189
224
  view: CollapsiblePagerHost?,
190
225
  value: Double,
191
- ) = Unit
226
+ ) {
227
+ view ?: return
228
+ view.nativeTabBarContentPaddingHorizontal = value
229
+ view.applyNativeHeaderStyle()
230
+ }
192
231
 
193
- override fun setNativeTabBarItemSpacing(view: CollapsiblePagerHost?, value: Double) = Unit
232
+ override fun setNativeTabBarItemSpacing(view: CollapsiblePagerHost?, value: Double) {
233
+ view ?: return
234
+ view.nativeTabBarItemSpacing = value
235
+ view.applyNativeHeaderStyle()
236
+ }
194
237
 
195
- override fun setNativeTabBarFontSize(view: CollapsiblePagerHost?, value: Double) = Unit
238
+ override fun setNativeTabBarFontSize(view: CollapsiblePagerHost?, value: Double) {
239
+ view ?: return
240
+ view.nativeTabBarFontSize = value
241
+ view.applyNativeHeaderStyle()
242
+ }
196
243
 
197
- override fun setNativeTabBarFontFamily(view: CollapsiblePagerHost?, value: String?) = Unit
244
+ override fun setNativeTabBarFontFamily(view: CollapsiblePagerHost?, value: String?) {
245
+ view ?: return
246
+ view.nativeTabBarFontFamily = value
247
+ view.applyNativeHeaderStyle()
248
+ }
198
249
 
199
- override fun setNativeTabBarBackgroundColor(view: CollapsiblePagerHost?, value: Int?) = Unit
250
+ override fun setNativeTabBarBackgroundColor(view: CollapsiblePagerHost?, value: Int?) {
251
+ view ?: return
252
+ view.nativeTabBarBackgroundColor = value ?: Color.TRANSPARENT
253
+ view.applyNativeHeaderStyle()
254
+ }
200
255
 
201
- override fun setNativeTabBarActiveTextColor(view: CollapsiblePagerHost?, value: Int?) = Unit
256
+ override fun setNativeTabBarActiveTextColor(view: CollapsiblePagerHost?, value: Int?) {
257
+ view ?: return
258
+ view.nativeTabBarActiveTextColor = value ?: Color.BLACK
259
+ view.applyNativeHeaderStyle()
260
+ }
202
261
 
203
- override fun setNativeTabBarInactiveTextColor(view: CollapsiblePagerHost?, value: Int?) = Unit
262
+ override fun setNativeTabBarInactiveTextColor(view: CollapsiblePagerHost?, value: Int?) {
263
+ view ?: return
264
+ view.nativeTabBarInactiveTextColor = value ?: Color.GRAY
265
+ view.applyNativeHeaderStyle()
266
+ }
204
267
 
205
- override fun setNativeTabBarIndicatorColor(view: CollapsiblePagerHost?, value: Int?) = Unit
268
+ override fun setNativeTabBarIndicatorColor(view: CollapsiblePagerHost?, value: Int?) {
269
+ view ?: return
270
+ view.nativeTabBarIndicatorColor = value ?: view.nativeTabBarActiveTextColor
271
+ view.applyNativeHeaderStyle()
272
+ }
206
273
 
207
- override fun setNativeTabBarIndicatorHeight(view: CollapsiblePagerHost?, value: Double) = Unit
274
+ override fun setNativeTabBarIndicatorHeight(view: CollapsiblePagerHost?, value: Double) {
275
+ view ?: return
276
+ view.nativeTabBarIndicatorHeight = value
277
+ view.applyNativeHeaderStyle()
278
+ }
208
279
 
209
- override fun setNativeTabBarIndicatorBottom(view: CollapsiblePagerHost?, value: Double) = Unit
280
+ override fun setNativeTabBarIndicatorBottom(view: CollapsiblePagerHost?, value: Double) {
281
+ view ?: return
282
+ view.nativeTabBarIndicatorBottom = value
283
+ view.applyNativeHeaderStyle()
284
+ }
210
285
 
211
- override fun setNativeSubHeaderConfig(view: CollapsiblePagerHost?, value: String?) = Unit
286
+ override fun setNativeSubHeaderConfig(view: CollapsiblePagerHost?, value: String?) {
287
+ view?.updateNativeSubHeader(value)
288
+ }
212
289
 
213
290
  override fun setNativeSubHeaderSelectedBackgroundColor(
214
291
  view: CollapsiblePagerHost?,
215
292
  value: Int?,
216
- ) = Unit
293
+ ) {
294
+ view ?: return
295
+ view.nativeSubHeaderSelectedBackgroundColor = value ?: Color.TRANSPARENT
296
+ view.applyNativeHeaderStyle()
297
+ }
217
298
 
218
299
  private fun parseStringArray(value: String?): List<String> {
219
300
  if (value.isNullOrEmpty()) return emptyList()
@@ -255,6 +336,14 @@ class CollapsiblePagerViewManager : ViewGroupManager<CollapsiblePagerHost>(),
255
336
  CollapsibleStateChangedEvent.EVENT_NAME,
256
337
  MapBuilder.of("registrationName", "onCollapsibleStateChanged"),
257
338
  )
339
+ .put(
340
+ NativeHeaderPressEvent.TAB_EVENT_NAME,
341
+ MapBuilder.of("registrationName", "onNativeTabPress"),
342
+ )
343
+ .put(
344
+ NativeHeaderPressEvent.SUB_HEADER_EVENT_NAME,
345
+ MapBuilder.of("registrationName", "onNativeSubHeaderPress"),
346
+ )
258
347
  .build()
259
348
  .toMutableMap()
260
349
 
@@ -32,7 +32,7 @@ open class NestedScrollableHost : FrameLayout {
32
32
  private var touchSlop = 0
33
33
  private var initialX = 0f
34
34
  private var initialY = 0f
35
- private var nativeGestureStarted: Boolean = false
35
+ protected var nestedNativeGestureStarted: Boolean = false
36
36
  private val parentViewPager: ViewPager2?
37
37
  get() {
38
38
  var v: View? = parent as? View
@@ -110,7 +110,7 @@ open class NestedScrollableHost : FrameLayout {
110
110
 
111
111
  if (scaledDx > touchSlop || scaledDy > touchSlop) {
112
112
  NativeGestureUtil.notifyNativeGestureStarted(this, e)
113
- nativeGestureStarted = true
113
+ nestedNativeGestureStarted = true
114
114
 
115
115
  if (orientation == null) return
116
116
  if (isVpHorizontal == (scaledDy > scaledDx)) {
@@ -132,9 +132,9 @@ open class NestedScrollableHost : FrameLayout {
132
132
 
133
133
  override fun onTouchEvent(e: MotionEvent): Boolean {
134
134
  if (e.actionMasked == MotionEvent.ACTION_UP) {
135
- if (nativeGestureStarted) {
135
+ if (nestedNativeGestureStarted) {
136
136
  NativeGestureUtil.notifyNativeGestureEnded(this, e)
137
- nativeGestureStarted = false
137
+ nestedNativeGestureStarted = false
138
138
  }
139
139
  }
140
140
  return super.onTouchEvent(e)
@@ -0,0 +1,31 @@
1
+ package com.reactnativepagerview.event
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.WritableMap
5
+ import com.facebook.react.uimanager.events.Event
6
+ import com.facebook.react.uimanager.events.RCTEventEmitter
7
+
8
+ class NativeHeaderPressEvent(
9
+ viewTag: Int,
10
+ private val position: Int,
11
+ private val key: String,
12
+ private val name: String,
13
+ ) : Event<NativeHeaderPressEvent>(viewTag) {
14
+ override fun getEventName() = name
15
+
16
+ override fun canCoalesce() = false
17
+
18
+ override fun dispatch(rctEventEmitter: RCTEventEmitter) {
19
+ rctEventEmitter.receiveEvent(viewTag, eventName, serializeEventData())
20
+ }
21
+
22
+ private fun serializeEventData(): WritableMap = Arguments.createMap().apply {
23
+ putInt("position", position)
24
+ putString("key", key)
25
+ }
26
+
27
+ companion object {
28
+ const val TAB_EVENT_NAME = "topNativeTabPress"
29
+ const val SUB_HEADER_EVENT_NAME = "topNativeSubHeaderPress"
30
+ }
31
+ }
@@ -73,7 +73,7 @@ export class CollapsiblePagerView extends React.PureComponent {
73
73
  return React.Children.toArray(this.props.children);
74
74
  }
75
75
  nativeTabBarEnabled() {
76
- return Platform.OS === "ios" && !!this.props.nativeTabBar?.items.length;
76
+ return (Platform.OS === "ios" || Platform.OS === "android") && !!this.props.nativeTabBar?.items.length;
77
77
  }
78
78
  dispatchNativeTabPageCommand(position, animated) {
79
79
  const commandId = ++this.nativeTabCommandId;
@@ -169,9 +169,9 @@ export class CollapsiblePagerView extends React.PureComponent {
169
169
  const pageKeys = pages.map(pageKey);
170
170
  const retained = new Set(this.mountedPages(pages.length));
171
171
  const deducedLayoutDirection = !layoutDirection || layoutDirection === "locale" ? I18nManager.isRTL ? "rtl" : "ltr" : layoutDirection;
172
- const nativeTabBarEnabled = Platform.OS === "ios" && !!nativeTabBar?.items.length;
172
+ const nativeTabBarEnabled = (Platform.OS === "ios" || Platform.OS === "android") && !!nativeTabBar?.items.length;
173
173
  const nativeTabBarStyle = nativeTabBar?.style;
174
- const nativeSubHeaderEnabled = Platform.OS === "ios" && !!nativeSubHeader?.items.length;
174
+ const nativeSubHeaderEnabled = (Platform.OS === "ios" || Platform.OS === "android") && !!nativeSubHeader?.items.length;
175
175
  const nativeSubHeaderStyle = nativeSubHeader?.style;
176
176
  const nativeSubHeaderConfig = nativeSubHeaderEnabled ? JSON.stringify({
177
177
  ...nativeSubHeader,
@@ -65,8 +65,8 @@ export interface CollapsiblePagerViewProps extends Omit<NativeProps, "children"
65
65
  /** Measured sticky bar height. */
66
66
  stickyHeaderHeight: number;
67
67
  /**
68
- * Lets the active iOS list own vertical gestures that begin on pager headers.
69
- * Defaults to false and currently has no effect on Android or Web.
68
+ * Lets the active native list own vertical gestures that begin on pager headers.
69
+ * Defaults to false and has no effect on Web.
70
70
  */
71
71
  nativeSmoothHeaderScrollEnabled?: boolean;
72
72
  /**
@@ -76,10 +76,10 @@ export interface CollapsiblePagerViewProps extends Omit<NativeProps, "children"
76
76
  */
77
77
  pageRetentionDistance?: number;
78
78
  layoutDirection?: "ltr" | "rtl" | "locale";
79
- /** Optional native tab bar. It is currently rendered on iOS only. */
79
+ /** Optional native tab bar for iOS and Android. */
80
80
  nativeTabBar?: CollapsiblePagerNativeTabBarConfig;
81
81
  onNativeTabPress?: (event: CollapsiblePagerViewOnNativeTabPressEvent) => void;
82
- /** Optional native secondary sticky header. It is currently rendered on iOS only. */
82
+ /** Optional native secondary sticky header for iOS and Android. */
83
83
  nativeSubHeader?: CollapsiblePagerNativeSubHeaderConfig;
84
84
  onNativeSubHeaderPress?: (event: CollapsiblePagerViewOnNativeSubHeaderPressEvent) => void;
85
85
  children?: React.ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-pager-view",
3
- "version": "3.0.119",
3
+ "version": "3.0.121",
4
4
  "description": "React Native wrapper for Android and iOS ViewPager",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -39,7 +39,7 @@
39
39
  "prepare": "rm -rf lib && bob build",
40
40
  "typecheck": "tsc -b",
41
41
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
42
- "test": "jest",
42
+ "test": "node --test src/__tests__/*.cjs",
43
43
  "release": "yarn prepare && npm whoami && npm publish --access public"
44
44
  },
45
45
  "keywords": [
@@ -67,6 +67,7 @@
67
67
  "typescript": "^5.9.2"
68
68
  },
69
69
  "peerDependencies": {
70
+ "@onekeyfe/react-native-native-logger": "3.0.121",
70
71
  "react": "*",
71
72
  "react-native": "*"
72
73
  },
@@ -115,8 +115,8 @@ export interface CollapsiblePagerViewProps
115
115
  /** Measured sticky bar height. */
116
116
  stickyHeaderHeight: number;
117
117
  /**
118
- * Lets the active iOS list own vertical gestures that begin on pager headers.
119
- * Defaults to false and currently has no effect on Android or Web.
118
+ * Lets the active native list own vertical gestures that begin on pager headers.
119
+ * Defaults to false and has no effect on Web.
120
120
  */
121
121
  nativeSmoothHeaderScrollEnabled?: boolean;
122
122
  /**
@@ -126,10 +126,10 @@ export interface CollapsiblePagerViewProps
126
126
  */
127
127
  pageRetentionDistance?: number;
128
128
  layoutDirection?: "ltr" | "rtl" | "locale";
129
- /** Optional native tab bar. It is currently rendered on iOS only. */
129
+ /** Optional native tab bar for iOS and Android. */
130
130
  nativeTabBar?: CollapsiblePagerNativeTabBarConfig;
131
131
  onNativeTabPress?: (event: CollapsiblePagerViewOnNativeTabPressEvent) => void;
132
- /** Optional native secondary sticky header. It is currently rendered on iOS only. */
132
+ /** Optional native secondary sticky header for iOS and Android. */
133
133
  nativeSubHeader?: CollapsiblePagerNativeSubHeaderConfig;
134
134
  onNativeSubHeaderPress?: (
135
135
  event: CollapsiblePagerViewOnNativeSubHeaderPressEvent
@@ -248,7 +248,10 @@ export class CollapsiblePagerView extends React.PureComponent<
248
248
  }
249
249
 
250
250
  private nativeTabBarEnabled() {
251
- return Platform.OS === "ios" && !!this.props.nativeTabBar?.items.length;
251
+ return (
252
+ (Platform.OS === "ios" || Platform.OS === "android") &&
253
+ !!this.props.nativeTabBar?.items.length
254
+ );
252
255
  }
253
256
 
254
257
  private dispatchNativeTabPageCommand(position: number, animated: boolean) {
@@ -393,10 +396,12 @@ export class CollapsiblePagerView extends React.PureComponent<
393
396
  : "ltr"
394
397
  : layoutDirection;
395
398
  const nativeTabBarEnabled =
396
- Platform.OS === "ios" && !!nativeTabBar?.items.length;
399
+ (Platform.OS === "ios" || Platform.OS === "android") &&
400
+ !!nativeTabBar?.items.length;
397
401
  const nativeTabBarStyle = nativeTabBar?.style;
398
402
  const nativeSubHeaderEnabled =
399
- Platform.OS === "ios" && !!nativeSubHeader?.items.length;
403
+ (Platform.OS === "ios" || Platform.OS === "android") &&
404
+ !!nativeSubHeader?.items.length;
400
405
  const nativeSubHeaderStyle = nativeSubHeader?.style;
401
406
  const nativeSubHeaderConfig = nativeSubHeaderEnabled
402
407
  ? JSON.stringify({