Skip to content
Snippets Groups Projects
Unverified Commit 53a0ea1b authored by shall0pass's avatar shall0pass Committed by GitHub
Browse files

Use navigitor.userAgent to determine isMobile (#570)

* mobile detection

* remove intermediate variable
parent f6973bfd
No related branches found
No related tags found
No related merge requests found
...@@ -203,7 +203,7 @@ function MobileNavTabs() { ...@@ -203,7 +203,7 @@ function MobileNavTabs() {
class FinancesApp extends React.Component { class FinancesApp extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { isMobile: isMobile(window.innerWidth) }; this.state = { isMobile: isMobile() };
this.history = createBrowserHistory(); this.history = createBrowserHistory();
let oldPush = this.history.push; let oldPush = this.history.push;
...@@ -232,7 +232,7 @@ class FinancesApp extends React.Component { ...@@ -232,7 +232,7 @@ class FinancesApp extends React.Component {
handleWindowResize() { handleWindowResize() {
this.setState({ this.setState({
isMobile: isMobile(window.innerWidth), isMobile: isMobile(),
windowWidth: window.innerWidth windowWidth: window.innerWidth
}); });
} }
......
import tokens from 'loot-design/src/tokens';
export function getModalRoute(name) { export function getModalRoute(name) {
let parts = name.split('/'); let parts = name.split('/');
return [parts[0], parts.slice(1).join('/')]; return [parts[0], parts.slice(1).join('/')];
} }
export function isMobile(width) { export function isMobile() {
// Simple detection: if the screen width is too small let details = navigator.userAgent;
const containerWidth = width || window.innerWidth; let regexp = /Mobi|android|iphone|kindle|ipad/i;
return containerWidth < parseInt(tokens.breakpoint_medium); return regexp.test(details);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment