mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-06-16 20:01:13 +08:00
Touchable component (#34)
* Initial implementation of Touchable component * Export touchable component * Fix export statement * Edit Touchable Component * Fix export statement * Update example app with usage of touchable component * Make eslint happy * Change style propType * Change Touchable name => TouchableRipple, add check on older versions of Android and change borderLess prop to borderless * Remove usage of TouchableRipple from example app
This commit is contained in:
committed by
Satyajit Sahoo
parent
deca4be4bb
commit
bd2f2a1b66
@@ -10,7 +10,7 @@ class App extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text>Open up main.js to start working on your app!</Text>
|
||||
<Text>React Native Paper will rock :D</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -19,9 +19,8 @@ class App extends React.Component {
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#fff',
|
||||
marginTop: 24,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
1
index.js
1
index.js
@@ -1,2 +1,3 @@
|
||||
// @flow
|
||||
export { default as ThemeProvider } from './src/styles/ThemeProvider';
|
||||
export { TouchableRipple } from './src/TouchableRipple';
|
||||
|
||||
46
src/TouchableRipple/TouchableRipple.android.js
Normal file
46
src/TouchableRipple/TouchableRipple.android.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// @flow
|
||||
import React, {
|
||||
Component,
|
||||
PropTypes,
|
||||
Platform,
|
||||
} from 'react';
|
||||
import {
|
||||
TouchableNativeFeedback,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
export default class TouchableRipple extends Component {
|
||||
|
||||
static propTypes = {
|
||||
children: PropTypes.element.isRequired,
|
||||
borderless: PropTypes.bool,
|
||||
onPress: PropTypes.func,
|
||||
rippleColor: PropTypes.string,
|
||||
style: View.propTypes.style,
|
||||
};
|
||||
static defaultProps = {
|
||||
borderless: false,
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
children,
|
||||
onPress,
|
||||
rippleColor,
|
||||
borderless,
|
||||
style,
|
||||
} = this.props;
|
||||
return (
|
||||
<TouchableNativeFeedback
|
||||
onPress={onPress}
|
||||
background={Platform.Version >= 21 ?
|
||||
TouchableNativeFeedback.Ripple(rippleColor, borderless) :
|
||||
TouchableNativeFeedback.SelectableBackground()}
|
||||
>
|
||||
<View style={style}>
|
||||
{children}
|
||||
</View>
|
||||
</TouchableNativeFeedback>
|
||||
);
|
||||
}
|
||||
}
|
||||
41
src/TouchableRipple/TouchableRipple.ios.js
Normal file
41
src/TouchableRipple/TouchableRipple.ios.js
Normal file
@@ -0,0 +1,41 @@
|
||||
// @flow
|
||||
import React, {
|
||||
Component,
|
||||
PropTypes,
|
||||
} from 'react';
|
||||
import {
|
||||
TouchableHighlight,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
export default class TouchableRipple extends Component {
|
||||
|
||||
static propTypes = {
|
||||
children: PropTypes.element.isRequired,
|
||||
borderless: PropTypes.bool,
|
||||
onPress: PropTypes.func,
|
||||
rippleColor: PropTypes.string,
|
||||
style: View.propTypes.style,
|
||||
};
|
||||
static defaultProps = {
|
||||
borderless: false,
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
children,
|
||||
onPress,
|
||||
rippleColor,
|
||||
style,
|
||||
} = this.props;
|
||||
return (
|
||||
<TouchableHighlight
|
||||
style={style}
|
||||
underlayColor={rippleColor}
|
||||
onPress={onPress}
|
||||
>
|
||||
{children}
|
||||
</TouchableHighlight>
|
||||
);
|
||||
}
|
||||
}
|
||||
1
src/TouchableRipple/index.js
Normal file
1
src/TouchableRipple/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { default as TouchableRipple } from './TouchableRipple';
|
||||
Reference in New Issue
Block a user