Skip to content

Commit 570229f

Browse files
emilisbethanshar
authored andcommitted
Migrate most popular components to PureComponents (#473)
* Migrate most popular components to PureComponents * Revert BaseInput
1 parent a1f8ae3 commit 570229f

File tree

8 files changed

+30
-30
lines changed

8 files changed

+30
-30
lines changed

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/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
/**

0 commit comments

Comments
 (0)