From 53a0ea1b7f670ba0273de83c28985135f53e55fc Mon Sep 17 00:00:00 2001 From: shall0pass <20625555+shall0pass@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:20:21 -0600 Subject: [PATCH] Use navigitor.userAgent to determine isMobile (#570) * mobile detection * remove intermediate variable --- packages/desktop-client/src/components/FinancesApp.js | 4 ++-- packages/desktop-client/src/util.js | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/desktop-client/src/components/FinancesApp.js b/packages/desktop-client/src/components/FinancesApp.js index e6f3dc6df..d8e44eb6d 100644 --- a/packages/desktop-client/src/components/FinancesApp.js +++ b/packages/desktop-client/src/components/FinancesApp.js @@ -203,7 +203,7 @@ function MobileNavTabs() { class FinancesApp extends React.Component { constructor(props) { super(props); - this.state = { isMobile: isMobile(window.innerWidth) }; + this.state = { isMobile: isMobile() }; this.history = createBrowserHistory(); let oldPush = this.history.push; @@ -232,7 +232,7 @@ class FinancesApp extends React.Component { handleWindowResize() { this.setState({ - isMobile: isMobile(window.innerWidth), + isMobile: isMobile(), windowWidth: window.innerWidth }); } diff --git a/packages/desktop-client/src/util.js b/packages/desktop-client/src/util.js index 2ed5cc5cf..bde05fce7 100644 --- a/packages/desktop-client/src/util.js +++ b/packages/desktop-client/src/util.js @@ -1,12 +1,10 @@ -import tokens from 'loot-design/src/tokens'; - export function getModalRoute(name) { let parts = name.split('/'); return [parts[0], parts.slice(1).join('/')]; } -export function isMobile(width) { - // Simple detection: if the screen width is too small - const containerWidth = width || window.innerWidth; - return containerWidth < parseInt(tokens.breakpoint_medium); +export function isMobile() { + let details = navigator.userAgent; + let regexp = /Mobi|android|iphone|kindle|ipad/i; + return regexp.test(details); } -- GitLab