home.js
8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
* Created by Cassie on 2018/03/06
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
Animated,
Modal
} from 'react-native';
import ScrollableTabView, { DefaultTabBar } from 'react-native-scrollable-tab-view';
import {width,height,zoomW,zoomH} from '../utils/getSize';
import {getHeaderHeight,getHeaderPadding,getFooterBottom} from "../utils/utils";
import HomeList from './homeList'
const back = require('../img/back.png');
const search = require('../img/search.png');
const more = require('../img/more.png');
export default class Home extends Component {
static navigationOptions = ({ navigation, screenProps }) => ({
header:null
});
constructor(props) {
super(props);
this.state = {
homeList:[
{isTop:true,title:'怎么看金蝶投资「纷享销客」5000万美元?',cover:true,video:true,content:'双方都否认了外界“收购”的传言,只是强调,区别于之前的财务投资,金蝶这一轮属于战略投资,“纷享...'},
{title:'区块链应用 | 微软、超级账本、联合国加入区块链身份项目',video:true,content:'双方都否认了外界“收购”的传言,只是强调,区别于之前的财务投资,金蝶这一轮属于战略投资,“纷享...'},
{title:'区块链应用 | 微软、超级账本、联合国加入区块链身份项目联合国加入区块链身份项目联合国加入区块链身份项目联合国加入区块链身份项目联合国加入区块链身份项目',content:'本组件继承自PureComponent而非通常的Component,这意味着如果其props在浅比较中是相等的,则不会重新渲染。所以请先检查你的renderItem函数所依赖的props数据(包括data属性以及可能用到的父组件的state),如果是一个引用类型(Object或者数组都是引用类型),则需要先修改其引用地址(比如先复制到一个新的Object或者数组中),然后再修改其值,否则界面很可能不会刷新。'}
],
newList:[
{isTop:true,title:'怎么看金蝶投资「纷享销客」5000万美元?',cover:true,video:true,content:'双方都否认了外界“收购”的传言,只是强调,区别于之前的财务投资,金蝶这一轮属于战略投资,“纷享...'},
{title:'区块链应用 | 微软、超级账本、联合国加入区块链身份项目',video:true,content:'双方都否认了外界“收购”的传言,只是强调,区别于之前的财务投资,金蝶这一轮属于战略投资,“纷享...'}
],
hotList:[
{isTop:true,title:'怎么看金蝶投资「纷享销客」5000万美元?',cover:true,video:true,content:'双方都否认了外界“收购”的传言,只是强调,区别于之前的财务投资,金蝶这一轮属于战略投资,“纷享...'},
{title:'区块链应用 | 微软、超级账本、联合国加入区块链身份项目联合国加入区块链身份项目联合国加入区块链身份项目联合国加入区块链身份项目联合国加入区块链身份项目',content:'本组件继承自PureComponent而非通常的Component,这意味着如果其props在浅比较中是相等的,则不会重新渲染。所以请先检查你的renderItem函数所依赖的props数据(包括data属性以及可能用到的父组件的state),如果是一个引用类型(Object或者数组都是引用类型),则需要先修改其引用地址(比如先复制到一个新的Object或者数组中),然后再修改其值,否则界面很可能不会刷新。'}
],
right:new Animated.Value(-(228/zoomW)),
showModal:false
};
}
/*右侧菜单栏显示*/
showRight(){
this.setState({
showModal:true
});
Animated.timing(
this.state.right,
{toValue:0}
).start();
}
/*右侧菜单栏关闭*/
closeRight(){
this.setState({
showModal:false,
right:new Animated.Value(-(228/zoomW)),
});
}
render() {
return (
<View style={styles.background}>
<View style={styles.topBar}>
<TouchableOpacity style={styles.leftIcon}>
<Image source={back} style={styles.backIcon} resizeMode="contain" />
<Text style={{color:'#fff',fontSize:16}}>犀牛</Text>
</TouchableOpacity>
<View style={styles.title}>
<Text style={{fontSize:18,color:'#fff',fontWeight:'600'}}>放牛娃</Text>
</View>
<View style={styles.rightTop}>
<TouchableOpacity style={styles.rightIcon}>
<Image source={search} style={styles.searchIcon} resizeMode="contain" />
</TouchableOpacity>
<TouchableOpacity style={styles.rightIcon} onPress={() => this.showRight()}>
<Image source={more} style={styles.moreIcon} resizeMode="contain" />
</TouchableOpacity>
</View>
</View>
<ScrollableTabView renderTabBar={() => <DefaultTabBar style={styles.tabStyle}/>}
tabBarUnderlineStyle={styles.tabBarLine}
tabBarActiveTextColor="#fff"
tabBarInactiveTextColor="#fff"
>
<HomeList tabLabel='首页' homeList={this.state.homeList} />
<HomeList tabLabel='最新' newList={this.state.newList} />
<HomeList tabLabel='最热' hotList={this.state.hotList} />
</ScrollableTabView>
<Modal animationType={'none'} transparent={true} visible={this.state.showModal} onRequestClose={() => {}}>
<View style={styles.modalBg}>
<TouchableOpacity style={{flex:1}} onPress={() => this.closeRight()}>
<Animated.View style={[styles.rightMenu,{right:this.state.right}]}>
</Animated.View>
</TouchableOpacity>
</View>
</Modal>
</View>
);
}
}
const styles = StyleSheet.create({
topBar:{
paddingTop:getHeaderPadding(),
height:getHeaderHeight(),
backgroundColor:'#1c1c20',
display:'flex',
flexDirection:'row'
},
leftIcon:{
flex:1,
height:'100%',
display:'flex',
flexDirection:'row',
alignItems:'center'
},
title:{
flex:2.5,
height:'100%',
display:'flex',
justifyContent:'center',
alignItems:'center'
},
backIcon:{
width:(10/zoomW),
height:(18/zoomH),
marginLeft:(10/zoomW),
marginRight:(5/zoomW)
},
rightTop:{
flex:1,
display:'flex',
flexDirection:'row',
justifyContent:'center',
alignItems:'center'
},
rightIcon:{
height:'100%',
width:(34/zoomW),
display:'flex',
justifyContent:'center',
alignItems:'flex-end'
},
searchIcon:{
width:(20/zoomW),
height:(20/zoomW)
},
moreIcon:{
width:(20/zoomW),
height:(20/zoomW)
},
background:{
width:'100%',
height:'100%',
backgroundColor:'#fff'
},
tabStyle:{
height:(34/zoomH),
backgroundColor:'#1c1c20'
},
tabBarLine:{
width:(20/zoomW),
backgroundColor:'#fff',
height:3,
borderRadius:8,
left:'16.66%',
marginLeft:-(10/zoomW)
},
modalBg:{
width:'100%',
height:'100%',
backgroundColor:'rgba(0,0,0,.5)'
},
rightMenu:{
width:(228/zoomW),
height:height,
display:'flex',
flexDirection:'row',
backgroundColor:'#fff',
position:'absolute',
right:0
}
});