@onekeyfe/react-native-pager-view 3.0.120 → 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.
|
@@ -760,9 +760,10 @@ class CollapsiblePagerHost(context: Context) : NestedScrollableHost(context), Ne
|
|
|
760
760
|
|
|
761
761
|
private fun finishHeaderGesture(event: MotionEvent) {
|
|
762
762
|
val owner = headerGestureOwner.name.lowercase()
|
|
763
|
-
if (nativeGestureStarted) {
|
|
763
|
+
if (nativeGestureStarted || nestedNativeGestureStarted) {
|
|
764
764
|
NativeGestureUtil.notifyNativeGestureEnded(this, event)
|
|
765
765
|
nativeGestureStarted = false
|
|
766
|
+
nestedNativeGestureStarted = false
|
|
766
767
|
}
|
|
767
768
|
log(
|
|
768
769
|
"gesture-end action=${event.actionMasked} owner=$owner region=$headerTouchRegion " +
|
|
@@ -791,6 +792,7 @@ class CollapsiblePagerHost(context: Context) : NestedScrollableHost(context), Ne
|
|
|
791
792
|
forwardedRecycler = null
|
|
792
793
|
pressCancelled = false
|
|
793
794
|
nativeGestureStarted = false
|
|
795
|
+
nestedNativeGestureStarted = false
|
|
794
796
|
headerTouchRegion = headerRegionAt(event.y) ?: "none"
|
|
795
797
|
headerTouchActive = headerTouchRegion != "none"
|
|
796
798
|
if (!headerTouchActive) return super.dispatchTouchEvent(event)
|
|
@@ -979,6 +981,7 @@ class CollapsiblePagerHost(context: Context) : NestedScrollableHost(context), Ne
|
|
|
979
981
|
forwardedRecycler = null
|
|
980
982
|
pressCancelled = false
|
|
981
983
|
nativeGestureStarted = false
|
|
984
|
+
nestedNativeGestureStarted = false
|
|
982
985
|
viewTreeObserver.removeOnPreDrawListener(pageContentLayoutListener)
|
|
983
986
|
detachRecyclerObserver()
|
|
984
987
|
for (recycler in originalRecyclerPadding.keys.toList()) {
|
|
@@ -53,6 +53,9 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
53
53
|
private val density = resources.displayMetrics.density
|
|
54
54
|
private val content = FrameLayout(context)
|
|
55
55
|
private val indicator = View(context)
|
|
56
|
+
private val indicatorBackground = GradientDrawable().apply {
|
|
57
|
+
shape = GradientDrawable.RECTANGLE
|
|
58
|
+
}
|
|
56
59
|
private val buttons = ArrayList<TextView>()
|
|
57
60
|
private val itemFrames = ArrayList<IntArray>()
|
|
58
61
|
private var items: List<CollapsiblePagerNativeHeaderItem> = emptyList()
|
|
@@ -80,7 +83,8 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
80
83
|
isFillViewport = true
|
|
81
84
|
overScrollMode = OVER_SCROLL_NEVER
|
|
82
85
|
clipToPadding = false
|
|
83
|
-
|
|
86
|
+
indicator.background = indicatorBackground
|
|
87
|
+
content.addView(indicator, FrameLayout.LayoutParams(0, 0))
|
|
84
88
|
addView(
|
|
85
89
|
content,
|
|
86
90
|
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT),
|
|
@@ -141,6 +145,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
141
145
|
if (showsProgressIndicator) {
|
|
142
146
|
indicatorHeightPx = max(0, dp(indicatorHeight))
|
|
143
147
|
indicatorBottomPx = max(0, dp(indicatorBottom))
|
|
148
|
+
indicatorBackground.cornerRadius = indicatorHeightPx / 2f
|
|
144
149
|
}
|
|
145
150
|
applyTypeface()
|
|
146
151
|
requestLayout()
|
|
@@ -159,7 +164,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
159
164
|
this.inactiveTextColor = inactiveTextColor
|
|
160
165
|
this.selectedBackgroundColor = selectedBackgroundColor
|
|
161
166
|
this.indicatorColor = indicatorColor
|
|
162
|
-
|
|
167
|
+
indicatorBackground.setColor(indicatorColor)
|
|
163
168
|
updatePresentation()
|
|
164
169
|
}
|
|
165
170
|
|
|
@@ -216,7 +221,6 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
216
221
|
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY),
|
|
217
222
|
)
|
|
218
223
|
setMeasuredDimension(width, height)
|
|
219
|
-
updatePresentation()
|
|
220
224
|
}
|
|
221
225
|
|
|
222
226
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
@@ -238,6 +242,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
238
242
|
private fun updatePresentation() {
|
|
239
243
|
if (buttons.isEmpty() || itemFrames.size != buttons.size) return
|
|
240
244
|
val selectedIndex: Int
|
|
245
|
+
val scrollTargetCenterX: Float
|
|
241
246
|
if (showsProgressIndicator) {
|
|
242
247
|
val clamped = progress.coerceIn(0f, buttons.lastIndex.toFloat())
|
|
243
248
|
val lower = floor(clamped).toInt()
|
|
@@ -245,18 +250,19 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
245
250
|
val fraction = clamped - lower
|
|
246
251
|
val from = itemFrames[lower]
|
|
247
252
|
val to = itemFrames[upper]
|
|
248
|
-
val
|
|
249
|
-
val
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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()
|
|
257
|
+
val indicatorTop = max(0, measuredHeight - indicatorBottomPx - indicatorHeightPx)
|
|
258
|
+
indicator.layout(
|
|
259
|
+
indicatorX,
|
|
260
|
+
indicatorTop,
|
|
261
|
+
indicatorX + indicatorWidth,
|
|
262
|
+
indicatorTop + indicatorHeightPx,
|
|
263
|
+
)
|
|
254
264
|
indicator.visibility = if (indicatorHeightPx > 0) VISIBLE else GONE
|
|
255
|
-
|
|
256
|
-
shape = GradientDrawable.RECTANGLE
|
|
257
|
-
setColor(indicatorColor)
|
|
258
|
-
cornerRadius = indicatorHeightPx / 2f
|
|
259
|
-
}
|
|
265
|
+
scrollTargetCenterX = interpolatedIndicatorX + interpolatedIndicatorWidth / 2f
|
|
260
266
|
selectedIndex = clamped.roundToInt()
|
|
261
267
|
buttons.forEachIndexed { index, button ->
|
|
262
268
|
val emphasis = 1f - min(1f, kotlin.math.abs(clamped - index))
|
|
@@ -266,6 +272,8 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
266
272
|
}
|
|
267
273
|
} else {
|
|
268
274
|
selectedIndex = items.indexOfFirst { item -> item.key == selectedKey }
|
|
275
|
+
val frame = itemFrames.getOrNull(selectedIndex)
|
|
276
|
+
scrollTargetCenterX = frame?.let { it[0] + it[1] / 2f } ?: 0f
|
|
269
277
|
indicator.visibility = GONE
|
|
270
278
|
buttons.forEachIndexed { index, button ->
|
|
271
279
|
val selected = index == selectedIndex
|
|
@@ -276,8 +284,7 @@ private class CollapsiblePagerHorizontalItemsView(
|
|
|
276
284
|
}
|
|
277
285
|
|
|
278
286
|
if (centerSelectionWhenIdle && !isTouchDragging && width > 0 && selectedIndex in itemFrames.indices) {
|
|
279
|
-
val
|
|
280
|
-
val desired = (frame[0] + frame[1] / 2 - width / 2)
|
|
287
|
+
val desired = (scrollTargetCenterX - width / 2f).roundToInt()
|
|
281
288
|
.coerceIn(0, max(0, content.measuredWidth - width))
|
|
282
289
|
scrollTo(desired, 0)
|
|
283
290
|
centerSelectionWhenIdle = false
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 (
|
|
135
|
+
if (nestedNativeGestureStarted) {
|
|
136
136
|
NativeGestureUtil.notifyNativeGestureEnded(this, e)
|
|
137
|
-
|
|
137
|
+
nestedNativeGestureStarted = false
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
return super.onTouchEvent(e)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-pager-view",
|
|
3
|
-
"version": "3.0.
|
|
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.
|
|
70
|
+
"@onekeyfe/react-native-native-logger": "3.0.122",
|
|
71
71
|
"react": "*",
|
|
72
72
|
"react-native": "*"
|
|
73
73
|
},
|