No Description

SmallVideoViewController.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. * Created by zack on 2018/4/19.
  3. */
  4. import {
  5. View,
  6. Text,
  7. Image,
  8. StyleSheet,
  9. TouchableHighlight,
  10. ImageBackground
  11. } from 'react-native'
  12. import React, { Component } from 'react'
  13. import ScreenDimensions from '../../../utils/ScreenDimensions'
  14. import ScreenDimensionsClientHeight from '../../../utils/ScreenDimensions'
  15. import NavigationBarHeight from '../../../utils/NavigationBarHeight'
  16. import TabBarHeight from '../../../utils/TabBarHeight'
  17. import RefreshInfiniteListView from '../../../utils/RefreshInfiniteListView'
  18. //ScreenDimensions.clientHeight
  19. const clientHeight = ScreenDimensions.clientHeight;
  20. export default class SmallVideoViewController extends Component {
  21. constructor(props) {
  22. super(props)
  23. this.state = {
  24. }
  25. }
  26. componentDidMount() {
  27. var data = [];
  28. let titles = ["如何在5分钟内记住100个单词", "Moira带你边走边学", "金融职员必备英语", "美式英语与英式英语的区别"];
  29. let users = ['Micheal', 'Moira', 'Nahila', 'Ahmed'];
  30. let watchs = ['241', '2万', '3574', '4.6万'];
  31. for (var i = 1; i < 5; i++) {
  32. data.push({
  33. key: i - 1,
  34. ima: "img_" + i,
  35. title: titles[i - 1],
  36. user: users[i - 1],
  37. watch: watchs[i - 1]
  38. });
  39. }
  40. this.list.setData(data)
  41. }
  42. render() {
  43. return (
  44. <View style={styles.View}>
  45. <RefreshInfiniteListView
  46. style={styles.flatListStyle}
  47. numColumns={2}
  48. onScroll={()=>{
  49. }}
  50. ref={this.listRef.bind(this)}
  51. renderItem={this.renderRow.bind(this)}
  52. onRefresh={this.onRefresh.bind(this)}
  53. onEndReached={this.onInfinite.bind(this)}>
  54. </RefreshInfiniteListView>
  55. </View>
  56. );
  57. }
  58. renderRow(item) {
  59. let uer = require('../../../resources/images/TabBar/Community/SmallVideo/img_4.png');
  60. let uerIcon = require('../../../resources/images/TabBar/Community/SmallVideo/user_3.png');
  61. let addIcon = require('../../../resources/images/TabBar/Community/SmallVideo/follow.png');
  62. return (
  63. <TouchableHighlight
  64. underlayColor={"white"}
  65. onPress={this.onPress.bind(this)}>
  66. <View style={item.index / 2 == 0 ? styles.cellLeftStyle : styles.cellRightStyle}>
  67. <ImageBackground source={uer} style={styles.ImageView}>
  68. <ImageBackground source={require('../../../resources/images/TabBar/Community/SmallVideo/bg.png')} style={styles.bottomImage} >
  69. <Text style={styles.titleStyle}>{item.title}</Text>
  70. <View style={styles.bottomStyle}>
  71. <View style={styles.bottomLeftStyle}>
  72. <View style={styles.headImage}>
  73. <Image source={uerIcon} style={styles.userIcon} />
  74. <Image source={addIcon} style={styles.followStyle} />
  75. </View>
  76. <Text style={styles.nameStyle}>{item.user}</Text>
  77. </View>
  78. <View style={styles.bottomRightStyle}>
  79. <Text style={styles.numberStyle}>{item.watch}</Text>
  80. <Image source={require('../../../resources/images/TabBar/Community/SmallVideo/view.png')} style={styles.watchStyle} />
  81. </View>
  82. </View>
  83. </ImageBackground>
  84. </ImageBackground>
  85. </View>
  86. </TouchableHighlight>
  87. )
  88. }
  89. listRef(node) {
  90. this.list = node;
  91. }
  92. onRefresh() {
  93. //下拉刷新
  94. this.list.setRefreshing(true);
  95. this.requestData(false)
  96. }
  97. onInfinite() {
  98. //上拉加载
  99. this.requestData(true)
  100. }
  101. requestData(isLoadMore) {
  102. this.list.setRefreshing(false);
  103. if (isLoadMore) {
  104. console.log("上啦中=======")
  105. } else {
  106. console.log("下啦中=======")
  107. }
  108. }
  109. onPress() {
  110. // this.hideTabBar()
  111. this.props.callSmallback();
  112. }
  113. }
  114. const styles = StyleSheet.create({
  115. flatListStyle: {
  116. width: ScreenDimensions.width,
  117. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height,
  118. },
  119. View: {
  120. width: ScreenDimensions.width,
  121. height: ScreenDimensions.height,
  122. // marginTop: NavigationBarHeight.height ,
  123. },
  124. rowStyle: {
  125. width: ScreenDimensions.width / 2,
  126. height: 200,
  127. },
  128. ImageView: {
  129. width: ScreenDimensions.width / 2 - 3,
  130. height: clientHeight / 2 - 1,
  131. justifyContent: "flex-end"
  132. },
  133. cellLeftStyle: {
  134. width: ScreenDimensions.width / 2,
  135. paddingLeft: 2,
  136. paddingRight: 1,
  137. marginTop: 1,
  138. height: clientHeight / 2,
  139. },
  140. cellRightStyle: {
  141. width: ScreenDimensions.width / 2,
  142. paddingLeft: 1,
  143. paddingRight: 2,
  144. marginTop: 1,
  145. height: clientHeight / 2,
  146. },
  147. bottomImage: {
  148. width: "100%",
  149. height: 171 / 512 * clientHeight / 2,
  150. marginBottom: 0,
  151. },
  152. titleStyle: {
  153. marginHorizontal: 11,
  154. color: "#fff",
  155. fontSize: 15,
  156. flex: 1
  157. },
  158. bottomStyle: {
  159. justifyContent: "space-between",
  160. flexDirection: "row",
  161. flex: 1.5,
  162. marginBottom: 10
  163. },
  164. bottomLeftStyle: {
  165. flex: 1,
  166. alignItems: "flex-end",
  167. flexDirection: "row",
  168. },
  169. nameStyle: {
  170. fontSize: 14,
  171. color: "#ffffff",
  172. marginLeft: 5
  173. },
  174. headImage: {
  175. flexDirection: "row"
  176. },
  177. bottomRightStyle: {
  178. flex: 1,
  179. alignItems: "flex-end",
  180. flexDirection: "row",
  181. justifyContent: "flex-end"
  182. },
  183. userIcon: {
  184. width: 40,
  185. height: 40,
  186. marginLeft: 11,
  187. },
  188. followStyle: {
  189. width: 12,
  190. height: 12,
  191. marginTop: 30,
  192. marginLeft: -15
  193. },
  194. watchStyle: {
  195. width: 17,
  196. height: 11,
  197. marginBottom: 2,
  198. marginRight: 8,
  199. marginLeft: 2
  200. },
  201. numberStyle: {
  202. fontSize: 14,
  203. color: "#ffffff"
  204. }
  205. })