Skip to content

Commit 06b4ab5

Browse files
Mugurellplingurar@mozilla.com
authored andcommitted
Bug 1991654 - part 1 - Rename current scrolling behavior to EngineViewScrollingGesturesBehavior r=android-reviewers,skhan
The plan is to use the previous name - EngineViewScrollingBehavior for the supertype of this and also of a new behavior using the scroll data for animating the toolbar. Differential Revision: https://phabricator.services.mozilla.com/D267221
1 parent 789d605 commit 06b4ab5

File tree

9 files changed

+59
-59
lines changed

9 files changed

+59
-59
lines changed

mobile/android/android-components/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import mozilla.components.support.ktx.kotlin.trimmed
3737
import mozilla.components.ui.autocomplete.AutocompleteView
3838
import mozilla.components.ui.autocomplete.InlineAutocompleteEditText
3939
import mozilla.components.ui.autocomplete.OnFilterListener
40-
import mozilla.components.ui.widgets.behavior.EngineViewScrollingBehavior
40+
import mozilla.components.ui.widgets.behavior.EngineViewScrollingGesturesBehavior
4141
import kotlin.coroutines.CoroutineContext
4242

4343
internal fun ImageView.setTintResource(@ColorRes tintColorResource: Int) {
@@ -394,26 +394,26 @@ class BrowserToolbar @JvmOverloads constructor(
394394
override fun enableScrolling() {
395395
// Behavior can be changed without us knowing. Not safe to use a memoized value.
396396
(layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
397-
(behavior as? EngineViewScrollingBehavior)?.enableScrolling()
397+
(behavior as? EngineViewScrollingGesturesBehavior)?.enableScrolling()
398398
}
399399
}
400400

401401
override fun disableScrolling() {
402402
// Behavior can be changed without us knowing. Not safe to use a memoized value.
403403
(layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
404-
(behavior as? EngineViewScrollingBehavior)?.disableScrolling()
404+
(behavior as? EngineViewScrollingGesturesBehavior)?.disableScrolling()
405405
}
406406
}
407407

408408
override fun expand() {
409409
(layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
410-
(behavior as? EngineViewScrollingBehavior)?.forceExpand(this@BrowserToolbar)
410+
(behavior as? EngineViewScrollingGesturesBehavior)?.forceExpand(this@BrowserToolbar)
411411
}
412412
}
413413

414414
override fun collapse() {
415415
(layoutParams as? CoordinatorLayout.LayoutParams)?.apply {
416-
(behavior as? EngineViewScrollingBehavior)?.forceCollapse(this@BrowserToolbar)
416+
(behavior as? EngineViewScrollingGesturesBehavior)?.forceCollapse(this@BrowserToolbar)
417417
}
418418
}
419419

mobile/android/android-components/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import mozilla.components.support.test.argumentCaptor
2929
import mozilla.components.support.test.mock
3030
import mozilla.components.support.test.robolectric.testContext
3131
import mozilla.components.support.test.whenever
32-
import mozilla.components.ui.widgets.behavior.EngineViewScrollingBehavior
32+
import mozilla.components.ui.widgets.behavior.EngineViewScrollingGesturesBehavior
3333
import mozilla.components.ui.widgets.behavior.ViewPosition
3434
import org.junit.Assert.assertEquals
3535
import org.junit.Assert.assertFalse
@@ -924,7 +924,7 @@ class BrowserToolbarTest {
924924
fun `enable scrolling is forwarded to the toolbar behavior`() {
925925
// Seems like real instances are needed for things to be set properly
926926
val toolbar = BrowserToolbar(testContext)
927-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
927+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
928928
val params = CoordinatorLayout.LayoutParams(10, 10).apply {
929929
this.behavior = behavior
930930
}
@@ -939,7 +939,7 @@ class BrowserToolbarTest {
939939
fun `disable scrolling is forwarded to the toolbar behavior`() {
940940
// Seems like real instances are needed for things to be set properly
941941
val toolbar = BrowserToolbar(testContext)
942-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
942+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
943943
val params = CoordinatorLayout.LayoutParams(10, 10).apply {
944944
this.behavior = behavior
945945
}
@@ -954,7 +954,7 @@ class BrowserToolbarTest {
954954
fun `expand is forwarded to the toolbar behavior`() {
955955
// Seems like real instances are needed for things to be set properly
956956
val toolbar = BrowserToolbar(testContext)
957-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
957+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
958958
val params = CoordinatorLayout.LayoutParams(10, 10).apply {
959959
this.behavior = behavior
960960
}
@@ -969,7 +969,7 @@ class BrowserToolbarTest {
969969
fun `collapse is forwarded to the toolbar behavior`() {
970970
// Seems like real instances are needed for things to be set properly
971971
val toolbar = BrowserToolbar(testContext)
972-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
972+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
973973
val params = CoordinatorLayout.LayoutParams(10, 10).apply {
974974
this.behavior = behavior
975975
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum class ViewPosition {
3333
* - Show/Hide the [View] automatically when scrolling vertically.
3434
* - Snap the [View] to be hidden or visible when the user stops scrolling.
3535
*/
36-
class EngineViewScrollingBehavior(
36+
class EngineViewScrollingGesturesBehavior(
3737
val context: Context?,
3838
attrs: AttributeSet?,
3939
private val viewPosition: ViewPosition,
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import org.mockito.Mockito.verify
3535
import org.mockito.Mockito.`when`
3636

3737
@RunWith(AndroidJUnit4::class)
38-
class EngineViewScrollingBehaviorTest {
38+
class EngineViewScrollingGesturesBehaviorTest {
3939
@Test
4040
fun `onStartNestedScroll should attempt scrolling only if browserToolbar is valid`() {
41-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
41+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
4242
doReturn(true).`when`(behavior).shouldScroll
4343

4444
behavior.dynamicScrollView = null
@@ -68,7 +68,7 @@ class EngineViewScrollingBehaviorTest {
6868

6969
@Test
7070
fun `startNestedScroll should cancel an ongoing snap animation`() {
71-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
71+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
7272
val yTranslator: ViewYTranslator = mock()
7373
behavior.yTranslator = yTranslator
7474
doReturn(true).`when`(behavior).shouldScroll
@@ -84,7 +84,7 @@ class EngineViewScrollingBehaviorTest {
8484

8585
@Test
8686
fun `startNestedScroll should not accept nested scrolls on the horizontal axis`() {
87-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
87+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
8888
doReturn(true).`when`(behavior).shouldScroll
8989

9090
var acceptsNestedScroll = behavior.startNestedScroll(
@@ -102,7 +102,7 @@ class EngineViewScrollingBehaviorTest {
102102

103103
@Test
104104
fun `GIVEN a gesture that doesn't scroll the toolbar WHEN startNestedScroll THEN nested scroll is not accepted`() {
105-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
105+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
106106
val engineView: EngineView = mock()
107107
val inputResultDetail: InputResultDetail = mock()
108108
val yTranslator: ViewYTranslator = mock()
@@ -122,7 +122,7 @@ class EngineViewScrollingBehaviorTest {
122122

123123
@Test
124124
fun `Behavior should not accept nested scrolls on the horizontal axis`() {
125-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
125+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
126126
behavior.dynamicScrollView = mock()
127127
doReturn(true).`when`(behavior).shouldScroll
128128

@@ -149,7 +149,7 @@ class EngineViewScrollingBehaviorTest {
149149

150150
@Test
151151
fun `Behavior should delegate the onStartNestedScroll logic`() {
152-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
152+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
153153
val view: View = mock()
154154
behavior.dynamicScrollView = view
155155
val inputType = ViewCompat.TYPE_TOUCH
@@ -169,7 +169,7 @@ class EngineViewScrollingBehaviorTest {
169169

170170
@Test
171171
fun `onStopNestedScroll should attempt stopping nested scrolling only if browserToolbar is valid`() {
172-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
172+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
173173

174174
behavior.dynamicScrollView = null
175175
behavior.onStopNestedScroll(
@@ -192,7 +192,7 @@ class EngineViewScrollingBehaviorTest {
192192

193193
@Test
194194
fun `Behavior should delegate the onStopNestedScroll logic`() {
195-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
195+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
196196
val inputType = ViewCompat.TYPE_TOUCH
197197
val view: View = mock()
198198

@@ -208,7 +208,7 @@ class EngineViewScrollingBehaviorTest {
208208

209209
@Test
210210
fun `stopNestedScroll will snap toolbar up if toolbar is more than 50 percent visible`() {
211-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
211+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
212212
val yTranslator: ViewYTranslator = mock()
213213
behavior.yTranslator = yTranslator
214214
behavior.dynamicScrollView = mock()
@@ -239,7 +239,7 @@ class EngineViewScrollingBehaviorTest {
239239

240240
@Test
241241
fun `stopNestedScroll will snap toolbar down if toolbar is less than 50 percent visible`() {
242-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
242+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
243243
doReturn(true).`when`(behavior).shouldScroll
244244
val yTranslator: ViewYTranslator = mock()
245245
behavior.yTranslator = yTranslator
@@ -270,7 +270,7 @@ class EngineViewScrollingBehaviorTest {
270270

271271
@Test
272272
fun `onStopNestedScroll should snap the toolbar only if browserToolbar is valid`() {
273-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
273+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
274274
behavior.dynamicScrollView = null
275275

276276
behavior.onStopNestedScroll(
@@ -285,7 +285,7 @@ class EngineViewScrollingBehaviorTest {
285285

286286
@Test
287287
fun `Behavior will intercept MotionEvents and pass them to the custom gesture detector`() {
288-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
288+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
289289
val gestureDetector: BrowserGestureDetector = mock()
290290
behavior.initGesturesDetector(gestureDetector)
291291
behavior.dynamicScrollView = mock()
@@ -298,7 +298,7 @@ class EngineViewScrollingBehaviorTest {
298298

299299
@Test
300300
fun `Behavior should only dispatch MotionEvents to the gesture detector only if browserToolbar is valid`() {
301-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
301+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
302302
val gestureDetector: BrowserGestureDetector = mock()
303303
behavior.initGesturesDetector(gestureDetector)
304304
val downEvent = TestUtils.getMotionEvent(ACTION_DOWN)
@@ -310,7 +310,7 @@ class EngineViewScrollingBehaviorTest {
310310

311311
@Test
312312
fun `Behavior will apply translation to toolbar only for vertical scrolls`() {
313-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
313+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
314314
behavior.initGesturesDetector(behavior.createGestureDetector())
315315
val child = spy(View(testContext, null, 0))
316316
behavior.dynamicScrollView = child
@@ -325,7 +325,7 @@ class EngineViewScrollingBehaviorTest {
325325

326326
@Test
327327
fun `GIVEN a null InputResultDetail from the EngineView WHEN shouldScroll is called THEN it returns false`() {
328-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
328+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
329329
behavior.engineView = null
330330
assertFalse(behavior.shouldScroll)
331331
behavior.engineView = mock()
@@ -336,7 +336,7 @@ class EngineViewScrollingBehaviorTest {
336336

337337
@Test
338338
fun `GIVEN an InputResultDetail with the right values and scroll enabled WHEN shouldScroll is called THEN it returns true`() {
339-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
339+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
340340
val engineView: EngineView = mock()
341341
behavior.engineView = engineView
342342
behavior.isScrollEnabled = true
@@ -358,7 +358,7 @@ class EngineViewScrollingBehaviorTest {
358358

359359
@Test
360360
fun `GIVEN an InputResultDetail with the right values but with scroll disabled WHEN shouldScroll is called THEN it returns false`() {
361-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
361+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
362362
behavior.engineView = mock()
363363
behavior.isScrollEnabled = false
364364
val validInputResultDetail: InputResultDetail = mock()
@@ -370,7 +370,7 @@ class EngineViewScrollingBehaviorTest {
370370

371371
@Test
372372
fun `GIVEN scroll enabled but EngineView cannot scroll to bottom WHEN shouldScroll is called THEN it returns false`() {
373-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
373+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
374374
behavior.engineView = mock()
375375
behavior.isScrollEnabled = true
376376
val validInputResultDetail: InputResultDetail = mock()
@@ -382,7 +382,7 @@ class EngineViewScrollingBehaviorTest {
382382

383383
@Test
384384
fun `GIVEN scroll enabled but EngineView cannot scroll to top WHEN shouldScroll is called THEN it returns false`() {
385-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
385+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
386386
behavior.engineView = mock()
387387
behavior.isScrollEnabled = true
388388
val validInputResultDetail: InputResultDetail = mock()
@@ -394,7 +394,7 @@ class EngineViewScrollingBehaviorTest {
394394

395395
@Test
396396
fun `Behavior will vertically scroll nested scroll started and EngineView handled the event`() {
397-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
397+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
398398
val yTranslator: ViewYTranslator = mock()
399399
behavior.yTranslator = yTranslator
400400
doReturn(true).`when`(behavior).shouldScroll
@@ -411,7 +411,7 @@ class EngineViewScrollingBehaviorTest {
411411

412412
@Test
413413
fun `Behavior will not scroll vertically if startedScroll is false`() {
414-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
414+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
415415
val yTranslator: ViewYTranslator = mock()
416416
behavior.yTranslator = yTranslator
417417
doReturn(true).`when`(behavior).shouldScroll
@@ -428,7 +428,7 @@ class EngineViewScrollingBehaviorTest {
428428

429429
@Test
430430
fun `Behavior will not scroll vertically if EngineView did not handled the event`() {
431-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
431+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
432432
val yTranslator: ViewYTranslator = mock()
433433
behavior.yTranslator = yTranslator
434434
doReturn(false).`when`(behavior).shouldScroll
@@ -444,7 +444,7 @@ class EngineViewScrollingBehaviorTest {
444444

445445
@Test
446446
fun `forceExpand should delegate the translator`() {
447-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
447+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
448448
val yTranslator: ViewYTranslator = mock()
449449
behavior.yTranslator = yTranslator
450450
val view: View = mock()
@@ -456,7 +456,7 @@ class EngineViewScrollingBehaviorTest {
456456

457457
@Test
458458
fun `forceCollapse should delegate the translator`() {
459-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
459+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
460460
val yTranslator: ViewYTranslator = mock()
461461
behavior.yTranslator = yTranslator
462462
val view: View = mock()
@@ -468,7 +468,7 @@ class EngineViewScrollingBehaviorTest {
468468

469469
@Test
470470
fun `Behavior will not forceExpand when scrolling up and !shouldScroll if the touch was not yet handled in the browser`() {
471-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
471+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
472472
val yTranslator: ViewYTranslator = mock()
473473
behavior.yTranslator = yTranslator
474474
behavior.initGesturesDetector(behavior.createGestureDetector())
@@ -500,7 +500,7 @@ class EngineViewScrollingBehaviorTest {
500500
addView(View(testContext))
501501
addView(engineView)
502502
}
503-
val behavior = spy(EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM))
503+
val behavior = spy(EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM))
504504

505505
behavior.onLayoutChild(container, view, View.LAYOUT_DIRECTION_LTR)
506506

@@ -510,7 +510,7 @@ class EngineViewScrollingBehaviorTest {
510510

511511
@Test
512512
fun `enableScrolling sets isScrollEnabled to true`() {
513-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
513+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
514514

515515
assertFalse(behavior.isScrollEnabled)
516516
behavior.enableScrolling()
@@ -520,7 +520,7 @@ class EngineViewScrollingBehaviorTest {
520520

521521
@Test
522522
fun `disableScrolling sets isScrollEnabled to false`() {
523-
val behavior = EngineViewScrollingBehavior(testContext, null, ViewPosition.BOTTOM)
523+
val behavior = EngineViewScrollingGesturesBehavior(testContext, null, ViewPosition.BOTTOM)
524524
behavior.isScrollEnabled = true
525525

526526
assertTrue(behavior.isScrollEnabled)

0 commit comments

Comments
 (0)