Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- //this part will be imported via a component. Need to check and make sure how to update state via component.
- const checkIfMobile = {
- Android: function() {
- return navigator.userAgent.match(/Android/i);
- },
- BlackBerry: function() {
- return navigator.userAgent.match(/BlackBerry/i);
- },
- iOS: function() {
- return navigator.userAgent.match(/iPhone|iPad|iPod/i);
- },
- Opera: function() {
- return navigator.userAgent.match(/Opera Mini/i);
- },
- Windows: function() {
- return navigator.userAgent.match(/IEMobile/i);
- },
- any: function() {
- return (
- checkIfMobile.Android() ||
- checkIfMobile.BlackBerry() ||
- checkIfMobile.iOS() ||
- checkIfMobile.Opera() ||
- checkIfMobile.Windows()
- );
- }
- };
- export default checkIfMobile;
- import React, { Component } from 'react';
- import ChromePluginNotice from '../components/banner/ChromePluginNotice';
- import Content from './Content';
- import Banner from './Banner';
- import Footer from '../components/footer/Footer';
- import checkIfMobile from '../components/banner/checks/mobile';
- // //this part will be imported via a component. Need to check and make sure how to update state via component.
- // const checkIfMobile = {
- // Android: function() {
- // return navigator.userAgent.match(/Android/i);
- // },
- // BlackBerry: function() {
- // return navigator.userAgent.match(/BlackBerry/i);
- // },
- // iOS: function() {
- // return navigator.userAgent.match(/iPhone|iPad|iPod/i);
- // },
- // Opera: function() {
- // return navigator.userAgent.match(/Opera Mini/i);
- // },
- // Windows: function() {
- // return navigator.userAgent.match(/IEMobile/i);
- // },
- // any: function() {
- // return (
- // checkIfMobile.Android() ||
- // checkIfMobile.BlackBerry() ||
- // checkIfMobile.iOS() ||
- // checkIfMobile.Opera() ||
- // checkIfMobile.Windows()
- // );
- // }
- // };
- export default class App extends Component {
- constructor() {
- super();
- this.state = { isMobile: checkIfMobile.any() };
- }
- render() {
- const { isMobile } = this.state; // destructure isMobile to variable
- return (
- <div>
- <ChromePluginNotice />
- <Banner isMobile={isMobile} />
- <Content isMobile={isMobile} />
- <Footer />
- </div>
- );
- }
- }
Add Comment
Please, Sign In to add comment