首页 > 解决方案 > 出现搜索栏,但我无法输入文本

问题描述

我尝试使用反应原生元素创建一个搜索栏。当我运行代码时,出现了一个搜索栏,但它不允许我在其中输入文本。事实上,搜索栏甚至没有占据模拟器的顶部。它就像一个小按钮的大小。它看起来像一个图标或静止图像,不允许我输入文本。这曾经发生在任何人身上吗?下面是我写的代码。有人知道可能是什么问题吗?我安装了 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}
              />
             )
            }
          }

标签: react-nativeecmascript-6uisearchbar

解决方案


您需要使用在构造函数中调用设置的值this.state.search


推荐阅读