1
- import React from 'react' ;
1
+ import React , { PureComponent } from 'react' ;
2
2
import { TouchableOpacity as RNTouchableOpacity } from 'react-native' ;
3
3
import PropTypes from 'prop-types' ;
4
4
import _ from 'lodash' ;
5
- import { PureBaseComponent } from '../../commons' ;
5
+ import { asBaseComponent , forwardRef } from '../../commons' ;
6
6
7
7
/**
8
8
* @description : A wrapper for TouchableOpacity component. Support onPress, throttling and activeBackgroundColor
@@ -12,7 +12,7 @@ import {PureBaseComponent} from '../../commons';
12
12
* @gif : https://media.giphy.com/media/xULW8AMIgw7l31zjm8/giphy.gif
13
13
* @example : https://github.com/wix/react-native-ui-lib/blob/master/src/components/touchableOpacity/index.js
14
14
*/
15
- export default class TouchableOpacity extends PureBaseComponent {
15
+ class TouchableOpacity extends PureComponent {
16
16
static displayName = 'TouchableOpacity' ;
17
17
18
18
static propTypes = {
@@ -37,7 +37,7 @@ export default class TouchableOpacity extends PureBaseComponent {
37
37
constructor ( props ) {
38
38
super ( props ) ;
39
39
40
- const { throttleTime, throttleOptions} = this . getThemeProps ( ) ;
40
+ const { throttleTime, throttleOptions} = this . props ;
41
41
42
42
this . onPress = _ . throttle ( this . onPress . bind ( this ) , throttleTime , throttleOptions ) ;
43
43
this . onPressIn = this . onPressIn . bind ( this ) ;
@@ -72,10 +72,8 @@ export default class TouchableOpacity extends PureBaseComponent {
72
72
}
73
73
74
74
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 ;
79
77
80
78
if ( backgroundColor ) {
81
79
return { backgroundColor} ;
@@ -92,8 +90,8 @@ export default class TouchableOpacity extends PureBaseComponent {
92
90
}
93
91
94
92
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 ;
97
95
98
96
return (
99
97
< RNTouchableOpacity
@@ -121,3 +119,5 @@ export default class TouchableOpacity extends PureBaseComponent {
121
119
_ . invoke ( this . props , 'onPress' , this . props ) ;
122
120
}
123
121
}
122
+
123
+ export default asBaseComponent ( forwardRef ( TouchableOpacity ) ) ;
0 commit comments