Skip to content

Commit

Permalink
Custom Touchable components
Browse files Browse the repository at this point in the history
  • Loading branch information
jevakallio committed Apr 23, 2016
1 parent ac7d91b commit 4443702
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Touchable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

import React from 'react-native';
import {findHandler} from './driver';
const {
View,
PropTypes
} = React;

function createTouchableClass(className) {
return React.createClass({
displayName: 'Cycle' + className,
propTypes: {
selector: PropTypes.string.isRequired,
},
setNativeProps(props) {
this._touchable.setNativeProps(props);
},
render() {
const TouchableClass = React[className];
const {selector, ...props} = this.props;
return (
<TouchableClass
ref={view => this._touchable = view}
onPress={findHandler(selector, 'press')}
onPressIn={findHandler(selector, 'pressIn')}
onPressOut={findHandler(selector, 'pressOut')}
onLongPress={findHandler(selector, 'longPress')}
>
<View {...props}>
{this.props.children}
</View>
</TouchableClass>
);
}
});
}

export default {
TouchableOpacity: createTouchableClass('TouchableOpacity'),
TouchableWithoutFeedback: createTouchableClass('TouchableWithoutFeedback'),
TouchableHighlight: createTouchableClass('TouchableHighlight'),
TouchableNativeFeedback: createTouchableClass('TouchableNativeFeedback')
};

0 comments on commit 4443702

Please sign in to comment.