Skip to content

Commit

Permalink
Fixed scrolling inaccuracy on Android (#4482)
Browse files Browse the repository at this point in the history
Fixed scrolling inaccuracy on Android
  • Loading branch information
gosha212 committed May 6, 2024
1 parent 047c95a commit 6f35c85
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class DetoxScrollActionBase internal constructor(
: ViewAction {
override fun getConstraints(): Matcher<View> = allOf(isAssignableFrom(View::class.java), isDisplayed())
override fun perform(uiController: UiController?, view: View?) =
ScrollHelper.perform(uiController, view, direction, amountInDp, startOffsetPercentX, startOffsetPercentY)
ScrollHelper.perform(uiController, view, direction, amountInDp, startOffsetPercentX, startOffsetPercentY)
}

class DetoxScrollAction(@MotionDir direction: Int, amountInDp: Double, startOffsetPercentX: Float?, startOffsetPercentY: Float?)
Expand All @@ -30,6 +30,8 @@ class DetoxScrollAction(@MotionDir direction: Int, amountInDp: Double, startOffs
override fun perform(uiController: UiController?, view: View?) {
try {
super.perform(uiController, view)
} catch (e: ScrollEdgeException) {
// Hit the edge
} catch (e: Exception) {
throw DetoxRuntimeException(e)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wix.detox.espresso.scroll

/**
* Along with [FlinglessSwiper], this is based on from Espresso's implementation of Swiping
* Along with [LinearSwiper], this is based on from Espresso's implementation of Swiping
* (i.e. in [androidx.test.espresso.action.Swipe] - typically dispatched via the
* [androidx.test.espresso.action.GeneralSwipeAction] action class).
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class ScrollHelper {
private static final String LOG_TAG = "DetoxScrollHelper";

private static final int SCROLL_MOTIONS = 70;
private static final int SCROLL_MOTIONS = 40;
private static final int MAX_FLING_WAITS = 3;

private static final double DEFAULT_DEADZONE_PERCENT = 0.05;
Expand Down Expand Up @@ -95,7 +95,7 @@ private static void scrollOnce(UiController uiController, View view, @MotionDir
}

private static void doScroll(final Context context, final UiController uiController, int downX, int downY, int upX, int upY) {
final DetoxSwiper swiper = new FlinglessSwiper(SCROLL_MOTIONS, uiController, ViewConfiguration.get(context));
final DetoxSwiper swiper = new LinearSwiper(uiController);
final DetoxSwipe swipe = new DetoxSwipe(downX, downY, upX, upY, SCROLL_MOTIONS, swiper);
swipe.perform();
}
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions detox/test/e2e/03.actions-scroll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ describe('Actions - Scroll', () => {
await expect(element(by.text('Text4'))).not.toBeVisible();
});

custom.it.withFailureIf.android('should scroll for a large amount in direction', async () => {
await expect(element(by.text('Text6'))).not.toBeVisible();
await element(by.id('ScrollView161')).scroll(220, 'down');
await expect(element(by.text('Text6'))).toBeVisible();
it('should scroll for a large amount in direction', async () => {
await expect(element(by.text('Text12'))).not.toBeVisible();
await element(by.id('ScrollView161')).scroll(1000, 'down');
await expect(element(by.text('Text12'))).toBeVisible();
});

it('should scroll for a large amount in horizontal direction', async () => {
Expand Down
3 changes: 1 addition & 2 deletions detox/test/e2e/03.actions.visibility-workaround.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {scrollViewDriver} = require('./drivers/fs-scroll-driver');
const {expectToThrow} = require('./utils/custom-expects');

/**
* A mini suite providing an alternative to tests failing due to issues found in RN 58+ on Android (see
Expand Down Expand Up @@ -32,7 +31,7 @@ describe(':android: Visibility-bug workaround actions', () => {
await expect(scrollViewDriver.firstItem()).toBeVisible();
await expect(scrollViewDriver.lastItem()).not.toBeVisible();

await expectToThrow(() => scrollViewDriver.scrollBy(1000));
await scrollViewDriver.scrollBy(3000);

await expect(scrollViewDriver.firstItem()).not.toBeVisible();
await expect(scrollViewDriver.lastItem()).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion detox/test/src/Screens/ScrollActionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ScrollActionsScreen extends Component {

render() {
return (
<View style={{ flex: 1, justifyContent: 'flex-start', borderColor: '#c0c0c0', borderWidth: 1, backgroundColor: '#f8f8ff' }}>
<View style={{ flex: 1, justifyContent: 'flex-start', borderColor: '#c0c0c0', borderWidth: 1, backgroundColor: '#f8f8ff' }} testID='root'>
<ScrollView testID='FSScrollActions.scrollView'>
{
Array.from({length: 20}, (_, index) => this.renderItem(index + 1))
Expand Down

0 comments on commit 6f35c85

Please sign in to comment.