1
1
import React , { PureComponent } from 'react' ;
2
- import { TouchableOpacity as RNTouchableOpacity } from 'react-native' ;
3
- import PropTypes from 'prop-types' ;
2
+ import { TouchableOpacity as RNTouchableOpacity , TouchableOpacityProps } from 'react-native' ;
4
3
import _ from 'lodash' ;
5
- import { asBaseComponent , forwardRef } from '../../commons' ;
4
+ import { asBaseComponent , forwardRef , BaseComponentInjectedProps , ForwardRefInjectedProps } from '../../commons/new' ;
5
+ // @ts -ignore
6
6
import Incubator from '../../incubator' ;
7
7
8
+ type IProps = TouchableOpacityProps & {
9
+ /**
10
+ * background color for TouchableOpacity
11
+ */
12
+ backgroundColor ?: string ;
13
+ /**
14
+ * throttle time in MS for onPress callback
15
+ */
16
+ throttleTime ?: number ;
17
+ /**
18
+ * throttle options {leading, trailing}
19
+ */
20
+ throttleOptions ?: { leading : boolean , trailing : boolean } ;
21
+ /**
22
+ * Apply background color on TouchableOpacity when active (press is on)
23
+ */
24
+ activeBackgroundColor ?: string ;
25
+ /**
26
+ * Should use a more native touchable opacity component
27
+ */
28
+ useNative ?: boolean ;
29
+ } ;
30
+
31
+ type Props = BaseComponentInjectedProps & ForwardRefInjectedProps & IProps ;
32
+
8
33
/**
9
34
* @description : A wrapper for TouchableOpacity component. Support onPress, throttling and activeBackgroundColor
10
35
* @extends : TouchableOpacity
@@ -13,33 +38,10 @@ import Incubator from '../../incubator';
13
38
* @gif : https://media.giphy.com/media/xULW8AMIgw7l31zjm8/giphy.gif
14
39
* @example : https://github.com/wix/react-native-ui-lib/blob/master/src/components/touchableOpacity/index.js
15
40
*/
16
- class TouchableOpacity extends PureComponent {
41
+ class TouchableOpacity extends PureComponent < Props , { active : boolean } > {
17
42
static displayName = 'TouchableOpacity' ;
18
43
19
- static propTypes = {
20
- /**
21
- * background color for TouchableOpacity
22
- */
23
- backgroundColor : PropTypes . string ,
24
- /**
25
- * throttle time in MS for onPress callback
26
- */
27
- throttleTime : PropTypes . number ,
28
- /**
29
- * throttle options
30
- */
31
- throttleOptions : PropTypes . shape ( { leading : PropTypes . bool , trailing : PropTypes . bool } ) ,
32
- /**
33
- * Apply background color on TouchableOpacity when active (press is on)
34
- */
35
- activeBackgroundColor : PropTypes . string ,
36
- /**
37
- * Should use a more native touchable opacity component
38
- */
39
- useNative : PropTypes . bool
40
- } ;
41
-
42
- constructor ( props ) {
44
+ constructor ( props : Props ) {
43
45
super ( props ) ;
44
46
45
47
const { throttleTime, throttleOptions} = this . props ;
@@ -50,7 +52,6 @@ class TouchableOpacity extends PureComponent {
50
52
}
51
53
52
54
state = {
53
- ...this . state ,
54
55
active : false
55
56
} ;
56
57
@@ -62,14 +63,14 @@ class TouchableOpacity extends PureComponent {
62
63
} ;
63
64
}
64
65
65
- onPressIn ( ...args ) {
66
+ onPressIn ( ...args : any ) {
66
67
this . setState ( {
67
68
active : true
68
69
} ) ;
69
70
_ . invoke ( this . props , 'onPressIn' , ...args ) ;
70
71
}
71
72
72
- onPressOut ( ...args ) {
73
+ onPressOut ( ...args : any ) {
73
74
this . setState ( {
74
75
active : false
75
76
} ) ;
@@ -103,6 +104,7 @@ class TouchableOpacity extends PureComponent {
103
104
}
104
105
105
106
return (
107
+ // @ts -ignore
106
108
< RNTouchableOpacity
107
109
{ ...this . getAccessibilityInfo ( ) }
108
110
{ ...others }
@@ -129,4 +131,4 @@ class TouchableOpacity extends PureComponent {
129
131
}
130
132
}
131
133
132
- export default asBaseComponent ( forwardRef ( TouchableOpacity ) ) ;
134
+ export default asBaseComponent < IProps > ( forwardRef ( TouchableOpacity ) ) ;
0 commit comments