我有以下代码:
import React, {Component} from 'react';
import {Platform, ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View,} from 'react-native';
import {Alert} from "react-native-web";
export default class HomeScreen extends Component {
state = {text: ''};
_onPressSearch() {
Alert.alert("Button pressed!")
}
render() {
return (<View style={styles.container}>
<ScrollView style={styles.scrollViewContainer} contentContainerStyle={styles.contentContainer}>
<View style={styles.searchContainer}>
<TextInput placeHolder="Type something!" onChangeText={(text) => this.setState({text})}
value={this.state.text}/>
</View>
<TouchableOpacity
onPress={this._onPressSearch}>
<View>
<Text>Search</Text>
</View>
</TouchableOpacity>
<View style={styles.listContainer}>
<Text>{this.state.text}</Text>
</View>
</ScrollView>
</View>
我的问题是,当我点击 TouchableOpacity 时,没有任何动作发生(在我的情况下显示警报)。我试图将 ToachableOpacity 和 View 组合更改为通常的按钮,但没有再发生任何事情。那么,有什么问题,我该如何解决呢?