[英]Replace search icon in react-native-paper searchbar with icons from MaterialCommunityIcons
I want to change the search icon in the searchbar of react-native-paper with the barcode-scan icon. 我想更改搜索图标搜索栏反应原生纸与条形码扫描图标。
The native-paper uses react-native-vector-icons for icons and barcode-scan available in MaterialCommunityIcons 本机纸使用react-native-vector-icons进行图标处理并在MaterialCommunityIcons中使用条形码扫描
Here is the code that I tried which gives a blank instead of an icon 这是我尝试的代码,该代码给出了空白而不是图标
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}/>}
/>
Is this the right way or am I missing something? 这是正确的方法还是我错过了什么?
您必须使用回调来传递图标prop中的组件
icon={() => <MaterialCommunityIcons name="barcode-scan" size={30}/>}
Just adding '()=>' in icon wiil be suffice 只需在图标中添加'()=>'就足够了
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}/>} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.