Skip to content

Commit

Permalink
feat: make IPHONE_TOP_BAR_HEIGHT configurable with `safariTabBarPosit…
Browse files Browse the repository at this point in the history
…ion` (#1361)

* feat: make IPHONE_TOP_BAR_HEIGHT configurable

* adjust a bit

* only iphone
  • Loading branch information
KazuCocoa authored Dec 11, 2021
1 parent 68767fa commit e845528
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ nativeWebTap | boolean | See the description of the corresponding capability.
nativeWebTapStrict | boolean | See the description of the corresponding capability.
nativeWebTapTabBarVisibility | enum | Bypass finding whether the existence of the _**tab bar**_ before tapping on the element. It could make native web tap faster. If it's `visible`, tab bar offset will be added without checking the existence of the tab bar. It's `invisible`, the tab bar offset will be `zero`. If you want to leave Appium to check and measure the tab bar offset, unset or set `detect`. Only applicable if `nativeWebTap` and `nativeWebTapStrict` are enabled. Unset by default.
nativeWebTapSmartAppBannerVisibility | enum | The same as `nativeWebTapTabBarVisibility`, this keyword will bypass finding whether the existence of the _**smart app banner**_.
safariTabBarPosition | string | Handle offset of Safari tab bar in `nativeWebTap` enabled interactions. If `platformVersion` was greater than or equal to 15 and iPhone device, the value is `bottom` by default. Otherwise `top`. When the value is `top`, Appium considers offset as the bar length. iOS 15+ environment can customize the bar position in the settings app, so please adjust the offset with this. Acceptable values: `bottom`, `top`
useJSONSource | boolean | See the description of the corresponding capability.

## Element Location
Expand Down
24 changes: 21 additions & 3 deletions lib/commands/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const INVISIBLE = 'invisible';
const DETECT = 'detect';
const VISIBILITIES = [VISIBLE, INVISIBLE, DETECT];

// The position of Safari's tab (search bar).
// Since iOS 15, the bar is the bottom by default.
const TAB_BAR_POSITION_TOP = 'top';
const TAB_BAR_POSITION_BOTTOM = 'bottom';
const TAB_BAR_POSSITIONS = [TAB_BAR_POSITION_TOP, TAB_BAR_POSITION_BOTTOM];

const commands = {}, helpers = {}, extensions = {};

function isValidElementIdentifier (id) {
Expand Down Expand Up @@ -356,22 +362,32 @@ extensions.getExtraTranslateWebCoordsOffset = async function getExtraTranslateWe
let topOffset = 0;
let bottomOffset = 0;

const isIphone = await this.getSafariIsIphone();

// No need to check whether the Smart App Banner or Tab Bar is visible or not
// if already defined by nativeWebTapTabBarVisibility or nativeWebTapSmartAppBannerVisibility in settings.
const {
nativeWebTapTabBarVisibility,
nativeWebTapSmartAppBannerVisibility
nativeWebTapSmartAppBannerVisibility,
safariTabBarPosition = util.compareVersions(this.opts.platformVersion, '>=', '15.0') && isIphone
? TAB_BAR_POSITION_BOTTOM : TAB_BAR_POSITION_TOP,
} = await this.settings.getSettings();
let tabBarVisibility = _.lowerCase(nativeWebTapTabBarVisibility);
let bannerVisibility = _.lowerCase(nativeWebTapSmartAppBannerVisibility);
const tabBarPosition = _.lowerCase(safariTabBarPosition);

if (!VISIBILITIES.includes(tabBarVisibility)) {
tabBarVisibility = DETECT;
}
if (!VISIBILITIES.includes(bannerVisibility)) {
bannerVisibility = DETECT;
}

const isIphone = await this.getSafariIsIphone();
if (!TAB_BAR_POSSITIONS.includes(tabBarPosition)) {
throw new errors.InvalidArgumentError(
`${safariTabBarPosition} is invalid as Safari tab bar position. Available positions are ${TAB_BAR_POSSITIONS}.`);
}

const isNotched = isIphone && await this.getSafariIsNotched();

const orientation = realDims.h > realDims.w ? 'PORTRAIT' : 'LANDSCAPE';
Expand All @@ -395,7 +411,9 @@ extensions.getExtraTranslateWebCoordsOffset = async function getExtraTranslateWe
topOffset = 0;
}
} else {
topOffset = IPHONE_TOP_BAR_HEIGHT + notchOffset;
topOffset = tabBarPosition === TAB_BAR_POSITION_BOTTOM ? 0 : IPHONE_TOP_BAR_HEIGHT;
topOffset += notchOffset;
log.debug(`tabBarPosition and topOffset: ${tabBarPosition}, ${topOffset}`);

if (isIphone) {
if (orientation === 'PORTRAIT') {
Expand Down

0 comments on commit e845528

Please sign in to comment.