Guest User

Untitled

a guest
Oct 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. //this part will be imported via a component. Need to check and make sure how to update state via component.
  4. const checkIfMobile = {
  5. Android: function() {
  6. return navigator.userAgent.match(/Android/i);
  7. },
  8. BlackBerry: function() {
  9. return navigator.userAgent.match(/BlackBerry/i);
  10. },
  11. iOS: function() {
  12. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  13. },
  14. Opera: function() {
  15. return navigator.userAgent.match(/Opera Mini/i);
  16. },
  17. Windows: function() {
  18. return navigator.userAgent.match(/IEMobile/i);
  19. },
  20. any: function() {
  21. return (
  22. checkIfMobile.Android() ||
  23. checkIfMobile.BlackBerry() ||
  24. checkIfMobile.iOS() ||
  25. checkIfMobile.Opera() ||
  26. checkIfMobile.Windows()
  27. );
  28. }
  29. };
  30.  
  31. export default checkIfMobile;
  32.  
  33. import React, { Component } from 'react';
  34. import ChromePluginNotice from '../components/banner/ChromePluginNotice';
  35. import Content from './Content';
  36. import Banner from './Banner';
  37. import Footer from '../components/footer/Footer';
  38. import checkIfMobile from '../components/banner/checks/mobile';
  39.  
  40. // //this part will be imported via a component. Need to check and make sure how to update state via component.
  41. // const checkIfMobile = {
  42. // Android: function() {
  43. // return navigator.userAgent.match(/Android/i);
  44. // },
  45. // BlackBerry: function() {
  46. // return navigator.userAgent.match(/BlackBerry/i);
  47. // },
  48. // iOS: function() {
  49. // return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  50. // },
  51. // Opera: function() {
  52. // return navigator.userAgent.match(/Opera Mini/i);
  53. // },
  54. // Windows: function() {
  55. // return navigator.userAgent.match(/IEMobile/i);
  56. // },
  57. // any: function() {
  58. // return (
  59. // checkIfMobile.Android() ||
  60. // checkIfMobile.BlackBerry() ||
  61. // checkIfMobile.iOS() ||
  62. // checkIfMobile.Opera() ||
  63. // checkIfMobile.Windows()
  64. // );
  65. // }
  66. // };
  67.  
  68. export default class App extends Component {
  69. constructor() {
  70. super();
  71. this.state = { isMobile: checkIfMobile.any() };
  72. }
  73. render() {
  74. const { isMobile } = this.state; // destructure isMobile to variable
  75.  
  76. return (
  77. <div>
  78. <ChromePluginNotice />
  79.  
  80. <Banner isMobile={isMobile} />
  81. <Content isMobile={isMobile} />
  82. <Footer />
  83. </div>
  84. );
  85. }
  86. }
Add Comment
Please, Sign In to add comment