diff --git a/e2e/kit/helpers/actions/index.ts b/e2e/kit/helpers/actions/index.ts index ac7cf2ea7..499584162 100644 --- a/e2e/kit/helpers/actions/index.ts +++ b/e2e/kit/helpers/actions/index.ts @@ -1,5 +1,4 @@ import colors from "colors/safe"; -import { expect } from "detox"; import { waitForElementById } from "../awaitable"; import { getDevicePreference } from "../env/devicePreferences"; @@ -129,26 +128,30 @@ export const scrollDownUntilElementIsVisible = async ( .scroll(100, "down", NaN, 0.5); }; +type Frame = { + x: number; + y: number; + width: number; + height: number; +}; + export const scrollUpUntilElementIsBarelyVisible = async ( scrollViewId: string, elementId: string, + threshold = 10, ): Promise => { - for (;;) { - await element(by.id(scrollViewId)).scroll(50, "up", 0.01, 0.5); - - try { - // verify that we can interact with element - if (device.getPlatform() === "ios") { - await expect(element(by.id(elementId))).toBeVisible(); - } else { - // on Android visible is always true - await element(by.id(elementId)).tap({ x: 0, y: 25 }); - } - } catch (e) { - await element(by.id(scrollViewId)).scroll(35, "down", 0.01, 0.5); - break; - } - } + const preference = getDevicePreference(); + const { frame } = (await element(by.id(elementId)).getAttributes()) as { + frame: Frame; + }; + const distance = + preference.height - + preference.keyboard - + frame.y - + frame.height - + threshold; + + await element(by.id(scrollViewId)).scroll(distance, "up", 0.01, 0.5); }; export const closeKeyboard = async (textInputId: string) => { diff --git a/e2e/kit/helpers/env/devicePreferences.ts b/e2e/kit/helpers/env/devicePreferences.ts index c9310b180..4f702148b 100644 --- a/e2e/kit/helpers/env/devicePreferences.ts +++ b/e2e/kit/helpers/env/devicePreferences.ts @@ -2,37 +2,44 @@ import parseDeviceName from "../../utils/parseDeviceName"; type Preference = { emojiButtonCoordinates?: { x: number; y: number }; + keyboard: number; width: number; height: number; }; const DEVICE_PREFERENCES: Record = { "e2e_emulator_28": { + keyboard: 980, emojiButtonCoordinates: undefined, width: 1080, height: 1920, }, "e2e_emulator_31": { + keyboard: 900, emojiButtonCoordinates: { x: 324, y: 1704 }, width: 1080, height: 1920, }, "iPhone 16 Pro": { + keyboard: 291, emojiButtonCoordinates: { x: 40, y: 830 }, width: 393, height: 852, }, "iPhone 15 Pro": { + keyboard: 291, emojiButtonCoordinates: { x: 40, y: 830 }, width: 393, height: 852, }, "iPhone 14 Pro": { + keyboard: 291, emojiButtonCoordinates: { x: 40, y: 830 }, width: 393, height: 852, }, "iPhone 13 Pro": { + keyboard: 286, emojiButtonCoordinates: { x: 40, y: 830 }, width: 390, height: 844,