/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
Image,
FlatList,
TouchableOpacity,
ImageBackground,
Button,
ViewPagerAndroid,
DeviceEventEmitter
} from "react-native";
import Swiper from "react-native-swiper";
import AndroidUtil from "../../util/AndroidUtil";
import BasePage from "../BasePage";
import Header from "./Header";
const instructions = Platform.select({
ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
android:
"Double tap R on your keyboard to reload,\n" +
"Shake or press menu button for dev menu"
});
type Props = {};
export default class MainPage extends BasePage {
render() {
return (
this.headerorfooterComponent()}
keyExtractor={(item, index) => item.key.toString()}
renderItem={({ item }) => {
return this.loadFlatItem(item);
}}
data={[
{
//轮播
key: 111,
typea: 1,
text: "第一种类型"
},
{
//标题类型
key: 333,
typea: 0,
title: "全部课程全部课程全部课程全部课程全部课程全部课程"
},
{
//只有一个标题下面两个图片
key: 222,
typea: 2,
item: {
item_type: 1,
title: "课程表:第一周",
icon_item: [
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第一张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第二张图片文字"
}
]
}
},
{
//一个标题,大长图
key: 444,
typea: 3,
title: "五月主题:五一启程,去看看不同世界",
text: "每天30分钟,玩学两不误",
icon_item: [
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第一张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第二张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第三张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第四张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第五张图片文字"
}
]
},
{
key: 555,
typea: 4,
title: "热门课程",
text: "text",
mask: false,
icon_item: [
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第一张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第二张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第三张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第四张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第五张图片文字"
}
]
},
{
//标题类型
key: 0,
typea: 0,
title: "全部课程"
},
{
//一个标题,icon下有文字
key: 666,
typea: 4,
title: "测试text为空的时候",
text: "",
mask: false,
icon_item: [
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第一张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第二张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第三张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第四张图片文字"
},
{
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第五张图片文字"
}
]
},
{
key: 777,
typea: 4,
title: "测试观看记录",
text: "",
mask: true,
icon_item: [
{
last_time: "2小时前",
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第一张图片文字",
curriculum_name: "课件名字"
},
{
last_time: "3小时前",
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第二张图片文字",
curriculum_name: "课件名字1"
},
{
last_time: "4小时前",
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第三张图片文字",
curriculum_name: "课件名字2"
},
{
last_time: "1天前",
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第四张图片文字",
curriculum_name: "课件名字3"
},
{
last_time: "2天前",
icon:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg",
name: "第五张图片文字",
curriculum_name: "课件名字4"
}
]
}
]}
/>
);
}
headerorfooterComponent() {
return (
this.toNextPage("MainActivity")}
/>
);
}
loadFlatItem(data) {
switch (data.typea) {
case 0:
return (
{data.title}
);
break;
case 1:
return (
this.toNextPage("MainActivity")}
>
);
break;
case 2:
let arr = [];
let index = 0;
for (let item of data.item.icon_item) {
arr.push(
{
alert(item.name);
}}
key={index}
activeOpacity={1}
>
);
if (index < data.item.icon_item.length - 1) {
arr.push(
);
}
index++;
}
return (
{data.item.title}
{arr}
);
break;
case 3:
return (
{data.title}
{text_z}
(
)}
showsHorizontalScrollIndicator={false}
keyExtractor={(item, index) => item.name.toString()}
data={data.icon_item}
horizontal={true}
renderItem={({ item }) => {
return (
{
alert(item.name);
}}
activeOpacity={1}
>
);
}}
/>
);
break;
case 4:
let text_z = [];
let zhezhao = [];
let view_height = 190;
//判断是否需要text
if (data.text != "") {
view_height = 217;
text_z.push(
{data.text}
);
}
return (
{data.title}
{text_z}
(
)}
showsHorizontalScrollIndicator={false}
keyExtractor={(item, index) => item.name.toString()}
data={data.icon_item}
horizontal={true}
renderItem={({ item }) => {
//判断是否需要遮盖层(观看记录)
if (data.mask) {
zhezhao = [];
zhezhao.push(
{item.last_time + ":"}
{item.curriculum_name}
);
}
return (
{
alert(item.name);
}}
activeOpacity={1}
>
{zhezhao}
{item.name}
);
}}
/>
);
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
}
}
}
const styles = StyleSheet.create({
title_text: {
justifyContent: "center",
alignItems: "center",
color: "red",
fontSize: 30,
textAlign: "center",
marginTop: 30,
marginBottom: 50
}
});