Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
parasharrajat committed Aug 26, 2021
1 parent 1fb5be3 commit fc5f99b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/components/ExpensiPicker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Component} from 'react';
import React, {PureComponent} from 'react';
import {Text, View} from 'react-native';
import PropTypes from 'prop-types';
import Picker from './Picker';
Expand All @@ -17,7 +17,7 @@ const defaultProps = {
isDisabled: false,
};

class ExpensiPicker extends Component {
class ExpensiPicker extends PureComponent {
constructor() {
super();
this.state = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Picker/pickerStyles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import getBrowser from '../../../libs/getBrowser';
import styles from '../../../styles/styles';

const pickerStylesWeb = () => {
if ([CONST.BROWSER.FIREFOX].includes(getBrowser())) {
if (CONST.BROWSER.FIREFOX === getBrowser()) {
return {
textIndent: -2,
};
Expand Down
31 changes: 11 additions & 20 deletions src/libs/getBrowser/index.web.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
import CONST from '../../CONST';

/**
* fetch Browser Name and version from UA string
* fetch Browser name from UA string
*
* @return {String} e.g. Chrome 80
* @return {String} e.g. Chrome
*/
function getBrowserVersion() {
function getBrowser() {
const {userAgent} = window.navigator;
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
let match = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))/i) || [];
let temp;

if (/trident/i.test(match[1])) {
temp = /\brv[ :]+(\d+)/g.exec(userAgent) || [];

return `IE ${temp[1] || ''}`;
return 'IE';
}

if (match[1] === 'Chrome') {
if (match[1] && (match[1].toLowerCase() === 'chrome')) {
temp = userAgent.match(/\b(OPR|Edge)\/(\d+)/);

if (temp !== null) {
return temp.slice(1).join(' ').replace('OPR', 'Opera');
return temp.slice(1).replace('OPR', 'Opera');
}

temp = userAgent.match(/\b(Edg)\/(\d+)/);

if (temp !== null) {
return temp.slice(1).join(' ').replace('Edg', 'Edge');
return temp.slice(1).replace('Edg', 'Edge');
}
}

match = match[2] ? [match[1], match[2]] : [navigator.appName, navigator.appVersion, '-?'];
temp = userAgent.match(/version\/(\d+)/i);

if (temp !== null) {
match.splice(1, 1, temp[1]);
}

return match.join(' ');
match = match[1] ? match[1] : navigator.appName;
return match;
}

/**
* Get the Browser name
* @returns {String}
*/
export default () => {
const browserAndVersion = getBrowserVersion();
const [browser] = browserAndVersion.split(' ');
const browser = getBrowser();
return browser ? browser.toLowerCase() : CONST.BROWSER.OTHER;
};

0 comments on commit fc5f99b

Please sign in to comment.