Skip to content

Commit cdfb393

Browse files
committed
use asBaseComponent in TouchableOpacity
1 parent 9d46471 commit cdfb393

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/commons/baseComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function baseComponent(usePure) {
2828
};
2929
}
3030

31+
// TODO: remove this after migrating all components to use asBaseComponent HOC
3132
UNSAFE_componentWillReceiveProps(nextProps) {
3233
this.updateModifiers(this.props, nextProps);
3334
}

src/components/touchableOpacity/index.js

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

77
/**
88
* @description: A wrapper for TouchableOpacity component. Support onPress, throttling and activeBackgroundColor
@@ -12,7 +12,7 @@ import {PureBaseComponent} 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 PureBaseComponent {
15+
class TouchableOpacity extends PureComponent {
1616
static displayName = 'TouchableOpacity';
1717

1818
static propTypes = {
@@ -37,7 +37,7 @@ export default class TouchableOpacity extends PureBaseComponent {
3737
constructor(props) {
3838
super(props);
3939

40-
const {throttleTime, throttleOptions} = this.getThemeProps();
40+
const {throttleTime, throttleOptions} = this.props;
4141

4242
this.onPress = _.throttle(this.onPress.bind(this), throttleTime, throttleOptions);
4343
this.onPressIn = this.onPressIn.bind(this);
@@ -72,10 +72,8 @@ export default class TouchableOpacity extends PureBaseComponent {
7272
}
7373

7474
get backgroundColorStyle() {
75-
const {backgroundColor: modifiersBackgroundColor} = this.state;
76-
const {backgroundColor: propsBackgroundColor} = this.getThemeProps();
77-
78-
const backgroundColor = propsBackgroundColor || modifiersBackgroundColor;
75+
const {backgroundColor: propsBackgroundColor, modifiers} = this.props;
76+
const backgroundColor = propsBackgroundColor || modifiers.backgroundColor;
7977

8078
if (backgroundColor) {
8179
return {backgroundColor};
@@ -92,8 +90,8 @@ export default class TouchableOpacity extends PureBaseComponent {
9290
}
9391

9492
render() {
95-
const {borderRadius, paddings, margins, alignments, flexStyle} = this.state;
96-
const {style, ...others} = this.getThemeProps();
93+
const {style, modifiers, ...others} = this.props;
94+
const {borderRadius, paddings, margins, alignments, flexStyle} = modifiers;
9795

9896
return (
9997
<RNTouchableOpacity
@@ -121,3 +119,5 @@ export default class TouchableOpacity extends PureBaseComponent {
121119
_.invoke(this.props, 'onPress', this.props);
122120
}
123121
}
122+
123+
export default asBaseComponent(forwardRef(TouchableOpacity));

0 commit comments

Comments
 (0)