3

我想用条形码扫描图标更改 react-native-paper 搜索栏中的搜索图标
native-paper 使用react-native-vector-icons作为MaterialCommunityIcons中的图标和条形码扫描
这是我尝试过的代码,它给出了一个空白而不是一个图标

import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
<Searchbar
  placeholder="Search"
  onChangeText={query => { this.setState({ firstQuery: query }); }}
  value={firstQuery}
  icon={<MaterialCommunityIcon name="barcode-scan" size={30}/>}
/>

这是正确的方法还是我错过了什么?

在此处输入图像描述

4

2 回答 2

5

您必须使用回调在图标道具中传递组件

icon={() => <MaterialCommunityIcons name="barcode-scan" size={30}/>}
于 2019-04-05T10:16:54.227 回答
0

只需在图标中添加 '()=>' 就足够了

import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
<Searchbar
  placeholder="Search"
  onChangeText={query => { this.setState({ firstQuery: query }); }}
  value={firstQuery}
  icon={()=><MaterialCommunityIcon name="barcode-scan" size={30}/>}
/>

于 2019-04-05T10:37:45.460 回答