📅  最后修改于: 2023-12-03 14:46:56.977000             🧑  作者: Mango
React Native Touchables组件是React Native的核心组件之一,它提供了一套可触摸的组件集合,其中包括TouchableWithoutFeedback、TouchableHighlight、TouchableOpacity和TouchableNativeFeedback等组件,可以用来创建可交互的用户界面。
import React, { Component } from 'react';
import { TouchableWithoutFeedback, Text } from 'react-native';
class App extends Component {
state = {
count: 0
}
handlePress = () => {
this.setState({ count: this.state.count + 1 });
}
render() {
return (
<TouchableWithoutFeedback onPress={this.handlePress}>
<Text>
You clicked {this.state.count} times
</Text>
</TouchableWithoutFeedback>
);
}
}
export default App;
import React, { Component } from 'react';
import { TouchableOpacity, Text } from 'react-native';
class App extends Component {
state = {
count: 0
}
handlePress = () => {
this.setState({ count: this.state.count + 1 });
}
render() {
return (
<TouchableOpacity onPress={this.handlePress}>
<Text>
Click me
</Text>
</TouchableOpacity>
);
}
}
export default App;
import React, { Component } from 'react';
import { TouchableHighlight, Text } from 'react-native';
class App extends Component {
state = {
count: 0
}
handlePress = () => {
this.setState({ count: this.state.count + 1 });
}
render() {
return (
<TouchableHighlight onPress={this.handlePress}>
<Text>
Click me
</Text>
</TouchableHighlight>
);
}
}
export default App;
import React, { Component } from 'react';
import { TouchableNativeFeedback, Text, View } from 'react-native';
class App extends Component {
state = {
count: 0
}
handlePress = () => {
this.setState({ count: this.state.count + 1 });
}
render() {
return (
<TouchableNativeFeedback onPress={this.handlePress} background={TouchableNativeFeedback.Ripple('#ffffff', false)}>
<View>
<Text>
Click me
</Text>
</View>
</TouchableNativeFeedback>
);
}
}
export default App;