Skip to content

Commit

Permalink
Refactoring and improving TouchableEffect.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasjunior committed Jul 23, 2017
1 parent 981e958 commit 392b37f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-simple-dialogs",
"version": "0.2.2",
"version": "0.2.3",
"description": "Cross-platform simple dialogs for React Native based on the Modal component. ⚛",
"private": false,
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
*/

import React, { Component } from 'react'
import PropTypes from 'prop-types';
import {
Modal,
View,
TouchableWithoutFeedback,
Text,
Platform
} from 'react-native'
const { OS } = Platform;

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

class Dialog extends Component {

Expand Down
32 changes: 9 additions & 23 deletions src/TouchableEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,33 @@ import {
TouchableNativeFeedback,
View
} from 'react-native'
import PropTypes from 'prop-types';
const { OS } = Platform;

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

class TouchableEffect extends Component {

render() {
const { onPress, children, style, background, delayPressIn } = this.props;

let touchable;

if (OS === 'android') {
touchable = <TouchableNativeFeedback
style={style}
onPress={onPress}
delayPressIn={delayPressIn}
background={background} >
{children}
</TouchableNativeFeedback>
touchable = <TouchableNativeFeedback {...this.props} />
} else {
touchable = <TouchableOpacity
style={style}
delayPressIn={delayPressIn}
onPress={onPress} >
{children}
</TouchableOpacity>
touchable = <TouchableOpacity {...this.props} />
}

return touchable;
}
}

TouchableEffect.propTypes = {
onPress: TouchableOpacity.propTypes.onPress.isRequired,
style: View.propTypes.style,
delayPressIn: TouchableOpacity.propTypes.delayPressIn,
background: OS === 'android' ? TouchableNativeFeedback.propTypes.background : PropTypes.any,
if (OS === 'android') {
TouchableEffect.propTypes = { ...TouchableNativeFeedback.propTypes };
} else {
TouchableEffect.propTypes = { ...TouchableOpacity.propTypes };
}

TouchableEffect.defaultProps = {
background: OS === 'android' ? TouchableNativeFeedback.SelectableBackground() : null
background: OS === 'android' ? TouchableNativeFeedback.SelectableBackground() : undefined
};

export default TouchableEffect

0 comments on commit 392b37f

Please sign in to comment.