知识点GET
- Ant design组件安装
- 搜索栏SearchBar
- 宫格Grid的使用
- Hook简介
1.ant design rn 官网https://rn.mobile.ant.design/components/grid-cn/
2.Hook 简介 https://react.docschina.org/docs/hooks-intro.html
创建项目并安装ant design组件可以参考我之前写的文章
https://blog.csdn.net/lxyoucan/article/details/108334465
所需数据[
{
icon: ,
text: 'a迎新页面',
},
{
icon: ,
text: 'a学生迎新',
},
{
icon: ,
text: 'a管理后台',
},
{
icon: ,
text: 'a我的快递',
},
{
icon: ,
text: 'a医疗健康',
},
{
icon: ,
text: 'a记账本',
},
{
icon: ,
text: 'a发票管家',
},
{
icon: ,
text: 'a车主服务',
},
{
icon: ,
text: 'a交通出行',
},
{
icon: ,
text: 'a体育服务',
},
{
icon: ,
text: 'a安全备忘',
},
{
icon: ,
text: 'a健康码',
url: 'http://www.hao123.com',
},
{
icon: ,
text: 'b迎新页面',
},
{
icon: ,
text: 'b学生迎新',
},
{
icon: ,
text: 'b管理后台',
},
{
icon: ,
text: 'b我的快递',
},
{
icon: ,
text: 'b医疗健康',
},
{
icon: ,
text: 'b记账本',
},
{
icon: ,
text: 'b发票管家',
},
{
icon: ,
text: 'b车主服务',
},
{
icon: ,
text: 'b交通出行',
},
{
icon: ,
text: 'b体育服务',
},
{
icon: ,
text: 'b安全备忘',
},
{
icon: ,
text: 'b健康码',
url: 'http://www.hao123.com',
},{
icon: ,
text: '1迎新页面',
},
{
icon: ,
text: '1学生迎新',
},
{
icon: ,
text: '1管理后台',
},
{
icon: ,
text: '1我的快递',
},
{
icon: ,
text: '2医疗健康',
},
{
icon: ,
text: '2记账本',
},
{
icon: ,
text: '2发票管家',
},
{
icon: ,
text: '2车主服务',
},
{
icon: ,
text: '2交通出行',
},
{
icon: ,
text: '2体育服务',
},
{
icon: ,
text: '2安全备忘',
},
{
icon: ,
text: '2健康码',
url: 'http://www.hao123.com',
},
]
完整代码
/* eslint-disable prettier/prettier */
import React,{useState,useEffect} from 'react';
import {ScrollView, Text, View, Alert, SafeAreaView, StyleSheet} from 'react-native';
import {Grid, Icon, SearchBar} from '@ant-design/react-native';
const data1 = [
{
icon: ,
text: 'a迎新页面',
},
{
icon: ,
text: 'a学生迎新',
},
{
icon: ,
text: 'a管理后台',
},
{
icon: ,
text: 'a我的快递',
},
{
icon: ,
text: 'a医疗健康',
},
{
icon: ,
text: 'a记账本',
},
{
icon: ,
text: 'a发票管家',
},
{
icon: ,
text: 'a车主服务',
},
{
icon: ,
text: 'a交通出行',
},
{
icon: ,
text: 'a体育服务',
},
{
icon: ,
text: 'a安全备忘',
},
{
icon: ,
text: 'a健康码',
url: 'http://www.hao123.com',
},
{
icon: ,
text: 'b迎新页面',
},
{
icon: ,
text: 'b学生迎新',
},
{
icon: ,
text: 'b管理后台',
},
{
icon: ,
text: 'b我的快递',
},
{
icon: ,
text: 'b医疗健康',
},
{
icon: ,
text: 'b记账本',
},
{
icon: ,
text: 'b发票管家',
},
{
icon: ,
text: 'b车主服务',
},
{
icon: ,
text: 'b交通出行',
},
{
icon: ,
text: 'b体育服务',
},
{
icon: ,
text: 'b安全备忘',
},
{
icon: ,
text: 'b健康码',
url: 'http://www.hao123.com',
}, {
icon: ,
text: '1迎新页面',
},
{
icon: ,
text: '1学生迎新',
},
{
icon: ,
text: '1管理后台',
},
{
icon: ,
text: '1我的快递',
},
{
icon: ,
text: '2医疗健康',
},
{
icon: ,
text: '2记账本',
},
{
icon: ,
text: '2发票管家',
},
{
icon: ,
text: '2车主服务',
},
{
icon: ,
text: '2交通出行',
},
{
icon: ,
text: '2体育服务',
},
{
icon: ,
text: '2安全备忘',
},
{
icon: ,
text: '2健康码',
url: 'http://www.hao123.com',
},
];
const AntSearchDemo = () => {
const [keyword,setKeyword] = useState('健康');
const [data,setData] = useState(data1);
useEffect(() => {
console.log('keyword:'+keyword);
let newData = [];
data1.map((item) => {
if (item.text.indexOf(keyword) >= 0) {
newData.push(item);
}
},
);
setData(newData);
},[keyword]);
const onChange = value => {
setKeyword(value);
};
const clear = () => {
setKeyword('');
};
return (
Alert.alert(value)}
showCancelButton
/>
关键字:{keyword}
alert(index)}
/>
);
};
export default AntSearchDemo;
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
视频教程
https://www.bilibili.com/video/bv1Zt4y1i7rx