Skip to content

Commit 392b37f

Browse files
committed
Refactoring and improving TouchableEffect.
1 parent 981e958 commit 392b37f

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-simple-dialogs",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Cross-platform simple dialogs for React Native based on the Modal component. ⚛",
55
"private": false,
66
"repository": {

src/Dialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
*/
2424

2525
import React, { Component } from 'react'
26-
import PropTypes from 'prop-types';
2726
import {
2827
Modal,
2928
View,
3029
TouchableWithoutFeedback,
3130
Text,
3231
Platform
3332
} from 'react-native'
33+
const { OS } = Platform;
3434

35-
const OS = Platform.OS;
35+
import PropTypes from 'prop-types';
3636

3737
class Dialog extends Component {
3838

src/TouchableEffect.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,33 @@ import {
2929
TouchableNativeFeedback,
3030
View
3131
} from 'react-native'
32-
import PropTypes from 'prop-types';
32+
const { OS } = Platform;
3333

34-
const OS = Platform.OS;
34+
import PropTypes from 'prop-types';
3535

3636
class TouchableEffect extends Component {
3737

3838
render() {
39-
const { onPress, children, style, background, delayPressIn } = this.props;
40-
4139
let touchable;
4240

4341
if (OS === 'android') {
44-
touchable = <TouchableNativeFeedback
45-
style={style}
46-
onPress={onPress}
47-
delayPressIn={delayPressIn}
48-
background={background} >
49-
{children}
50-
</TouchableNativeFeedback>
42+
touchable = <TouchableNativeFeedback {...this.props} />
5143
} else {
52-
touchable = <TouchableOpacity
53-
style={style}
54-
delayPressIn={delayPressIn}
55-
onPress={onPress} >
56-
{children}
57-
</TouchableOpacity>
44+
touchable = <TouchableOpacity {...this.props} />
5845
}
5946

6047
return touchable;
6148
}
6249
}
6350

64-
TouchableEffect.propTypes = {
65-
onPress: TouchableOpacity.propTypes.onPress.isRequired,
66-
style: View.propTypes.style,
67-
delayPressIn: TouchableOpacity.propTypes.delayPressIn,
68-
background: OS === 'android' ? TouchableNativeFeedback.propTypes.background : PropTypes.any,
51+
if (OS === 'android') {
52+
TouchableEffect.propTypes = { ...TouchableNativeFeedback.propTypes };
53+
} else {
54+
TouchableEffect.propTypes = { ...TouchableOpacity.propTypes };
6955
}
7056

7157
TouchableEffect.defaultProps = {
72-
background: OS === 'android' ? TouchableNativeFeedback.SelectableBackground() : null
58+
background: OS === 'android' ? TouchableNativeFeedback.SelectableBackground() : undefined
7359
};
7460

7561
export default TouchableEffect

0 commit comments

Comments
 (0)