react-native - 出现搜索栏,但我无法输入文本
问题描述
我尝试使用反应原生元素创建一个搜索栏。当我运行代码时,出现了一个搜索栏,但它不允许我在其中输入文本。事实上,搜索栏甚至没有占据模拟器的顶部。它就像一个小按钮的大小。它看起来像一个图标或静止图像,不允许我输入文本。这曾经发生在任何人身上吗?下面是我写的代码。有人知道可能是什么问题吗?我安装了 RN 元素并链接了它。我什至只是为了它而安装了 NPM,但什么也没发生。任何帮助或线索将不胜感激。这是我要创建的搜索栏的链接: https ://react-native-training.github.io/react-native-elements/docs/searchbar.html#docsNav
import { SearchBar } from 'react-native-elements';
export default SearchBar extends React.Component {
constructor(props) {
super(props);
this.state = {
search: ""
};
updateSearch = search => {
this.setState({ search });
};
}
render(){
return(
<SearchBar
containerStyle={{
backgroundColor: "white",
borderBottomWidth: 1,
borderRadius: 1 1
}}
inputStyle={{ backgroundColor: "white" }}
placeholder="Type Here..."
placeholderTextColor={ "White" }
onChangeText={this.updateSearch}
value={search}
/>
)
}
}
解决方案
您需要使用在构造函数中调用设置的值this.state.search
推荐阅读
- c# - 在 Roslyn Binder 阶段会发生什么?
- python - 如何创建只有用户可以看到而不是管理员可以看到的输入字段?
- c++ - 为什么当它是 lambda 时我需要传递一个比较器来构造一个 priority_queue,而不是当它是 std::greater 时?
- ios - 如何动态排列图像
- tvos - TVML / tvOS 检测滚动结束
- php - 如何检查值是否在关联数组中?
- xml - 如何使用 XSLT 在 XML 中打印节符号 ( § )?
- php - 数据表上的总和页脚
- javascript - 如何以编程方式在 mapbox-gl-draw 中链接绘图点
- sonarqube - Jacoco 的 Sonarqube 代码覆盖率指标