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

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.
@@ -242,6 +242,7 @@ private class CollapsiblePagerHorizontalItemsView(
242
242
  private fun updatePresentation() {
243
243
  if (buttons.isEmpty() || itemFrames.size != buttons.size) return
244
244
  val selectedIndex: Int
245
+ val scrollTargetCenterX: Float
245
246
  if (showsProgressIndicator) {
246
247
  val clamped = progress.coerceIn(0f, buttons.lastIndex.toFloat())
247
248
  val lower = floor(clamped).toInt()
@@ -249,8 +250,10 @@ private class CollapsiblePagerHorizontalItemsView(
249
250
  val fraction = clamped - lower
250
251
  val from = itemFrames[lower]
251
252
  val to = itemFrames[upper]
252
- val indicatorX = (from[2] + (to[2] - from[2]) * fraction).roundToInt()
253
- val indicatorWidth = (from[3] + (to[3] - from[3]) * fraction).roundToInt()
253
+ val interpolatedIndicatorX = from[2] + (to[2] - from[2]) * fraction
254
+ val interpolatedIndicatorWidth = from[3] + (to[3] - from[3]) * fraction
255
+ val indicatorX = interpolatedIndicatorX.roundToInt()
256
+ val indicatorWidth = interpolatedIndicatorWidth.roundToInt()
254
257
  val indicatorTop = max(0, measuredHeight - indicatorBottomPx - indicatorHeightPx)
255
258
  indicator.layout(
256
259
  indicatorX,
@@ -259,6 +262,7 @@ private class CollapsiblePagerHorizontalItemsView(
259
262
  indicatorTop + indicatorHeightPx,
260
263
  )
261
264
  indicator.visibility = if (indicatorHeightPx > 0) VISIBLE else GONE
265
+ scrollTargetCenterX = interpolatedIndicatorX + interpolatedIndicatorWidth / 2f
262
266
  selectedIndex = clamped.roundToInt()
263
267
  buttons.forEachIndexed { index, button ->
264
268
  val emphasis = 1f - min(1f, kotlin.math.abs(clamped - index))
@@ -268,6 +272,8 @@ private class CollapsiblePagerHorizontalItemsView(
268
272
  }
269
273
  } else {
270
274
  selectedIndex = items.indexOfFirst { item -> item.key == selectedKey }
275
+ val frame = itemFrames.getOrNull(selectedIndex)
276
+ scrollTargetCenterX = frame?.let { it[0] + it[1] / 2f } ?: 0f
271
277
  indicator.visibility = GONE
272
278
  buttons.forEachIndexed { index, button ->
273
279
  val selected = index == selectedIndex
@@ -278,8 +284,7 @@ private class CollapsiblePagerHorizontalItemsView(
278
284
  }
279
285
 
280
286
  if (centerSelectionWhenIdle && !isTouchDragging && width > 0 && selectedIndex in itemFrames.indices) {
281
- val frame = itemFrames[selectedIndex]
282
- val desired = (frame[0] + frame[1] / 2 - width / 2)
287
+ val desired = (scrollTargetCenterX - width / 2f).roundToInt()
283
288
  .coerceIn(0, max(0, content.measuredWidth - width))
284
289
  scrollTo(desired, 0)
285
290
  centerSelectionWhenIdle = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-pager-view",
3
- "version": "3.0.121",
3
+ "version": "3.0.122",
4
4
  "description": "React Native wrapper for Android and iOS ViewPager",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -67,7 +67,7 @@
67
67
  "typescript": "^5.9.2"
68
68
  },
69
69
  "peerDependencies": {
70
- "@onekeyfe/react-native-native-logger": "3.0.121",
70
+ "@onekeyfe/react-native-native-logger": "3.0.122",
71
71
  "react": "*",
72
72
  "react-native": "*"
73
73
  },