Skip to content

A local-first personal finance app

Use navigitor.userAgent to determine isMobile (#570)

shall0pass53a0ea1b7f67
diff --git a/packages/desktop-client/src/components/FinancesApp.js b/packages/desktop-client/src/components/FinancesApp.js
index e6f3dc6df8..d8e44eb6d1 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 2ed5cc5cfd..bde05fce7d 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);
}