@onekeyfe/react-native-pager-view 6.7.0-4 → 6.7.0-41
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 +21 -0
- package/android/build.gradle +1 -0
- package/android/src/androidTest/AndroidManifest.xml +7 -0
- package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt +476 -0
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerHost.kt +233 -43
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerNativeHeaders.kt +596 -27
- package/android/src/main/java/com/reactnativepagerview/CollapsiblePagerViewManager.kt +40 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerScrollAwayInsets.kt +19 -0
- package/android/src/main/java/com/reactnativepagerview/NativeScrollerView.kt +50 -6
- package/android/src/main/java/com/reactnativepagerview/NestedScrollableHost.kt +8 -2
- package/android/src/main/java/com/reactnativepagerview/event/NativeHeaderPressEvent.kt +8 -0
- package/android/src/test/java/com/reactnativepagerview/NativeScrollerScrollAwayInsetsTest.kt +40 -0
- package/docs/SPEC.md +700 -10
- package/ios/RNCCollapsiblePagerViewComponentView.mm +2221 -94
- package/ios/RNCNativeScrollerComponentView.h +2 -0
- package/ios/RNCNativeScrollerComponentView.mm +42 -0
- package/ios/tests/RNCCollapsiblePagerFirstFrameTests.mm +562 -1
- package/ios/tests/RNCCollapsiblePagerHitTestTests.mm +1116 -0
- package/ios/tests/RNCCollapsiblePagerPressCancellationTests.mm +74 -9
- package/ios/tests/RNCCollapsiblePagerRefreshControlTests.mm +50 -0
- package/lib/module/CollapsiblePagerView.js +75 -11
- package/lib/module/CollapsiblePagerView.web.js +653 -8
- package/lib/module/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/lib/module/NativeScroller.web.js +3 -0
- package/lib/module/NativeScrollerNativeComponent.ts +42 -46
- package/lib/module/PagerViewNativeComponent.ts +20 -25
- package/lib/module/WebCollapsiblePagerPage.js +7 -2
- package/lib/module/index.native.js +9 -0
- package/lib/typescript/src/CollapsiblePagerView.d.ts +62 -4
- package/lib/typescript/src/CollapsiblePagerView.web.d.ts +56 -2
- package/lib/typescript/src/CollapsiblePagerViewNativeComponent.d.ts +54 -38
- package/lib/typescript/src/NativeScroller.d.ts +5 -3
- package/lib/typescript/src/NativeScroller.web.d.ts +1 -1
- package/lib/typescript/src/NativeScrollerNativeComponent.d.ts +47 -48
- package/lib/typescript/src/PagerView.d.ts +1 -1
- package/lib/typescript/src/PagerView.web.d.ts +1 -1
- package/lib/typescript/src/PagerViewNativeComponent.d.ts +20 -21
- package/lib/typescript/src/WebCollapsiblePagerPage.d.ts +1 -1
- package/lib/typescript/src/index.native.d.ts +13 -0
- package/lib/typescript/src/usePagerView.d.ts +2 -2
- package/lib/typescript/src/utils.d.ts +2 -2
- package/package.json +22 -7
- package/react-native-pager-view.podspec +1 -0
- package/src/CollapsiblePagerView.tsx +208 -12
- package/src/CollapsiblePagerView.web.tsx +587 -7
- package/src/CollapsiblePagerViewNativeComponent.ts +57 -42
- package/src/NativeScroller.tsx +14 -4
- package/src/NativeScroller.web.tsx +15 -1
- package/src/NativeScrollerNativeComponent.ts +42 -46
- package/src/PagerViewNativeComponent.ts +20 -25
- package/src/WebCollapsiblePagerPage.tsx +7 -2
- package/src/index.native.tsx +30 -0
package/README.md
CHANGED
|
@@ -66,6 +66,11 @@ replacing its delegate. Android coordinates nested scroll with the active
|
|
|
66
66
|
Web scroll child can opt in by exposing a DOM element with
|
|
67
67
|
`data-collapsible-pager-scroll`. CSS scroll timelines drive header/sticky
|
|
68
68
|
movement, so React is not updated on each vertical scroll frame.
|
|
69
|
+
`pagerRef.current?.scrollHeaderBy(delta)` immediately moves the active page's
|
|
70
|
+
collapsible header by a finite logical distance, clamped to its measured range.
|
|
71
|
+
`scrollHeaderToOffset(offset)` targets an absolute collapse position, so a
|
|
72
|
+
keyboard's own scroll adjustment cannot add a second relative movement.
|
|
73
|
+
It is useful for revealing a focused field above a keyboard.
|
|
69
74
|
|
|
70
75
|
On Web, `WebCollapsiblePagerView` is an explicit root export of the existing Web
|
|
71
76
|
pager. It measures Header and sticky content when their heights are omitted.
|
|
@@ -82,6 +87,18 @@ non-adjacent presses jump directly to the target without passing intermediate
|
|
|
82
87
|
pages. Set `nativeTabPressAnimationEnabled={true}` to always animate, or `false`
|
|
83
88
|
to always jump. Swipe gestures and imperative page commands are unchanged.
|
|
84
89
|
|
|
90
|
+
The `text` variant supports `controlled`, stable `selectedKey` and one per-key
|
|
91
|
+
`toolbar` map. Controlled presses report intent; the caller keeps page commands,
|
|
92
|
+
menus and routing. Label colors follow actual page movement while selected font
|
|
93
|
+
weight follows business selection. Toolbar artwork, label, action key and selected
|
|
94
|
+
background transfer together only when the final physical page and selection
|
|
95
|
+
agree. Motion keeps the old artwork with hit/AX disabled; two present icons replace
|
|
96
|
+
in place, and only presence changes fade for about 100 ms. Omitting `toolbar`
|
|
97
|
+
reserves zero width; `{}` reserves 44 logical units, and nonempty maps use their
|
|
98
|
+
largest `contentWidth + trailingInset`. Missing/failed content keeps that slot
|
|
99
|
+
without an active control. See [the contract](docs/SPEC.md#text-tabs-controlled-selection-and-per-tab-toolbar)
|
|
100
|
+
for ownership, cancellation, progress, fallback and current acceptance limits.
|
|
101
|
+
|
|
85
102
|
> **Behavior change:** earlier versions animated every native tab press when
|
|
86
103
|
> `nativeTabPressAnimationEnabled` was omitted. Pass
|
|
87
104
|
> `nativeTabPressAnimationEnabled={true}` to keep that behavior.
|
|
@@ -137,3 +154,7 @@ position emit a momentum begin/end pair; a no-op emits no new pair. A new comman
|
|
|
137
154
|
new touch, content-root replacement or detach ends the previous active sequence.
|
|
138
155
|
The focused JS tests verify wrapper routing, not native scrolling,
|
|
139
156
|
Yoga rendering, keyboard interaction or refresh placement on a device.
|
|
157
|
+
|
|
158
|
+
The codegen type boundary uses React Native's public `CodegenTypes` namespace.
|
|
159
|
+
RN 0.86.2/0.88.0 declaration and parser checks preserve emitted JS, native schemas
|
|
160
|
+
and the existing NativeScroller method set; no private type import patch is needed.
|
package/android/build.gradle
CHANGED
|
@@ -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()) {
|
package/android/src/androidTest/java/com/reactnativepagerview/CollapsiblePagerTabReservationTest.kt
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
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.graphics.Typeface
|
|
10
|
+
import android.graphics.drawable.ColorDrawable
|
|
11
|
+
import android.graphics.drawable.GradientDrawable
|
|
12
|
+
import android.test.InstrumentationTestCase
|
|
13
|
+
import android.view.MotionEvent
|
|
14
|
+
import android.view.View
|
|
15
|
+
import android.view.ViewGroup
|
|
16
|
+
import android.widget.HorizontalScrollView
|
|
17
|
+
import android.widget.TextView
|
|
18
|
+
import androidx.recyclerview.widget.RecyclerView
|
|
19
|
+
import androidx.viewpager2.widget.ViewPager2
|
|
20
|
+
import com.facebook.react.uimanager.PointerEvents
|
|
21
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
22
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
23
|
+
import kotlin.math.roundToInt
|
|
24
|
+
|
|
25
|
+
class CollapsiblePagerHitTestActivity : Activity()
|
|
26
|
+
|
|
27
|
+
class CollapsiblePagerTabReservationTest : InstrumentationTestCase() {
|
|
28
|
+
fun testSegmentedNativeTabsTrackFractionalProgressAndReset() {
|
|
29
|
+
val context = instrumentation.targetContext
|
|
30
|
+
assertTrue(context.applicationInfo.flags and ApplicationInfo.FLAG_SUPPORTS_RTL != 0)
|
|
31
|
+
val activity = instrumentation.startActivitySync(
|
|
32
|
+
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
33
|
+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
34
|
+
) as CollapsiblePagerHitTestActivity
|
|
35
|
+
val density = context.resources.displayMetrics.density
|
|
36
|
+
fun dp(value: Int) = (value * density).roundToInt()
|
|
37
|
+
lateinit var tab: CollapsiblePagerNativeTabBarView
|
|
38
|
+
lateinit var row: HorizontalScrollView
|
|
39
|
+
lateinit var content: ViewGroup
|
|
40
|
+
lateinit var track: View
|
|
41
|
+
lateinit var thumb: View
|
|
42
|
+
lateinit var buttons: List<TextView>
|
|
43
|
+
fun layout(width: Int = 320, height: Int = 56) {
|
|
44
|
+
tab.measure(View.MeasureSpec.makeMeasureSpec(dp(width), View.MeasureSpec.EXACTLY),
|
|
45
|
+
View.MeasureSpec.makeMeasureSpec(dp(height), View.MeasureSpec.EXACTLY))
|
|
46
|
+
tab.layout(0, 0, dp(width), dp(height))
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
instrumentation.runOnMainSync {
|
|
50
|
+
tab = CollapsiblePagerNativeTabBarView(context)
|
|
51
|
+
activity.setContentView(tab)
|
|
52
|
+
val presses = mutableListOf<String>()
|
|
53
|
+
tab.onItemPress = { _, key -> presses.add(key) }
|
|
54
|
+
tab.updateItemsJSON("""[{"key":"recent","title":"Recents"},""" +
|
|
55
|
+
"""{"key":"account","title":"Accounts"},""" +
|
|
56
|
+
"""{"key":"book","title":"Address Book"}]""")
|
|
57
|
+
tab.updateStyle(56.0, "segmented", 20.0, 12.0, 0.0, 14.0, null, 2.0, 0.0)
|
|
58
|
+
tab.updateColors(Color.LTGRAY, Color.BLACK, Color.GRAY, Color.WHITE)
|
|
59
|
+
layout()
|
|
60
|
+
row = tab.getChildAt(0) as HorizontalScrollView
|
|
61
|
+
content = row.getChildAt(0) as ViewGroup
|
|
62
|
+
track = content.getChildAt(0)
|
|
63
|
+
thumb = content.getChildAt(1)
|
|
64
|
+
buttons = (0 until content.childCount).map(content::getChildAt).filterIsInstance<TextView>()
|
|
65
|
+
assertEquals(3, buttons.size)
|
|
66
|
+
assertEquals(dp(20), track.left)
|
|
67
|
+
assertTrue(kotlin.math.abs(dp(32) - track.height) <= 1)
|
|
68
|
+
assertEquals(0, row.scrollX)
|
|
69
|
+
assertTrue(kotlin.math.abs(buttons[0].width - buttons[1].width) <= 1)
|
|
70
|
+
tab.setProgress(0f)
|
|
71
|
+
val firstX = thumb.left
|
|
72
|
+
tab.setProgress(1f)
|
|
73
|
+
val secondX = thumb.left
|
|
74
|
+
tab.setProgress(0.25f)
|
|
75
|
+
assertTrue(kotlin.math.abs(thumb.left - (firstX + (secondX - firstX) * 0.25f)) <= 1)
|
|
76
|
+
tab.setProgress(0.5f)
|
|
77
|
+
assertTrue(kotlin.math.abs(thumb.left - (firstX + secondX) / 2f) <= 1)
|
|
78
|
+
tab.setProgress(0f)
|
|
79
|
+
assertEquals(firstX, thumb.left)
|
|
80
|
+
buttons[1].performClick()
|
|
81
|
+
assertEquals(listOf("account"), presses)
|
|
82
|
+
|
|
83
|
+
tab.layoutDirection = View.LAYOUT_DIRECTION_RTL
|
|
84
|
+
}
|
|
85
|
+
instrumentation.waitForIdleSync()
|
|
86
|
+
instrumentation.runOnMainSync {
|
|
87
|
+
layout()
|
|
88
|
+
assertEquals(View.LAYOUT_DIRECTION_RTL, row.layoutDirection)
|
|
89
|
+
val rtlFirst = buttons[0].layoutParams as android.widget.FrameLayout.LayoutParams
|
|
90
|
+
val rtlSecond = buttons[1].layoutParams as android.widget.FrameLayout.LayoutParams
|
|
91
|
+
assertTrue(rtlFirst.leftMargin > rtlSecond.leftMargin)
|
|
92
|
+
val rtlGeometry = "rowDir=${row.layoutDirection} contentDir=${content.layoutDirection} " +
|
|
93
|
+
buttons.mapIndexed { index, button ->
|
|
94
|
+
val params = button.layoutParams as android.widget.FrameLayout.LayoutParams
|
|
95
|
+
"$index:${button.left}-${button.right} margin=${params.leftMargin}/${params.rightMargin} gravity=${params.gravity}"
|
|
96
|
+
}.joinToString(" ")
|
|
97
|
+
assertTrue(rtlGeometry, buttons[0].left >= buttons[1].right)
|
|
98
|
+
assertEquals(dp(20), track.left)
|
|
99
|
+
tab.setProgress(0f)
|
|
100
|
+
val rtlFirstX = thumb.left
|
|
101
|
+
tab.setProgress(1f)
|
|
102
|
+
val rtlSecondX = thumb.left
|
|
103
|
+
assertTrue(rtlFirstX > rtlSecondX)
|
|
104
|
+
tab.setProgress(0.5f)
|
|
105
|
+
assertTrue(kotlin.math.abs(thumb.left - (rtlFirstX + rtlSecondX) / 2f) <= 1)
|
|
106
|
+
tab.layoutDirection = View.LAYOUT_DIRECTION_LTR
|
|
107
|
+
}
|
|
108
|
+
instrumentation.waitForIdleSync()
|
|
109
|
+
instrumentation.runOnMainSync {
|
|
110
|
+
layout()
|
|
111
|
+
assertTrue(buttons[0].right <= buttons[1].left)
|
|
112
|
+
tab.updateItemsJSON("""[{"key":"recent","title":"Recents (8)"},""" +
|
|
113
|
+
"""{"key":"account","title":"Accounts"}]""")
|
|
114
|
+
layout()
|
|
115
|
+
val twoButtons = (0 until content.childCount).map(content::getChildAt).filterIsInstance<TextView>()
|
|
116
|
+
assertEquals(2, twoButtons.size)
|
|
117
|
+
assertTrue(kotlin.math.abs(twoButtons[0].width - track.width / 2) <= 1)
|
|
118
|
+
layout(width = 30)
|
|
119
|
+
assertEquals(dp(15), track.left)
|
|
120
|
+
assertEquals(0, track.width)
|
|
121
|
+
tab.updateStyle(56.0, "segmented", 20.0, 40.0, 0.0, 14.0, null, 2.0, 0.0)
|
|
122
|
+
layout(width = 30)
|
|
123
|
+
assertTrue(kotlin.math.abs(dp(28) - track.top) <= 1)
|
|
124
|
+
assertEquals(0, track.height)
|
|
125
|
+
assertEquals(View.GONE, thumb.visibility)
|
|
126
|
+
tab.updateItemsJSON("[]")
|
|
127
|
+
assertEquals(View.GONE, tab.visibility)
|
|
128
|
+
tab.updateItemsJSON("""[{"key":"recent","title":"Recents"}]""")
|
|
129
|
+
tab.updateStyle(44.0, "underline", 20.0, 0.0, 8.0, 16.0, null, 2.0, 0.0)
|
|
130
|
+
layout(height = 44)
|
|
131
|
+
assertEquals(View.GONE, track.visibility)
|
|
132
|
+
assertEquals(dp(2), thumb.height)
|
|
133
|
+
}
|
|
134
|
+
} finally {
|
|
135
|
+
instrumentation.runOnMainSync { activity.finish() }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
fun testTabViewportToolbarHitAndResetInBothDirections() {
|
|
140
|
+
val context = instrumentation.targetContext
|
|
141
|
+
assertTrue(context.applicationInfo.flags and ApplicationInfo.FLAG_SUPPORTS_RTL != 0)
|
|
142
|
+
val activity = instrumentation.startActivitySync(
|
|
143
|
+
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
144
|
+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
145
|
+
) as CollapsiblePagerHitTestActivity
|
|
146
|
+
val toolbarPresses = AtomicInteger()
|
|
147
|
+
val tabPresses = AtomicInteger()
|
|
148
|
+
try {
|
|
149
|
+
instrumentation.runOnMainSync {
|
|
150
|
+
val density = context.resources.displayMetrics.density
|
|
151
|
+
fun dp(value: Int) = (value * density).roundToInt()
|
|
152
|
+
val width = dp(320)
|
|
153
|
+
val height = dp(500)
|
|
154
|
+
val reserved = dp(64)
|
|
155
|
+
val tabHeight = dp(44)
|
|
156
|
+
val host = CollapsiblePagerHost(context)
|
|
157
|
+
activity.setContentView(host)
|
|
158
|
+
assertTrue(host.isAttachedToWindow)
|
|
159
|
+
val sticky = ReactViewGroup(context).apply { pointerEvents = PointerEvents.BOX_NONE }
|
|
160
|
+
val fade = View(context).apply { setBackgroundColor(Color.RED) }
|
|
161
|
+
val toolbar = View(context).apply {
|
|
162
|
+
setBackgroundColor(Color.BLUE)
|
|
163
|
+
isClickable = true
|
|
164
|
+
}
|
|
165
|
+
sticky.addView(fade)
|
|
166
|
+
sticky.addView(toolbar)
|
|
167
|
+
host.addReactChild(View(context), 0)
|
|
168
|
+
host.addReactChild(sticky, 1)
|
|
169
|
+
host.headerHeightPx = 0
|
|
170
|
+
host.stickyHeaderHeightPx = tabHeight
|
|
171
|
+
host.nativeTabBarBackgroundColor = Color.GREEN
|
|
172
|
+
host.applyNativeHeaderStyle()
|
|
173
|
+
host.updateNativeTabBarItems(
|
|
174
|
+
"""[{"key":"a","title":"Overview"},{"key":"b","title":"Ethereum"},""" +
|
|
175
|
+
"""{"key":"c","title":"BNB Chain"},{"key":"d","title":"Polygon"}]""",
|
|
176
|
+
)
|
|
177
|
+
val tab = (0 until host.childCount).map(host::getChildAt)
|
|
178
|
+
.first { it.javaClass.simpleName == "CollapsiblePagerNativeTabBarView" } as ViewGroup
|
|
179
|
+
val row = tab.getChildAt(0) as HorizontalScrollView
|
|
180
|
+
toolbar.setOnClickListener { toolbarPresses.incrementAndGet() }
|
|
181
|
+
host.onNativeTabPress = { _, _ -> tabPresses.incrementAndGet() }
|
|
182
|
+
|
|
183
|
+
fun layout() {
|
|
184
|
+
host.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
185
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
|
|
186
|
+
host.layout(0, 0, width, height)
|
|
187
|
+
}
|
|
188
|
+
fun tap(x: Int) {
|
|
189
|
+
val time = android.os.SystemClock.uptimeMillis()
|
|
190
|
+
val down = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN,
|
|
191
|
+
x.toFloat(), (tabHeight / 2).toFloat(), 0)
|
|
192
|
+
val up = MotionEvent.obtain(time, time + 20, MotionEvent.ACTION_UP,
|
|
193
|
+
x.toFloat(), (tabHeight / 2).toFloat(), 0)
|
|
194
|
+
host.dispatchTouchEvent(down)
|
|
195
|
+
host.dispatchTouchEvent(up)
|
|
196
|
+
down.recycle()
|
|
197
|
+
up.recycle()
|
|
198
|
+
}
|
|
199
|
+
fun colorAt(x: Int): Int {
|
|
200
|
+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
201
|
+
host.draw(Canvas(bitmap))
|
|
202
|
+
val color = bitmap.getPixel(x, tabHeight / 2)
|
|
203
|
+
bitmap.recycle()
|
|
204
|
+
return color
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
host.nativeTabBarTrailingReservedWidth = 64.0
|
|
208
|
+
layout()
|
|
209
|
+
fade.layout(width - reserved - dp(20), 0, width - reserved, tabHeight)
|
|
210
|
+
toolbar.layout(width - reserved, 0, width, tabHeight)
|
|
211
|
+
assertEquals(width - reserved, tab.width)
|
|
212
|
+
assertEquals(0, tab.left)
|
|
213
|
+
assertEquals(width, sticky.width)
|
|
214
|
+
assertEquals(Color.RED, colorAt(width - reserved - dp(10)))
|
|
215
|
+
tap(width - dp(10))
|
|
216
|
+
tap(dp(28))
|
|
217
|
+
host.updateNativeTabProgress(3, 0f)
|
|
218
|
+
val content = row.getChildAt(0) as ViewGroup
|
|
219
|
+
val lastTab = (0 until content.childCount).map(content::getChildAt)
|
|
220
|
+
.filterIsInstance<TextView>().last()
|
|
221
|
+
assertTrue(lastTab.left >= row.scrollX - dp(1))
|
|
222
|
+
assertTrue(lastTab.right <= row.scrollX + row.width + dp(1))
|
|
223
|
+
|
|
224
|
+
host.setPagerLayoutDirection(View.LAYOUT_DIRECTION_RTL)
|
|
225
|
+
host.nativeTabBarTrailingReservedWidth = 64.0
|
|
226
|
+
layout()
|
|
227
|
+
assertEquals(View.LAYOUT_DIRECTION_RTL, tab.layoutDirection)
|
|
228
|
+
toolbar.layout(0, 0, reserved, tabHeight)
|
|
229
|
+
fade.layout(reserved, 0, reserved + dp(20), tabHeight)
|
|
230
|
+
assertEquals(reserved, tab.left)
|
|
231
|
+
assertEquals(width, tab.right)
|
|
232
|
+
assertEquals(Color.RED, colorAt(reserved + dp(10)))
|
|
233
|
+
tap(dp(10))
|
|
234
|
+
|
|
235
|
+
host.nativeTabBarTrailingReservedWidth = 500.0
|
|
236
|
+
layout()
|
|
237
|
+
assertEquals(0, tab.width)
|
|
238
|
+
host.nativeTabBarTrailingReservedWidth = 0.0
|
|
239
|
+
layout()
|
|
240
|
+
assertEquals(0, tab.left)
|
|
241
|
+
assertEquals(width, tab.width)
|
|
242
|
+
assertTrue(host.indexOfChild(sticky) < host.indexOfChild(tab))
|
|
243
|
+
}
|
|
244
|
+
instrumentation.waitForIdleSync()
|
|
245
|
+
assertEquals(2, toolbarPresses.get())
|
|
246
|
+
assertEquals(1, tabPresses.get())
|
|
247
|
+
} finally {
|
|
248
|
+
instrumentation.runOnMainSync { activity.finish() }
|
|
249
|
+
instrumentation.waitForIdleSync()
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
fun testUnmountWithTransitioningPageHoldersSkipsEmptyRecyclerLayout() {
|
|
254
|
+
val context = instrumentation.targetContext
|
|
255
|
+
val activity = instrumentation.startActivitySync(
|
|
256
|
+
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
257
|
+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
258
|
+
) as CollapsiblePagerHitTestActivity
|
|
259
|
+
try {
|
|
260
|
+
instrumentation.runOnMainSync {
|
|
261
|
+
val density = context.resources.displayMetrics.density
|
|
262
|
+
fun dp(value: Int) = (value * density).roundToInt()
|
|
263
|
+
val width = dp(320)
|
|
264
|
+
val height = dp(500)
|
|
265
|
+
val host = CollapsiblePagerHost(context)
|
|
266
|
+
activity.setContentView(host)
|
|
267
|
+
val header = View(context)
|
|
268
|
+
val sticky = View(context)
|
|
269
|
+
val page0 = View(context)
|
|
270
|
+
val page1 = View(context)
|
|
271
|
+
host.addReactChild(header, 0)
|
|
272
|
+
host.addReactChild(sticky, 1)
|
|
273
|
+
host.addReactChild(page0, 2)
|
|
274
|
+
host.addReactChild(page1, 3)
|
|
275
|
+
host.measure(
|
|
276
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
277
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY),
|
|
278
|
+
)
|
|
279
|
+
host.layout(0, 0, width, height)
|
|
280
|
+
val pager = (0 until host.childCount).map(host::getChildAt).filterIsInstance<ViewPager2>().first()
|
|
281
|
+
val recycler = pager.getChildAt(0) as RecyclerView
|
|
282
|
+
assertNull(recycler.itemAnimator)
|
|
283
|
+
assertTrue(host.attachedPageCount() > 0)
|
|
284
|
+
|
|
285
|
+
val transitioningHolders = (0 until recycler.childCount).map(recycler::getChildAt)
|
|
286
|
+
transitioningHolders.forEach { recycler.startViewTransition(it) }
|
|
287
|
+
|
|
288
|
+
host.removeReactChild(page1)
|
|
289
|
+
host.removeReactChild(page0)
|
|
290
|
+
host.removeReactChild(sticky)
|
|
291
|
+
host.removeReactChild(header)
|
|
292
|
+
|
|
293
|
+
host.viewTreeObserver.dispatchOnPreDraw()
|
|
294
|
+
host.measure(
|
|
295
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
296
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY),
|
|
297
|
+
)
|
|
298
|
+
host.layout(0, 0, width, height)
|
|
299
|
+
assertTrue(host.attachedPageCount() > 0)
|
|
300
|
+
|
|
301
|
+
transitioningHolders.forEach { recycler.endViewTransition(it) }
|
|
302
|
+
}
|
|
303
|
+
instrumentation.waitForIdleSync()
|
|
304
|
+
} finally {
|
|
305
|
+
instrumentation.runOnMainSync { activity.finish() }
|
|
306
|
+
instrumentation.waitForIdleSync()
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
fun testControlledPagerSettlesWhenOnlyParentLayoutRequestRemains() {
|
|
310
|
+
val context = instrumentation.targetContext
|
|
311
|
+
val activity = instrumentation.startActivitySync(
|
|
312
|
+
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
313
|
+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
314
|
+
) as CollapsiblePagerHitTestActivity
|
|
315
|
+
lateinit var host: CollapsiblePagerHost
|
|
316
|
+
lateinit var tab: CollapsiblePagerNativeTabBarView
|
|
317
|
+
val drain = CollapsiblePagerHost::class.java.getDeclaredMethod("layoutPagerIfRequested").apply { isAccessible = true }
|
|
318
|
+
try {
|
|
319
|
+
instrumentation.runOnMainSync {
|
|
320
|
+
val density = context.resources.displayMetrics.density
|
|
321
|
+
val width = (320 * density).roundToInt()
|
|
322
|
+
val height = (500 * density).roundToInt()
|
|
323
|
+
host = CollapsiblePagerHost(context)
|
|
324
|
+
host.pendingInitialPage = 1
|
|
325
|
+
activity.setContentView(host)
|
|
326
|
+
repeat(4) { host.addReactChild(View(context), it) }
|
|
327
|
+
host.applyPendingInitialPage()
|
|
328
|
+
host.nativeTabBarVariant = "text"
|
|
329
|
+
host.applyNativeHeaderStyle()
|
|
330
|
+
host.updateNativeTabBarItems("""[{"key":"a","title":"A"},{"key":"b","title":"B"}]""")
|
|
331
|
+
host.updateNativeTabBarConfig("""{"controlled":true,"selectedKey":"b","pageKeys":["a","b"],"toolbar":{}}""")
|
|
332
|
+
host.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
333
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
|
|
334
|
+
host.layout(0, 0, width, height)
|
|
335
|
+
tab = (0 until host.childCount).map(host::getChildAt)
|
|
336
|
+
.filterIsInstance<CollapsiblePagerNativeTabBarView>().single()
|
|
337
|
+
host.pager.setCurrentItem(1, false)
|
|
338
|
+
val recycler = host.pager.getChildAt(0) as RecyclerView
|
|
339
|
+
host.pager.requestLayout()
|
|
340
|
+
recycler.requestLayout()
|
|
341
|
+
recycler.measure(View.MeasureSpec.makeMeasureSpec(recycler.width, View.MeasureSpec.EXACTLY),
|
|
342
|
+
View.MeasureSpec.makeMeasureSpec(recycler.height, View.MeasureSpec.EXACTLY))
|
|
343
|
+
recycler.layout(recycler.left, recycler.top, recycler.right, recycler.bottom)
|
|
344
|
+
assertFalse(recycler.isLayoutRequested)
|
|
345
|
+
assertTrue(host.pager.isLayoutRequested)
|
|
346
|
+
assertTrue(tab.needsToolbarPagerSettlement(1))
|
|
347
|
+
drain.invoke(host)
|
|
348
|
+
assertFalse(host.pager.isLayoutRequested)
|
|
349
|
+
}
|
|
350
|
+
instrumentation.waitForIdleSync()
|
|
351
|
+
instrumentation.runOnMainSync {
|
|
352
|
+
assertFalse(tab.needsToolbarPagerSettlement(1))
|
|
353
|
+
val posted = CollapsiblePagerHost::class.java.getDeclaredField("toolbarSettlePostedGeneration").apply { isAccessible = true }
|
|
354
|
+
repeat(50) { drain.invoke(host) }
|
|
355
|
+
assertNull(posted.get(host))
|
|
356
|
+
assertFalse(host.pager.isLayoutRequested)
|
|
357
|
+
}
|
|
358
|
+
instrumentation.runOnMainSync {
|
|
359
|
+
val parent = host.parent as ViewGroup
|
|
360
|
+
val index = parent.indexOfChild(host)
|
|
361
|
+
parent.removeView(host)
|
|
362
|
+
parent.addView(host, index)
|
|
363
|
+
assertTrue(host.isAttachedToWindow)
|
|
364
|
+
assertTrue(host.isShown)
|
|
365
|
+
assertTrue(host.width > 0 && host.height > 0)
|
|
366
|
+
assertFalse(host.isLaidOut)
|
|
367
|
+
assertEquals(1, host.pager.currentItem)
|
|
368
|
+
drain.invoke(host)
|
|
369
|
+
assertTrue(host.isLaidOut)
|
|
370
|
+
}
|
|
371
|
+
instrumentation.waitForIdleSync()
|
|
372
|
+
instrumentation.runOnMainSync {
|
|
373
|
+
assertEquals(1, host.pager.currentItem)
|
|
374
|
+
assertFalse(tab.needsToolbarPagerSettlement(1))
|
|
375
|
+
}
|
|
376
|
+
} finally {
|
|
377
|
+
instrumentation.runOnMainSync { activity.finish() }
|
|
378
|
+
instrumentation.waitForIdleSync()
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
fun testTextToolbarBackgroundCoversSlotWithSingleTranslucentLayer() {
|
|
383
|
+
val context = instrumentation.targetContext
|
|
384
|
+
val activity = instrumentation.startActivitySync(
|
|
385
|
+
Intent(context, CollapsiblePagerHitTestActivity::class.java)
|
|
386
|
+
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
|
387
|
+
) as CollapsiblePagerHitTestActivity
|
|
388
|
+
try {
|
|
389
|
+
instrumentation.runOnMainSync {
|
|
390
|
+
val density = context.resources.displayMetrics.density
|
|
391
|
+
fun dp(value: Int) = (value * density).roundToInt()
|
|
392
|
+
val width = dp(320)
|
|
393
|
+
val height = dp(44)
|
|
394
|
+
val tab = CollapsiblePagerNativeTabBarView(context)
|
|
395
|
+
tab.layoutDirection = View.LAYOUT_DIRECTION_LTR
|
|
396
|
+
activity.setContentView(tab)
|
|
397
|
+
tab.updateItemsJSON("""[{"key":"a","title":"A"}]""")
|
|
398
|
+
fun configure(variant: String, background: Int, entry: Boolean) {
|
|
399
|
+
tab.updateStyle(44.0, variant, 20.0, 0.0, 8.0, 18.0, null, 2.0, 0.0)
|
|
400
|
+
val toolbar = if (entry) """{"a":{"iconName":"SliderHorOutline"}}""" else "{}"
|
|
401
|
+
tab.updateConfigJSON("""{"controlled":true,"selectedKey":"a","pageKeys":["a"],"toolbar":$toolbar}""")
|
|
402
|
+
tab.updateToolbarPagerState(0, false)
|
|
403
|
+
tab.updateColors(background, Color.BLACK, Color.GRAY, Color.BLACK)
|
|
404
|
+
tab.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
405
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
|
|
406
|
+
tab.layout(0, 0, width, height)
|
|
407
|
+
}
|
|
408
|
+
for (background in listOf(0xff204060.toInt(), 0x80204060.toInt(), Color.TRANSPARENT)) {
|
|
409
|
+
for (entry in listOf(false, true)) {
|
|
410
|
+
configure("text", background, entry)
|
|
411
|
+
val row = tab.getChildAt(0) as HorizontalScrollView
|
|
412
|
+
assertEquals(width - dp(44), row.width)
|
|
413
|
+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
414
|
+
tab.draw(Canvas(bitmap))
|
|
415
|
+
assertEquals(Color.alpha(background), Color.alpha(bitmap.getPixel(1, height - 1)))
|
|
416
|
+
assertEquals(Color.alpha(background), Color.alpha(bitmap.getPixel(width - 1, height - 1)))
|
|
417
|
+
assertEquals(Color.TRANSPARENT, (row.background as ColorDrawable).color)
|
|
418
|
+
assertEquals(Color.TRANSPARENT, ((row.getChildAt(0) as ViewGroup).background as ColorDrawable).color)
|
|
419
|
+
bitmap.recycle()
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
for (variant in listOf("underline", "text", "segmented", "text")) {
|
|
423
|
+
val background = 0xff204060.toInt()
|
|
424
|
+
configure(variant, background, false)
|
|
425
|
+
val row = tab.getChildAt(0) as HorizontalScrollView
|
|
426
|
+
assertEquals(if (variant == "text") background else Color.TRANSPARENT,
|
|
427
|
+
(tab.background as ColorDrawable).color)
|
|
428
|
+
if (variant == "underline") assertEquals(background, (row.background as ColorDrawable).color)
|
|
429
|
+
if (variant == "segmented") {
|
|
430
|
+
val content = row.getChildAt(0) as ViewGroup
|
|
431
|
+
val track = content.getChildAt(0)
|
|
432
|
+
assertEquals(background, (track.background as GradientDrawable).color?.defaultColor)
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
} finally {
|
|
437
|
+
instrumentation.runOnMainSync { activity.finish() }
|
|
438
|
+
instrumentation.waitForIdleSync()
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
fun testTextActiveTypefaceInheritsNormalFamilyAndKeepsExplicitFace() {
|
|
443
|
+
instrumentation.runOnMainSync {
|
|
444
|
+
val tab = CollapsiblePagerNativeTabBarView(instrumentation.targetContext)
|
|
445
|
+
tab.updateItemsJSON("""[{"key":"a","title":"Wide glyphs pygy"}]""")
|
|
446
|
+
tab.updateStyle(44.0, "text", 0.0, 0.0, 0.0, 18.0, "serif", 0.0, 0.0)
|
|
447
|
+
val row = tab.getChildAt(0) as HorizontalScrollView
|
|
448
|
+
val content = row.getChildAt(0) as ViewGroup
|
|
449
|
+
val button = (0 until content.childCount).map(content::getChildAt).filterIsInstance<TextView>().single()
|
|
450
|
+
val normal = com.facebook.react.common.assets.ReactFontManager.getInstance()
|
|
451
|
+
.getTypeface("serif", Typeface.NORMAL, instrumentation.targetContext.assets)
|
|
452
|
+
val expected = if (android.os.Build.VERSION.SDK_INT >= 28) Typeface.create(normal, 600, normal.isItalic)
|
|
453
|
+
else Typeface.create(normal, Typeface.BOLD)
|
|
454
|
+
for (config in listOf("{}", """{"activeFontFamily":""}""")) {
|
|
455
|
+
tab.updateConfigJSON(config)
|
|
456
|
+
tab.measure(View.MeasureSpec.makeMeasureSpec(320, View.MeasureSpec.EXACTLY),
|
|
457
|
+
View.MeasureSpec.makeMeasureSpec(44, View.MeasureSpec.EXACTLY))
|
|
458
|
+
tab.layout(0, 0, 320, 44)
|
|
459
|
+
assertEquals(expected, button.typeface)
|
|
460
|
+
if (android.os.Build.VERSION.SDK_INT >= 28) assertEquals(600, button.typeface.weight)
|
|
461
|
+
}
|
|
462
|
+
tab.updateConfigJSON("""{"activeFontFamily":"monospace"}""")
|
|
463
|
+
tab.setProgress(0f)
|
|
464
|
+
val explicit = com.facebook.react.common.assets.ReactFontManager.getInstance()
|
|
465
|
+
.getTypeface("monospace", Typeface.NORMAL, instrumentation.targetContext.assets)
|
|
466
|
+
assertEquals(explicit, button.typeface)
|
|
467
|
+
tab.updateStyle(44.0, "text", 0.0, 0.0, 0.0, 18.0, null, 0.0, 0.0)
|
|
468
|
+
tab.updateConfigJSON("{}")
|
|
469
|
+
tab.setProgress(0f)
|
|
470
|
+
val system = if (android.os.Build.VERSION.SDK_INT >= 28) Typeface.create(Typeface.create("sans-serif", Typeface.NORMAL), 600, false)
|
|
471
|
+
else Typeface.create("sans-serif", Typeface.BOLD)
|
|
472
|
+
assertEquals(system, button.typeface)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
}
|