mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-28 20:34:52 +08:00
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
/**
|
|
* @flow
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { StyleSheet, View, Text, TouchableHighlight } from 'react-native';
|
|
|
|
export default class TouchableCustomStyleOverridesExample extends React.Component {
|
|
buttons = ['One', 'Two', 'Three'];
|
|
state = {};
|
|
|
|
select = selectedButton => event => {
|
|
const newState = {};
|
|
this.buttons.forEach(button => {
|
|
newState[button] = selectedButton === button;
|
|
});
|
|
this.setState(newState);
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<View style={styles.container}>
|
|
{this.buttons.map(button => {
|
|
return (
|
|
<TouchableHighlight
|
|
key={button}
|
|
onPress={this.select(button)}
|
|
style={[styles.touchable, this.state[button] && styles.blue]}
|
|
underlayColor="#1b95e020"
|
|
>
|
|
<Text style={[!this.state[button] && styles.text]}>{button}</Text>
|
|
</TouchableHighlight>
|
|
);
|
|
})}
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
blue: {
|
|
backgroundColor: '#1b95e040',
|
|
borderColor: '#1B95E0'
|
|
},
|
|
text: {
|
|
color: '#555'
|
|
},
|
|
container: {
|
|
flexDirection: 'row'
|
|
},
|
|
touchable: {
|
|
borderWidth: 3,
|
|
borderColor: '#ccc',
|
|
padding: 20,
|
|
marginVertical: 10,
|
|
marginRight: 10
|
|
}
|
|
});
|