@onekeyfe/react-native-pager-view 6.7.0-alpha.359 → 6.7.0-alpha.363
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 +0 -5
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +21 -76
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +7 -72
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +0 -27
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +6 -50
- package/docs/SPEC.md +1 -101
- package/ios/RNCCollapsiblePagerViewComponentView.mm +12 -124
- package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +0 -178
- package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +0 -65
- package/lib/module/CollapsiblePagerView.js +4 -20
- package/lib/module/CollapsiblePagerView.web.js +2 -11
- package/lib/module/CollapsiblePagerViewNativeComponent.ts +0 -13
- package/lib/typescript/src/CollapsiblePagerView.d.ts +1 -6
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +0 -2
- package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +0 -5
- package/package.json +2 -2
- package/src/CollapsiblePagerView.tsx +4 -68
- package/src/CollapsiblePagerView.web.tsx +2 -19
- package/src/CollapsiblePagerViewNativeComponent.ts +0 -13
- package/android/src/androidTest/AndroidManifest.xml +0 -7
- package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +0 -247
|
@@ -580,23 +580,6 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
580
580
|
this.scrollCurrentPageToTop(0, options?.animated ?? true);
|
|
581
581
|
};
|
|
582
582
|
|
|
583
|
-
public scrollHeaderBy = (delta: number) => {
|
|
584
|
-
if (!Number.isFinite(delta)) return;
|
|
585
|
-
const offset = Math.min(
|
|
586
|
-
this.headerHeight,
|
|
587
|
-
Math.max(0, this.sharedHeaderOffset + delta)
|
|
588
|
-
);
|
|
589
|
-
this.scrollCurrentPageToTop(offset, false);
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
public scrollHeaderToOffset = (offset: number) => {
|
|
593
|
-
if (!Number.isFinite(offset)) return;
|
|
594
|
-
this.scrollCurrentPageToTop(
|
|
595
|
-
Math.min(this.headerHeight, Math.max(0, offset)),
|
|
596
|
-
false
|
|
597
|
-
);
|
|
598
|
-
};
|
|
599
|
-
|
|
600
583
|
public scrollToStickyTop = (options?: Readonly<{ animated?: boolean }>) => {
|
|
601
584
|
this.scrollCurrentPageToTop(
|
|
602
585
|
this.headerHeight,
|
|
@@ -691,10 +674,10 @@ export class CollapsiblePagerView extends React.PureComponent<
|
|
|
691
674
|
)
|
|
692
675
|
return;
|
|
693
676
|
this.pageOffsets.set(key, 0);
|
|
694
|
-
this.sharedHeaderOffset =
|
|
677
|
+
this.sharedHeaderOffset = offset;
|
|
695
678
|
this.bodyAlignment = { element, key };
|
|
696
679
|
scrollElementTo(element, {
|
|
697
|
-
top:
|
|
680
|
+
top: offset,
|
|
698
681
|
behavior: animated ? "smooth" : "instant",
|
|
699
682
|
});
|
|
700
683
|
this.syncFallbackHeader();
|
|
@@ -67,10 +67,7 @@ export interface NativeProps extends ViewProps {
|
|
|
67
67
|
retainedPages?: string;
|
|
68
68
|
nativeTabBarItems?: string;
|
|
69
69
|
nativeTabBarHeight?: Double;
|
|
70
|
-
nativeTabBarVariant?: string;
|
|
71
|
-
nativeTabBarTrailingReservedWidth?: WithDefault<Double, 0>;
|
|
72
70
|
nativeTabBarContentPaddingHorizontal?: Double;
|
|
73
|
-
nativeTabBarContentPaddingVertical?: Double;
|
|
74
71
|
nativeTabBarItemSpacing?: Double;
|
|
75
72
|
nativeTabBarFontSize?: Double;
|
|
76
73
|
nativeTabBarFontFamily?: string;
|
|
@@ -94,14 +91,6 @@ export interface NativeProps extends ViewProps {
|
|
|
94
91
|
type CollapsiblePagerViewNativeType = HostComponent<NativeProps>;
|
|
95
92
|
|
|
96
93
|
export interface NativeCommands {
|
|
97
|
-
scrollHeaderToOffset: (
|
|
98
|
-
viewRef: React.ElementRef<CollapsiblePagerViewNativeType>,
|
|
99
|
-
offset: Double
|
|
100
|
-
) => void;
|
|
101
|
-
scrollHeaderBy: (
|
|
102
|
-
viewRef: React.ElementRef<CollapsiblePagerViewNativeType>,
|
|
103
|
-
delta: Double
|
|
104
|
-
) => void;
|
|
105
94
|
scrollToTop: (
|
|
106
95
|
viewRef: React.ElementRef<CollapsiblePagerViewNativeType>,
|
|
107
96
|
target: Int32,
|
|
@@ -123,8 +112,6 @@ export interface NativeCommands {
|
|
|
123
112
|
|
|
124
113
|
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
125
114
|
supportedCommands: [
|
|
126
|
-
"scrollHeaderToOffset",
|
|
127
|
-
"scrollHeaderBy",
|
|
128
115
|
"scrollToTop",
|
|
129
116
|
"setPage",
|
|
130
117
|
"setPageWithoutAnimation",
|
package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
package com.reactnativepagerview
|
|
2
|
-
|
|
3
|
-
import android.app.Activity
|
|
4
|
-
import android.content.Intent
|
|
5
|
-
import android.content.pm.ApplicationInfo
|
|
6
|
-
import android.graphics.Bitmap
|
|
7
|
-
import android.graphics.Canvas
|
|
8
|
-
import android.graphics.Color
|
|
9
|
-
import android.test.InstrumentationTestCase
|
|
10
|
-
import android.view.MotionEvent
|
|
11
|
-
import android.view.View
|
|
12
|
-
import android.view.ViewGroup
|
|
13
|
-
import android.widget.HorizontalScrollView
|
|
14
|
-
import android.widget.TextView
|
|
15
|
-
import com.facebook.react.uimanager.PointerEvents
|
|
16
|
-
import com.facebook.react.views.view.ReactViewGroup
|
|
17
|
-
import java.util.concurrent.atomic.AtomicInteger
|
|
18
|
-
import kotlin.math.roundToInt
|
|
19
|
-
|
|
20
|
-
class CollapsiblePagerHitTestActivity : Activity()
|
|
21
|
-
|
|
22
|
-
class CollapsiblePagerTabReservationTest : InstrumentationTestCase() {
|
|
23
|
-
fun testSegmentedNativeTabsTrackFractionalProgressAndReset() {
|
|
24
|
-
val context = instrumentation.targetContext
|
|
25
|
-
assertTrue(context.applicationInfo.flags and ApplicationInfo.FLAG_SUPPORTS_RTL != 0)
|
|
26
|
-
val activity = instrumentation.startActivitySync(
|
|
27
|
-
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
28
|
-
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
29
|
-
) as CollapsiblePagerHitTestActivity
|
|
30
|
-
val density = context.resources.displayMetrics.density
|
|
31
|
-
fun dp(value: Int) = (value * density).roundToInt()
|
|
32
|
-
lateinit var tab: CollapsiblePagerNativeTabBarView
|
|
33
|
-
lateinit var row: HorizontalScrollView
|
|
34
|
-
lateinit var content: ViewGroup
|
|
35
|
-
lateinit var track: View
|
|
36
|
-
lateinit var thumb: View
|
|
37
|
-
lateinit var buttons: List<TextView>
|
|
38
|
-
fun layout(width: Int = 320, height: Int = 56) {
|
|
39
|
-
tab.measure(View.MeasureSpec.makeMeasureSpec(dp(width), View.MeasureSpec.EXACTLY),
|
|
40
|
-
View.MeasureSpec.makeMeasureSpec(dp(height), View.MeasureSpec.EXACTLY))
|
|
41
|
-
tab.layout(0, 0, dp(width), dp(height))
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
instrumentation.runOnMainSync {
|
|
45
|
-
tab = CollapsiblePagerNativeTabBarView(context)
|
|
46
|
-
activity.setContentView(tab)
|
|
47
|
-
val presses = mutableListOf<String>()
|
|
48
|
-
tab.onItemPress = { _, key -> presses.add(key) }
|
|
49
|
-
tab.updateItemsJSON("""[{"key":"recent","title":"Recents"},""" +
|
|
50
|
-
"""{"key":"account","title":"Accounts"},""" +
|
|
51
|
-
"""{"key":"book","title":"Address Book"}]""")
|
|
52
|
-
tab.updateStyle(56.0, "segmented", 20.0, 12.0, 0.0, 14.0, null, 2.0, 0.0)
|
|
53
|
-
tab.updateColors(Color.LTGRAY, Color.BLACK, Color.GRAY, Color.WHITE)
|
|
54
|
-
layout()
|
|
55
|
-
row = tab.getChildAt(0) as HorizontalScrollView
|
|
56
|
-
content = row.getChildAt(0) as ViewGroup
|
|
57
|
-
track = content.getChildAt(0)
|
|
58
|
-
thumb = content.getChildAt(1)
|
|
59
|
-
buttons = (0 until content.childCount).map(content::getChildAt).filterIsInstance<TextView>()
|
|
60
|
-
assertEquals(3, buttons.size)
|
|
61
|
-
assertEquals(dp(20), track.left)
|
|
62
|
-
assertTrue(kotlin.math.abs(dp(32) - track.height) <= 1)
|
|
63
|
-
assertEquals(0, row.scrollX)
|
|
64
|
-
assertTrue(kotlin.math.abs(buttons[0].width - buttons[1].width) <= 1)
|
|
65
|
-
tab.setProgress(0f)
|
|
66
|
-
val firstX = thumb.left
|
|
67
|
-
tab.setProgress(1f)
|
|
68
|
-
val secondX = thumb.left
|
|
69
|
-
tab.setProgress(0.25f)
|
|
70
|
-
assertTrue(kotlin.math.abs(thumb.left - (firstX + (secondX - firstX) * 0.25f)) <= 1)
|
|
71
|
-
tab.setProgress(0.5f)
|
|
72
|
-
assertTrue(kotlin.math.abs(thumb.left - (firstX + secondX) / 2f) <= 1)
|
|
73
|
-
tab.setProgress(0f)
|
|
74
|
-
assertEquals(firstX, thumb.left)
|
|
75
|
-
buttons[1].performClick()
|
|
76
|
-
assertEquals(listOf("account"), presses)
|
|
77
|
-
|
|
78
|
-
tab.layoutDirection = View.LAYOUT_DIRECTION_RTL
|
|
79
|
-
}
|
|
80
|
-
instrumentation.waitForIdleSync()
|
|
81
|
-
instrumentation.runOnMainSync {
|
|
82
|
-
layout()
|
|
83
|
-
assertEquals(View.LAYOUT_DIRECTION_RTL, row.layoutDirection)
|
|
84
|
-
val rtlFirst = buttons[0].layoutParams as android.widget.FrameLayout.LayoutParams
|
|
85
|
-
val rtlSecond = buttons[1].layoutParams as android.widget.FrameLayout.LayoutParams
|
|
86
|
-
assertTrue(rtlFirst.leftMargin > rtlSecond.leftMargin)
|
|
87
|
-
val rtlGeometry = "rowDir=${row.layoutDirection} contentDir=${content.layoutDirection} " +
|
|
88
|
-
buttons.mapIndexed { index, button ->
|
|
89
|
-
val params = button.layoutParams as android.widget.FrameLayout.LayoutParams
|
|
90
|
-
"$index:${button.left}-${button.right} margin=${params.leftMargin}/${params.rightMargin} gravity=${params.gravity}"
|
|
91
|
-
}.joinToString(" ")
|
|
92
|
-
assertTrue(rtlGeometry, buttons[0].left >= buttons[1].right)
|
|
93
|
-
assertEquals(dp(20), track.left)
|
|
94
|
-
tab.setProgress(0f)
|
|
95
|
-
val rtlFirstX = thumb.left
|
|
96
|
-
tab.setProgress(1f)
|
|
97
|
-
val rtlSecondX = thumb.left
|
|
98
|
-
assertTrue(rtlFirstX > rtlSecondX)
|
|
99
|
-
tab.setProgress(0.5f)
|
|
100
|
-
assertTrue(kotlin.math.abs(thumb.left - (rtlFirstX + rtlSecondX) / 2f) <= 1)
|
|
101
|
-
tab.layoutDirection = View.LAYOUT_DIRECTION_LTR
|
|
102
|
-
}
|
|
103
|
-
instrumentation.waitForIdleSync()
|
|
104
|
-
instrumentation.runOnMainSync {
|
|
105
|
-
layout()
|
|
106
|
-
assertTrue(buttons[0].right <= buttons[1].left)
|
|
107
|
-
tab.updateItemsJSON("""[{"key":"recent","title":"Recents (8)"},""" +
|
|
108
|
-
"""{"key":"account","title":"Accounts"}]""")
|
|
109
|
-
layout()
|
|
110
|
-
val twoButtons = (0 until content.childCount).map(content::getChildAt).filterIsInstance<TextView>()
|
|
111
|
-
assertEquals(2, twoButtons.size)
|
|
112
|
-
assertTrue(kotlin.math.abs(twoButtons[0].width - track.width / 2) <= 1)
|
|
113
|
-
layout(width = 30)
|
|
114
|
-
assertEquals(dp(15), track.left)
|
|
115
|
-
assertEquals(0, track.width)
|
|
116
|
-
tab.updateStyle(56.0, "segmented", 20.0, 40.0, 0.0, 14.0, null, 2.0, 0.0)
|
|
117
|
-
layout(width = 30)
|
|
118
|
-
assertTrue(kotlin.math.abs(dp(28) - track.top) <= 1)
|
|
119
|
-
assertEquals(0, track.height)
|
|
120
|
-
assertEquals(View.GONE, thumb.visibility)
|
|
121
|
-
tab.updateItemsJSON("[]")
|
|
122
|
-
assertEquals(View.GONE, tab.visibility)
|
|
123
|
-
tab.updateItemsJSON("""[{"key":"recent","title":"Recents"}]""")
|
|
124
|
-
tab.updateStyle(44.0, "underline", 20.0, 0.0, 8.0, 16.0, null, 2.0, 0.0)
|
|
125
|
-
layout(height = 44)
|
|
126
|
-
assertEquals(View.GONE, track.visibility)
|
|
127
|
-
assertEquals(dp(2), thumb.height)
|
|
128
|
-
}
|
|
129
|
-
} finally {
|
|
130
|
-
instrumentation.runOnMainSync { activity.finish() }
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
fun testTabViewportToolbarHitAndResetInBothDirections() {
|
|
135
|
-
val context = instrumentation.targetContext
|
|
136
|
-
assertTrue(context.applicationInfo.flags and ApplicationInfo.FLAG_SUPPORTS_RTL != 0)
|
|
137
|
-
val activity = instrumentation.startActivitySync(
|
|
138
|
-
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
139
|
-
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
140
|
-
) as CollapsiblePagerHitTestActivity
|
|
141
|
-
val toolbarPresses = AtomicInteger()
|
|
142
|
-
val tabPresses = AtomicInteger()
|
|
143
|
-
try {
|
|
144
|
-
instrumentation.runOnMainSync {
|
|
145
|
-
val density = context.resources.displayMetrics.density
|
|
146
|
-
fun dp(value: Int) = (value * density).roundToInt()
|
|
147
|
-
val width = dp(320)
|
|
148
|
-
val height = dp(500)
|
|
149
|
-
val reserved = dp(64)
|
|
150
|
-
val tabHeight = dp(44)
|
|
151
|
-
val host = CollapsiblePagerHost(context)
|
|
152
|
-
activity.setContentView(host)
|
|
153
|
-
assertTrue(host.isAttachedToWindow)
|
|
154
|
-
val sticky = ReactViewGroup(context).apply { pointerEvents = PointerEvents.BOX_NONE }
|
|
155
|
-
val fade = View(context).apply { setBackgroundColor(Color.RED) }
|
|
156
|
-
val toolbar = View(context).apply {
|
|
157
|
-
setBackgroundColor(Color.BLUE)
|
|
158
|
-
isClickable = true
|
|
159
|
-
}
|
|
160
|
-
sticky.addView(fade)
|
|
161
|
-
sticky.addView(toolbar)
|
|
162
|
-
host.addReactChild(View(context), 0)
|
|
163
|
-
host.addReactChild(sticky, 1)
|
|
164
|
-
host.headerHeightPx = 0
|
|
165
|
-
host.stickyHeaderHeightPx = tabHeight
|
|
166
|
-
host.nativeTabBarBackgroundColor = Color.GREEN
|
|
167
|
-
host.applyNativeHeaderStyle()
|
|
168
|
-
host.updateNativeTabBarItems(
|
|
169
|
-
"""[{"key":"a","title":"Overview"},{"key":"b","title":"Ethereum"},""" +
|
|
170
|
-
"""{"key":"c","title":"BNB Chain"},{"key":"d","title":"Polygon"}]""",
|
|
171
|
-
)
|
|
172
|
-
val tab = (0 until host.childCount).map(host::getChildAt)
|
|
173
|
-
.first { it.javaClass.simpleName == "CollapsiblePagerNativeTabBarView" } as ViewGroup
|
|
174
|
-
val row = tab.getChildAt(0) as HorizontalScrollView
|
|
175
|
-
toolbar.setOnClickListener { toolbarPresses.incrementAndGet() }
|
|
176
|
-
host.onNativeTabPress = { _, _ -> tabPresses.incrementAndGet() }
|
|
177
|
-
|
|
178
|
-
fun layout() {
|
|
179
|
-
host.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
180
|
-
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
|
|
181
|
-
host.layout(0, 0, width, height)
|
|
182
|
-
}
|
|
183
|
-
fun tap(x: Int) {
|
|
184
|
-
val time = android.os.SystemClock.uptimeMillis()
|
|
185
|
-
val down = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN,
|
|
186
|
-
x.toFloat(), (tabHeight / 2).toFloat(), 0)
|
|
187
|
-
val up = MotionEvent.obtain(time, time + 20, MotionEvent.ACTION_UP,
|
|
188
|
-
x.toFloat(), (tabHeight / 2).toFloat(), 0)
|
|
189
|
-
host.dispatchTouchEvent(down)
|
|
190
|
-
host.dispatchTouchEvent(up)
|
|
191
|
-
down.recycle()
|
|
192
|
-
up.recycle()
|
|
193
|
-
}
|
|
194
|
-
fun colorAt(x: Int): Int {
|
|
195
|
-
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
196
|
-
host.draw(Canvas(bitmap))
|
|
197
|
-
val color = bitmap.getPixel(x, tabHeight / 2)
|
|
198
|
-
bitmap.recycle()
|
|
199
|
-
return color
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
host.nativeTabBarTrailingReservedWidth = 64.0
|
|
203
|
-
layout()
|
|
204
|
-
fade.layout(width - reserved - dp(20), 0, width - reserved, tabHeight)
|
|
205
|
-
toolbar.layout(width - reserved, 0, width, tabHeight)
|
|
206
|
-
assertEquals(width - reserved, tab.width)
|
|
207
|
-
assertEquals(0, tab.left)
|
|
208
|
-
assertEquals(width, sticky.width)
|
|
209
|
-
assertEquals(Color.RED, colorAt(width - reserved - dp(10)))
|
|
210
|
-
tap(width - dp(10))
|
|
211
|
-
tap(dp(28))
|
|
212
|
-
host.updateNativeTabProgress(3, 0f)
|
|
213
|
-
val content = row.getChildAt(0) as ViewGroup
|
|
214
|
-
val lastTab = (0 until content.childCount).map(content::getChildAt)
|
|
215
|
-
.filterIsInstance<TextView>().last()
|
|
216
|
-
assertTrue(lastTab.left >= row.scrollX - dp(1))
|
|
217
|
-
assertTrue(lastTab.right <= row.scrollX + row.width + dp(1))
|
|
218
|
-
|
|
219
|
-
host.setPagerLayoutDirection(View.LAYOUT_DIRECTION_RTL)
|
|
220
|
-
host.nativeTabBarTrailingReservedWidth = 64.0
|
|
221
|
-
layout()
|
|
222
|
-
assertEquals(View.LAYOUT_DIRECTION_RTL, tab.layoutDirection)
|
|
223
|
-
toolbar.layout(0, 0, reserved, tabHeight)
|
|
224
|
-
fade.layout(reserved, 0, reserved + dp(20), tabHeight)
|
|
225
|
-
assertEquals(reserved, tab.left)
|
|
226
|
-
assertEquals(width, tab.right)
|
|
227
|
-
assertEquals(Color.RED, colorAt(reserved + dp(10)))
|
|
228
|
-
tap(dp(10))
|
|
229
|
-
|
|
230
|
-
host.nativeTabBarTrailingReservedWidth = 500.0
|
|
231
|
-
layout()
|
|
232
|
-
assertEquals(0, tab.width)
|
|
233
|
-
host.nativeTabBarTrailingReservedWidth = 0.0
|
|
234
|
-
layout()
|
|
235
|
-
assertEquals(0, tab.left)
|
|
236
|
-
assertEquals(width, tab.width)
|
|
237
|
-
assertTrue(host.indexOfChild(sticky) < host.indexOfChild(tab))
|
|
238
|
-
}
|
|
239
|
-
instrumentation.waitForIdleSync()
|
|
240
|
-
assertEquals(2, toolbarPresses.get())
|
|
241
|
-
assertEquals(1, tabPresses.get())
|
|
242
|
-
} finally {
|
|
243
|
-
instrumentation.runOnMainSync { activity.finish() }
|
|
244
|
-
instrumentation.waitForIdleSync()
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|