Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/libs/Browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type {GetBrowser, IsMobile, IsMobileChrome, IsMobileIOS, IsMobileSafari, IsMobileSafariOnIos26, IsMobileWebKit, IsSafari} from './types';
import type {GetBrowser, IsIPadInDesktopMode, IsMobile, IsMobileChrome, IsMobileIOS, IsMobileSafari, IsMobileSafariOnIos26, IsMobileWebKit, IsSafari} from './types';

const getBrowser: GetBrowser = () => '';

const isMobile: IsMobile = () => false;

const isIPadInDesktopMode: IsIPadInDesktopMode = () => false;

const isMobileIOS: IsMobileIOS = () => false;

const isMobileSafari: IsMobileSafari = () => false;
Expand All @@ -16,4 +18,4 @@ const isSafari: IsSafari = () => false;

const isMobileSafariOnIos26: IsMobileSafariOnIos26 = () => false;

export {getBrowser, isMobile, isMobileIOS, isMobileSafari, isMobileWebKit, isSafari, isMobileSafariOnIos26, isMobileChrome};
export {getBrowser, isMobile, isIPadInDesktopMode, isMobileIOS, isMobileSafari, isMobileWebKit, isSafari, isMobileSafariOnIos26, isMobileChrome};
10 changes: 8 additions & 2 deletions src/libs/Browser/index.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getOSAndName from '@libs/actions/Device/getDeviceInfo/getOSAndName';

import CONST from '@src/CONST';

import type {GetBrowser, IsMobile, IsMobileChrome, IsMobileIOS, IsMobileSafari, IsMobileSafariOnIos26, IsMobileWebKit, IsSafari} from './types';
import type {GetBrowser, IsIPadInDesktopMode, IsMobile, IsMobileChrome, IsMobileIOS, IsMobileSafari, IsMobileSafariOnIos26, IsMobileWebKit, IsSafari} from './types';

/**
* Fetch browser name from UA string
Expand Down Expand Up @@ -41,6 +41,12 @@ const getBrowser: GetBrowser = () => {
*/
const isMobile: IsMobile = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Silk|Opera Mini/i.test(navigator.userAgent);

/**
* iPadOS Safari in "Request Desktop Website" mode (the default) reports a Macintosh user agent that
* isMobile() can't recognize; real Macs report zero touch points.
*/
const isIPadInDesktopMode: IsIPadInDesktopMode = () => /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints > 1;

const isMobileIOS: IsMobileIOS = () => {
const userAgent = navigator.userAgent;
return /iP(ad|od|hone)/i.test(userAgent);
Expand Down Expand Up @@ -78,4 +84,4 @@ const isMobileSafariOnIos26: IsMobileSafariOnIos26 = (): boolean => {
return isMobileSafari() && getOSAndName().osVersion === '26';
};

export {getBrowser, isMobile, isMobileIOS, isMobileSafari, isMobileWebKit, isSafari, isMobileChrome, isMobileSafariOnIos26};
export {getBrowser, isMobile, isIPadInDesktopMode, isMobileIOS, isMobileSafari, isMobileWebKit, isSafari, isMobileChrome, isMobileSafariOnIos26};
4 changes: 3 additions & 1 deletion src/libs/Browser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ type GetBrowser = () => string;

type IsMobile = () => boolean;

type IsIPadInDesktopMode = () => boolean;

type IsMobileIOS = () => boolean;

type IsMobileSafari = () => boolean;
Expand All @@ -14,4 +16,4 @@ type IsSafari = () => boolean;

type IsMobileSafariOnIos26 = () => boolean;

export type {GetBrowser, IsMobile, IsMobileIOS, IsMobileSafari, IsMobileChrome, IsMobileWebKit, IsSafari, IsMobileSafariOnIos26};
export type {GetBrowser, IsMobile, IsIPadInDesktopMode, IsMobileIOS, IsMobileSafari, IsMobileChrome, IsMobileWebKit, IsSafari, IsMobileSafariOnIos26};
8 changes: 1 addition & 7 deletions src/libs/snapshotPickedFile/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {isMobile} from '@libs/Browser';

// iPadOS Safari in "Request Desktop Website" mode (the default) reports a Macintosh user agent that
// isMobile() can't recognize; real Macs report zero touch points.
function isIPadInDesktopMode(): boolean {
return /Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints > 1;
}
import {isIPadInDesktopMode, isMobile} from '@libs/Browser';

/**
* Copies a picked file's bytes into a memory-backed File. A picked File only references its OS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import useOnyx from '@hooks/useOnyx';
import useOriginalReportID from '@hooks/useOriginalReportID';
import useResponsiveLayout from '@hooks/useResponsiveLayout';

import {isIPadInDesktopMode, isMobile} from '@libs/Browser';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import Log from '@libs/Log';
import {chatIncludesConcierge} from '@libs/ReportUtils';
Expand Down Expand Up @@ -36,6 +37,7 @@ import useDebouncedCommentMaxLengthValidation from './useDebouncedCommentMaxLeng
import useEditMessage from './useEditMessage';

const shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();
const isMobileBrowser = isMobile() || isIPadInDesktopMode();

type ComposerProviderProps = {
reportID: string;
Expand All @@ -51,7 +53,7 @@ function ComposerProvider({children, reportID}: ComposerProviderProps) {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`);

const shouldFocusComposerOnScreenFocus = shouldFocusInputOnScreenFocus || !!draftComment;
const shouldFocusComposerOnScreenFocus = shouldFocusInputOnScreenFocus || (!!draftComment && !isMobileBrowser);
const initialFocused = shouldFocusComposerOnScreenFocus && !initialModalState?.isVisible && !initialModalState?.willAlertModalBecomeVisible;

const includesConcierge = chatIncludesConcierge({participants: report?.participants});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';

import {isMobileSafari} from '@libs/Browser';
import {isIPadInDesktopMode, isMobile, isMobileSafari} from '@libs/Browser';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import {forceClearInput} from '@libs/ComponentUtils';
import {canSkipTriggerHotkeys, findCommonSuffixLength, insertText, insertWhiteSpaceAtIndex} from '@libs/ComposerUtils';
Expand Down Expand Up @@ -207,6 +207,8 @@ const willBlurTextInputOnTapOutside = willBlurTextInputOnTapOutsideFunc();
// prevent auto focus for mobile device
const shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();

const isMobileBrowser = isMobile() || isIPadInDesktopMode();

/**
* This component holds the value and selection state.
* If a component really needs access to these state values it should be put here.
Expand Down Expand Up @@ -387,7 +389,7 @@ function ComposerWithSuggestions({
}, [text]);

const maxComposerLines = shouldUseNarrowLayout ? CONST.COMPOSER.MAX_LINES_SMALL_SCREEN : CONST.COMPOSER.MAX_LINES;
const shouldAutoFocus = (shouldFocusInputOnScreenFocus || !!text) && areAllModalsHidden() && isFocused;
const shouldAutoFocus = (shouldFocusInputOnScreenFocus || (!!text && !isMobileBrowser)) && areAllModalsHidden() && isFocused;
const delayedAutoFocusRouteKeyRef = useRef<string | null>(null);

const valueRef = useRef(initialText);
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/ValidateAttachmentFileSnapshotTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import * as FileUtils from '../../src/libs/fileDownload/FileUtils';
jest.mock('@src/libs/snapshotPickedFile', () => jest.requireActual<{default: (file: File, name: string) => Promise<File>}>('@src/libs/snapshotPickedFile/index.ts'));

// The web snapshot only copies bytes on desktop browsers; make the browser type controllable per test.
// Force the web implementation here too, so the user-agent based checks under test are the real ones.
jest.mock('@src/libs/Browser', () => ({
...jest.requireActual<Record<string, unknown>>('@src/libs/Browser'),
...jest.requireActual<Record<string, unknown>>('@src/libs/Browser/index.web.ts'),
isMobile: jest.fn(() => false),
}));

Expand Down
Loading