Skip to content

Commit e206347

Browse files
committed
Merge branch 'master' into release
2 parents 02fc75e + 570229f commit e206347

File tree

17 files changed

+154
-54
lines changed

17 files changed

+154
-54
lines changed

demo/src/screens/MainScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export default class UiLibExplorerMenu extends Component {
307307
const data = this.getMenuData();
308308

309309
return (
310-
<View flex bg-dark80>
310+
<View testID="demo_main_screen" flex bg-dark80>
311311
{this.renderHeader()}
312312
{showNoResults && (
313313
<View paddingH-24>

eslint-rules/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module.exports = {
22
rules: {
33
'no-hard-coded-color': require('./lib/rules/no-hard-coded-color'),
4-
'component-deprecation': require('./lib/rules/component-deprecation'),
54
'no-direct-import': require('./lib/rules/no-direct-import'),
5+
'component-deprecation': require('./lib/rules/component-deprecation'),
66
'assets-deprecation': require('./lib/rules/assets-deprecation'),
7+
// for duplicate rules usage
8+
'component-deprecation_warn': require('./lib/rules/component-deprecation'),
9+
'assets-deprecation_warn': require('./lib/rules/assets-deprecation'),
10+
'component-deprecation_error': require('./lib/rules/component-deprecation'),
11+
'assets-deprecation_error': require('./lib/rules/assets-deprecation'),
712
},
813
};

eslint-rules/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-uilib",
3-
"version": "1.0.16",
3+
"version": "1.0.18",
44
"description": "uilib set of eslint rules",
55
"keywords": [
66
"eslint",
@@ -16,7 +16,7 @@
1616
"type": "git",
1717
"url": "https://github.com/wix/react-native-ui-lib"
1818
},
19-
"main": "lib/index.js",
19+
"main": "index.js",
2020
"scripts": {
2121
"test": "mocha tests --recursive",
2222
"test:watch": "mocha tests --recursive --watch"

src/components/avatar/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import React from 'react';
44
import {StyleSheet, ViewPropTypes, TouchableOpacity} from 'react-native';
55
import {Colors, BorderRadiuses} from '../../style';
6-
import {BaseComponent} from '../../commons';
6+
import {PureBaseComponent} from '../../commons';
77
import Badge, {BADGE_SIZES} from '../badge';
88
import View from '../view';
99
import Text from '../text';
@@ -38,7 +38,7 @@ const DEFAULT_BADGE_POSITION = BADGE_POSITIONS.TOP_RIGHT;
3838
* @image: https://user-images.githubusercontent.com/33805983/34480603-197d7f64-efb6-11e7-9feb-db8ba756f055.png
3939
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/AvatarsScreen.js
4040
*/
41-
export default class Avatar extends BaseComponent {
41+
export default class Avatar extends PureBaseComponent {
4242
constructor(props) {
4343
super(props);
4444

src/components/badge/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import React from 'react';
44
import {StyleSheet, Text, ViewPropTypes} from 'react-native';
55
import {View as AnimatableView} from 'react-native-animatable';
6-
import {BaseComponent} from '../../commons';
6+
import {PureBaseComponent} from '../../commons';
77
import {BorderRadiuses, Colors, ThemeManager, Typography} from '../../style';
88
import View from '../view';
99
import Image from '../image';
@@ -27,7 +27,7 @@ export const BADGE_SIZES = {
2727
* @image: https://user-images.githubusercontent.com/33805983/34480753-df7a868a-efb6-11e7-9072-80f5c110a4f3.png
2828
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/BadgesScreen.js
2929
*/
30-
export default class Badge extends BaseComponent {
30+
export default class Badge extends PureBaseComponent {
3131
static displayName = 'Badge';
3232
static propTypes = {
3333
/**
@@ -109,7 +109,7 @@ export default class Badge extends BaseComponent {
109109
const {borderWidth, size, icon} = this.props;
110110
const label = this.getFormattedLabel();
111111
const badgeHeight = _.isNumber(size) ? size : BADGE_SIZES[size];
112-
112+
113113
const style = {
114114
paddingHorizontal: this.isSmallBadge() ? 4 : 6,
115115
height: badgeHeight,

src/components/button/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import {Platform, StyleSheet, LayoutAnimation, Image} from 'react-native';
55
import {Constants} from '../../helpers';
66
import {Colors, Typography, ThemeManager, BorderRadiuses} from '../../style';
7-
import {BaseComponent} from '../../commons';
7+
import {PureBaseComponent} from '../../commons';
88
import TouchableOpacity from '../touchableOpacity';
99
import View from '../view';
1010
import Text from '../text';
@@ -38,7 +38,7 @@ const DEFAULT_SIZE = 'large';
3838
* @gif: https://media.giphy.com/media/xULW8j5WzsuPytqklq/giphy.gif
3939
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/ButtonsScreen.js
4040
*/
41-
export default class Button extends BaseComponent {
41+
export default class Button extends PureBaseComponent {
4242
static displayName = 'Button';
4343
static propTypes = {
4444
...Text.propTypes,
@@ -185,7 +185,7 @@ export default class Button extends BaseComponent {
185185
const size = height >= width ? height : width;
186186
this.setState({size});
187187
}
188-
188+
189189
if (Constants.isAndroid && Platform.Version <= 17) {
190190
this.setState({borderRadius: height / 2});
191191
}
@@ -271,29 +271,29 @@ export default class Button extends BaseComponent {
271271
const outlineWidth = this.getThemeProps().outlineWidth || 1;
272272

273273
const CONTAINER_STYLE_BY_SIZE = {};
274-
CONTAINER_STYLE_BY_SIZE[Button.sizes.xSmall] = round ?
275-
{height: this.state.size, width: this.state.size, padding: PADDINGS.XSMALL} :
274+
CONTAINER_STYLE_BY_SIZE[Button.sizes.xSmall] = round ?
275+
{height: this.state.size, width: this.state.size, padding: PADDINGS.XSMALL} :
276276
{
277277
paddingVertical: PADDINGS.XSMALL,
278278
paddingHorizontal: HORIZONTAL_PADDINGS.XSMALL,
279279
minWidth: MIN_WIDTH.XSMALL,
280280
};
281281
CONTAINER_STYLE_BY_SIZE[Button.sizes.small] = round ?
282-
{height: this.state.size, width: this.state.size, padding: PADDINGS.SMALL} :
282+
{height: this.state.size, width: this.state.size, padding: PADDINGS.SMALL} :
283283
{
284284
paddingVertical: PADDINGS.SMALL,
285285
paddingHorizontal: HORIZONTAL_PADDINGS.SMALL,
286286
minWidth: MIN_WIDTH.SMALL,
287287
};
288-
CONTAINER_STYLE_BY_SIZE[Button.sizes.medium] = round ?
289-
{height: this.state.size, width: this.state.size, padding: PADDINGS.MEDIUM} :
288+
CONTAINER_STYLE_BY_SIZE[Button.sizes.medium] = round ?
289+
{height: this.state.size, width: this.state.size, padding: PADDINGS.MEDIUM} :
290290
{
291291
paddingVertical: PADDINGS.MEDIUM,
292292
paddingHorizontal: HORIZONTAL_PADDINGS.MEDIUM,
293293
minWidth: MIN_WIDTH.MEDIUM,
294294
};
295-
CONTAINER_STYLE_BY_SIZE[Button.sizes.large] = round ?
296-
{height: this.state.size, width: this.state.size, padding: PADDINGS.LARGE} :
295+
CONTAINER_STYLE_BY_SIZE[Button.sizes.large] = round ?
296+
{height: this.state.size, width: this.state.size, padding: PADDINGS.LARGE} :
297297
{
298298
paddingVertical: PADDINGS.LARGE,
299299
paddingHorizontal: HORIZONTAL_PADDINGS.LARGE,
@@ -333,7 +333,7 @@ export default class Button extends BaseComponent {
333333

334334
getOutlineStyle() {
335335
const {outline, outlineColor, outlineWidth, link, disabled} = this.getThemeProps();
336-
336+
337337
let outlineStyle;
338338
if ((outline || outlineColor) && !link) {
339339
outlineStyle = {
@@ -410,7 +410,7 @@ export default class Button extends BaseComponent {
410410

411411
renderIcon() {
412412
const {iconSource} = this.props;
413-
413+
414414
if (iconSource) {
415415
const iconStyle = this.getIconStyle();
416416
if (typeof iconSource === 'function') {
@@ -427,7 +427,7 @@ export default class Button extends BaseComponent {
427427
const typography = this.extractTypographyValue();
428428
const color = this.getLabelColor();
429429
const labelSizeStyle = this.getLabelSizeStyle();
430-
430+
431431
if (label) {
432432
return (
433433
<Text

src/components/card/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {StyleSheet, ViewPropTypes, Animated} from 'react-native';
55
import {BlurView} from '@react-native-community/blur';
66
import {Constants} from '../../helpers';
77
import {Colors, BorderRadiuses} from '../../style';
8-
import {BaseComponent} from '../../commons';
8+
import {PureBaseComponent} from '../../commons';
99
import View from '../view';
1010
import TouchableOpacity from '../touchableOpacity';
1111
import Image from '../image';
@@ -32,7 +32,7 @@ const DEFAULT_SELECTION_PROPS = {
3232
* @gif: https://media.giphy.com/media/l0HU9SKWmv0VTOYMM/giphy.gif
3333
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/CardsScreen.js
3434
*/
35-
class Card extends BaseComponent {
35+
class Card extends PureBaseComponent {
3636
static displayName = 'Card';
3737

3838
static propTypes = {

src/components/connectionStatusBar/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import _ from 'lodash';
44
import {StyleSheet, Text, NetInfo} from 'react-native';
55
import * as Constants from '../../helpers/Constants';
6-
import {BaseComponent} from '../../commons';
6+
import {PureBaseComponent} from '../../commons';
77
import {Colors, Typography} from '../../style';
88
import TouchableOpacity from '../touchableOpacity';
99
import View from '../view';
@@ -13,7 +13,7 @@ import View from '../view';
1313
* @image: https://user-images.githubusercontent.com/33805983/34683190-f3b1904c-f4a9-11e7-9d46-9a340bd35448.png, https://user-images.githubusercontent.com/33805983/34484206-edc6c6e4-efcb-11e7-88b2-cd394c19dd5e.png
1414
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/ConnectionStatusBarScreen.js
1515
*/
16-
export default class ConnectionStatusBar extends BaseComponent {
16+
export default class ConnectionStatusBar extends PureBaseComponent {
1717
static displayName = 'ConnectionStatusBar';
1818
static propTypes = {
1919
/**

src/components/hint/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Hint extends BaseComponent {
124124
};
125125

126126
onTargetLayout = ({nativeEvent: {layout}}) => {
127-
if (!this.state.targetLayout) {
127+
if (!_.isEqual(this.state.targetLayout, layout)) {
128128
this.setState({
129129
targetLayout: layout,
130130
});

src/components/image/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import React from 'react';
44
import hoistNonReactStatic from 'hoist-non-react-statics';
55
import {Image as RNImage, StyleSheet} from 'react-native';
66
import {Constants} from '../../helpers';
7-
import {BaseComponent} from '../../commons';
7+
import {PureBaseComponent} from '../../commons';
88
import Assets from '../../assets';
99

1010
/**
1111
* @description: Image wrapper with extra functionality like source transform and assets support
1212
* @extends: Image
1313
* @extendslink: https://facebook.github.io/react-native/docs/image.html
1414
*/
15-
class Image extends BaseComponent {
15+
class Image extends PureBaseComponent {
1616
static displayName = 'Image';
1717

1818
static propTypes = {

src/components/text/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import {Text as RNText, StyleSheet} from 'react-native';
4-
import {BaseComponent} from '../../commons';
4+
import {PureBaseComponent} from '../../commons';
55

66
/**
77
* @description: A wrapper for Text component with extra functionality like modifiers support
88
* @extends: Text
99
* @extendslink: https://facebook.github.io/react-native/docs/text.html
1010
* @modifiers: margins, color, typography
1111
*/
12-
export default class Text extends BaseComponent {
12+
export default class Text extends PureBaseComponent {
1313
static displayName = 'Text';
1414
static propTypes = {
1515
...RNText.propTypes,
16-
...BaseComponent.propTypes,
16+
...PureBaseComponent.propTypes,
1717
/**
1818
* color of the text
1919
*/

src/components/touchableOpacity/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import {TouchableOpacity as RNTouchableOpacity} from 'react-native';
33
import PropTypes from 'prop-types';
44
import _ from 'lodash';
5-
import {BaseComponent} from '../../commons';
5+
import {PureBaseComponent} from '../../commons';
66

77
/**
88
* @description: A wrapper for TouchableOpacity component. Support onPress, throttling and activeBackgroundColor
@@ -12,12 +12,12 @@ import {BaseComponent} from '../../commons';
1212
* @gif: https://media.giphy.com/media/xULW8AMIgw7l31zjm8/giphy.gif
1313
* @example: https://github.com/wix/react-native-ui-lib/blob/master/src/components/touchableOpacity/index.js
1414
*/
15-
export default class TouchableOpacity extends BaseComponent {
15+
export default class TouchableOpacity extends PureBaseComponent {
1616
static displayName = 'TouchableOpacity';
1717

1818
static propTypes = {
1919
/**
20-
* background color for TouchableOpacity
20+
* background color for TouchableOpacity
2121
*/
2222
backgroundColor: PropTypes.string,
2323
/**

src/helpers/Constants.js

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,77 @@
1+
import _ from 'lodash';
12
import {Platform, Dimensions, NativeModules, I18nManager} from 'react-native';
23

3-
const {StatusBarManager} = NativeModules;
4-
const {height, width} = Dimensions.get('window');
54

5+
const dimensionsScope = {
6+
WINDOW: 'window',
7+
SCREEN: 'screen'
8+
}
9+
const orientations = {
10+
PORTRAIT: 'portrait',
11+
LANDSCAPE: 'landscape'
12+
}
13+
14+
/* Platform */
615
export const isAndroid = Platform.OS === 'android';
716
export const isIOS = Platform.OS === 'ios';
8-
export const screenWidth = width;
9-
export const screenHeight = height;
10-
// export const isSmallScreen = isIOS ? screenWidth <= 320 : screenWidth <= 360;
11-
export const isSmallScreen = screenWidth <= 340;
12-
export const isShortScreen = screenHeight <= 600;
13-
export let statusBarHeight = isIOS ? 20 : StatusBarManager.HEIGHT; // eslint-disable-line
14-
export const isIphoneX = isIOS && !Platform.isPad && !Platform.isTVOS && (screenHeight >= 812 || screenWidth >= 812);
15-
export const isRTL = I18nManager.isRTL;
1617

1718
export function getAndroidVersion() {
1819
return isAndroid ? parseInt(Platform.Version, 10) : undefined;
1920
}
2021

21-
export function getSafeAreaInsets(mode) {
22-
return (mode === 'landscape') ?
22+
/* Navigation */
23+
const {StatusBarManager} = NativeModules;
24+
export let statusBarHeight = setStatusBarHeight();
25+
26+
function setStatusBarHeight() {
27+
statusBarHeight = isIOS ? 20 : StatusBarManager.HEIGHT; // eslint-disable-line
28+
if (isIOS) {
29+
// override guesstimate height with the actual height from StatusBarManager
30+
StatusBarManager.getHeight(data => (statusBarHeight = data.height));
31+
}
32+
}
33+
34+
/* Layout */
35+
export const isRTL = I18nManager.isRTL;
36+
37+
const {height, width} = Dimensions.get(dimensionsScope.WINDOW);
38+
export let orientation = getOrientation(height, width);
39+
export let screenWidth = width;
40+
export let screenHeight = height;
41+
export let isSmallScreen = screenWidth <= 340;
42+
export let isShortScreen = screenHeight <= 600;
43+
44+
export function getSafeAreaInsets() {
45+
return (orientation === orientation.LANDSCAPE) ?
2346
{left: 44, right: 44, bottom: 24, top: 0} :
2447
{left: 0, right: 0, bottom: 34, top: 44};
2548
}
2649

27-
// override guesstimate height with the actual height from StatusBarManager
28-
if (isIOS) {
29-
StatusBarManager.getHeight(data => (statusBarHeight = data.height));
50+
/* Devices */
51+
export const isIphoneX = isIOS && !Platform.isPad && !Platform.isTVOS && (screenHeight >= 812 || screenWidth >= 812);
52+
53+
/* Orientation */
54+
function getOrientation(height, width) {
55+
return width < height ? orientations.PORTRAIT : orientations.LANDSCAPE;
56+
}
57+
58+
function updateConstants() {
59+
const {height, width} = Dimensions.get(dimensionsScope.WINDOW);
60+
orientation = getOrientation(height, width);
61+
screenWidth = width;
62+
screenHeight = height;
63+
isSmallScreen = screenWidth <= 340;
64+
isShortScreen = screenHeight <= 600;
65+
66+
setStatusBarHeight();
67+
}
68+
69+
Dimensions.addEventListener('change', updateConstants);
70+
71+
export function addDimensionsEventListener(callback) {
72+
Dimensions.addEventListener('change', callback);
73+
}
74+
75+
export function removeDimensionsEventListener(callback) {
76+
Dimensions.removeEventListener('change', callback);
3077
}

0 commit comments

Comments
 (0)