Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Locale Picker and small picker styles #4810

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/CONST.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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, {PureComponent} from 'react';
import React, {Component} 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 PureComponent {
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
class ExpensiPicker extends Component {
constructor() {
super();
this.state = {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const Picker = ({
fixAndroidTouchableBug
onOpen={onOpen}
onClose={onClose}
pickerProps={{
onFocus: onOpen,
onBlur: onClose,
}}
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
/>
);

Expand Down
19 changes: 18 additions & 1 deletion src/components/Picker/pickerStyles/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import CONST from '../../../CONST';
import getBrowser from '../../../libs/getBrowser';
import styles from '../../../styles/styles';

const pickerStyles = disabled => styles.expensiPicker(disabled);
const pickerStylesWeb = () => {
if ([CONST.BROWSER.FIREFOX].includes(getBrowser())) {
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
return {
textIndent: -2,
};
}
return {};
};

const pickerStyles = disabled => ({
...styles.expensiPicker(disabled),
inputWeb: {
...styles.expensiPicker(disabled).inputWeb,
...pickerStylesWeb(),
},
});

export default pickerStyles;
4 changes: 3 additions & 1 deletion src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function setCurrentURL(url) {
* @param {String} locale
*/
function setLocale(locale) {
API.PreferredLocale_Update({name: 'preferredLocale', value: locale});
if (currentUserAccountID) {
API.PreferredLocale_Update({name: 'preferredLocale', value: locale});
}
Onyx.merge(ONYXKEYS.NVP_PREFERRED_LOCALE, locale);
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/getBrowser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => '';
51 changes: 51 additions & 0 deletions src/libs/getBrowser/index.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import CONST from '../../CONST';

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

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

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

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

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

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

if (temp !== null) {
return temp.slice(1).join(' ').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(' ');
}

/**
* Get the Browser name
* @returns {String}
*/
export default () => {
const browserAndVersion = getBrowserVersion();
const [browser] = browserAndVersion.split(' ');
return browser ? browser.toLowerCase() : CONST.BROWSER.OTHER;
};
3 changes: 3 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ const styles = {
borderRadius: variables.componentBorderRadius,
borderWidth: 1,
borderColor: themeColors.border,
borderStyle: 'solid',
color: themeColors.text,
height: variables.componentSizeSmall,
opacity: 1,
Expand All @@ -385,6 +386,7 @@ const styles = {
borderWidth: 1,
borderRadius: variables.componentBorderRadius,
borderColor: themeColors.border,
borderStyle: 'solid',
color: themeColors.text,
appearance: 'none',
height: variables.componentSizeSmall,
Expand All @@ -402,6 +404,7 @@ const styles = {
borderWidth: 1,
borderRadius: variables.componentBorderRadius,
borderColor: themeColors.border,
borderStyle: 'solid',
color: themeColors.text,
height: variables.componentSizeSmall,
opacity: 1,
Expand Down