Advertisement
yosadade

Toast

Jan 18th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.58 KB | None | 0 0
  1. import React, { PureComponent } from 'react';
  2. import { ListItem, Thumbnail, Left, Body, Button, Footer, Icon, Text, Toast } from 'native-base'
  3. import { Image, TouchableOpacity, View, StyleSheet, ScrollView } from 'react-native'
  4. import { Avatar } from 'react-native-elements';
  5. import analytics from '@react-native-firebase/analytics';
  6.  
  7. import moment from 'moment/min/moment-with-locales'
  8. moment.locale('id')
  9.  
  10.  
  11. export default class extends PureComponent {
  12. render() {
  13. let jam = moment(this.props.item.tgl).fromNow(true)
  14. // jam = jam.replace('hours ago', 'j')
  15. if (this.props.index===0) {
  16. return(
  17. <View style={{flex: 1}}>
  18. <View style={darkStyles.tabs}>
  19. <ScrollView
  20. horizontal
  21. >
  22. <Button transparent style={darkStyles.buttonMainTabs}
  23. onPress={() => {
  24. this.props.navigation.navigate('HomeScreen')
  25. }}
  26. >
  27.  
  28.  
  29. // Toast Error
  30.  
  31. <Text style={darkStyles.textMainTabs}>Terbaru</Text>
  32. </Button>
  33. <Button transparent style={darkStyles.buttonTabs}
  34. onPress={() => {
  35. Toast.show({text: 'Menu belum tersedia.', buttonText: 'OK'})
  36. analytics().logEvent('pilih_kategori_politik')
  37. // this.props.navigation.navigate('Tab1')
  38. }}
  39. >
  40. <Text style={darkStyles.textTabs}>Politik</Text>
  41. </Button>
  42. <Button transparent style={darkStyles.buttonTabs}
  43. onPress={() => {
  44. Toast.show({text: 'Menu belum tersedia.', buttonText: 'OK'})
  45. analytics().logEvent('pilih_kategori_ekonomi')
  46. // this.props.navigation.navigate('Tab2')
  47. }}
  48. >
  49. <Text style={darkStyles.textTabs}>Ekonomi</Text>
  50. </Button>
  51. <Button transparent style={darkStyles.buttonTabs}
  52. onPress={() => {
  53. Toast.show({text: 'Menu belum tersedia.', buttonText: 'OK'})
  54. analytics().logEvent('pilih_kategori_teknologi')
  55. // this.props.navigation.navigate('Tab3')
  56. }}
  57. >
  58. <Text style={darkStyles.textTabs}>Teknologi</Text>
  59. </Button>
  60. <Button transparent style={darkStyles.buttonTabs}
  61. onPress={() => {
  62. Toast.show({text: 'Menu belum tersedia.', buttonText: 'OK'})
  63. analytics().logEvent('pilih_kategori_olahraga')
  64. // this.props.navigation.navigate('Tab4')
  65. }}
  66. >
  67. <Text style={darkStyles.textTabs}>Olahraga</Text>
  68. </Button>
  69. </ScrollView>
  70. </View>
  71. <View style={darkStyles.container}>
  72. <TouchableOpacity
  73. onPress={() => {
  74. analytics().logEvent('touch_headline')
  75. this.props.navigation.navigate('DescScreen', { item: this.props.item })
  76. }}>
  77. <Image source={{uri: this.props.item.ilustrasi}} style={darkStyles.imageHeadline} />
  78. <View style={darkStyles.backgroundHeadline}/>
  79.  
  80. <Text numberOfLines={2} style={darkStyles.judulHeadline}>{ this.props.item.judul }</Text>
  81. <Text note numberOfLines={1} style={darkStyles.sumberHeadline}>{ this.props.item.sumber }</Text>
  82. <View style={darkStyles.containerJamImpresi}>
  83. <View style={darkStyles.viewJam}>
  84. <Icon name="time" style={darkStyles.iconHeadlineJam} />
  85. <Text style={darkStyles.textHeadlineJam}>{jam}</Text>
  86. </View>
  87. <View style={darkStyles.viewImpresi}>
  88. <Icon name="eye" style={darkStyles.iconHeadlineEye} />
  89. <Text style={darkStyles.textHeadlineEye}>{this.props.item.impresi}</Text>
  90. </View>
  91. </View>
  92. </TouchableOpacity>
  93. <TouchableOpacity
  94. onPress={() => {
  95. analytics().logEvent('touch_user_settings')
  96. this.props.navigation.navigate('UserSettingScreen')
  97. }}
  98. style={darkStyles.avatar}>
  99. <Avatar
  100. rounded
  101. size={'small'}
  102. icon={{name:'person'}}
  103. activeOpacity={0.7}
  104. />
  105. </TouchableOpacity>
  106. </View>
  107. </View>
  108. )
  109. }
  110.  
  111. return (
  112. <View style={darkStyles.container}>
  113. <TouchableOpacity>
  114. <ListItem thumbnail onPress={() => {
  115. analytics().logEvent('touch_berita')
  116. this.props.navigation.navigate('DescScreen', { item: this.props.item })
  117. }}>
  118. <Left>
  119. <Thumbnail square large source={{ uri: this.props.ilustrasi }} style={{borderRadius:16}}/>
  120. </Left>
  121. <Body style={darkStyles.body}>
  122. <Text numberOfLines={2} style={darkStyles.judulDesc}>{this.props.judul}</Text>
  123. <Text note numberOfLines={1} style={darkStyles.linkDesc}>{this.props.sumber}</Text>
  124. <Footer style={darkStyles.footerDesc}>
  125. <Button transparent style={darkStyles.buttonJam}>
  126. <Icon name="time" style={darkStyles.iconDescJam}/>
  127. <Text numberOfLines={1} style={darkStyles.textDescJam}>{jam}</Text>
  128. </Button>
  129. <Button transparent style={darkStyles.buttonImpresi}>
  130. <Icon name="eye" style={darkStyles.iconDescEye}/>
  131. <Text style={darkStyles.textDescEye}>{this.props.impresi}</Text>
  132. </Button>
  133. </Footer>
  134. </Body>
  135. </ListItem>
  136. </TouchableOpacity>
  137. </View>
  138. )
  139. }
  140. }
  141.  
  142. // dark mode
  143. const darkStyles = StyleSheet.create({
  144. tabs: {
  145. height: 52,
  146. backgroundColor: '#2E3136',
  147. flexDirection: 'row'
  148. },
  149. buttonMainTabs: {
  150. flex: 1,
  151. alignItems: 'center',
  152. justifyContent: 'center',
  153. height: 52,
  154. borderBottomColor: '#2795D9',
  155. borderBottomWidth: 5
  156. },
  157. textMainTabs: {
  158. color: '#2795D9',
  159. fontSize: 15,
  160. fontWeight: '600',
  161. textTransform: 'capitalize'
  162. },
  163. buttonTabs: {
  164. flex: 1,
  165. alignItems: 'center',
  166. justifyContent: 'center',
  167. height: 52,
  168. backgroundColor: '#2E3136'
  169. },
  170. textTabs: {
  171. color: 'white',
  172. fontSize: 15,
  173. fontWeight: '600',
  174. textTransform: 'capitalize'
  175. },
  176. container: {
  177. flex: 1,
  178. backgroundColor: '#2E3136'
  179. },
  180. backgroundHeadline: {
  181. backgroundColor:'black',
  182. position:'absolute',
  183. width:'100%',
  184. height:220,
  185. opacity: 0.7
  186. },
  187. imageHeadline: {
  188. height: 220,
  189. width: null,
  190. flex: 1
  191. },
  192. judulHeadline: {
  193. marginHorizontal: 10,
  194. fontSize: 25 ,
  195. color: 'white',
  196. position: 'absolute',
  197. textAlign: 'center',
  198. alignSelf: 'center',
  199. marginTop: 70
  200. },
  201. sumberHeadline: {
  202. fontSize: 14 ,
  203. position: 'absolute',
  204. textAlign: 'center',
  205. lineHeight: 205,
  206. alignSelf: 'center',
  207. fontWeight: '500',
  208. marginTop: 45
  209. },
  210. avatar: {
  211. position: 'absolute',
  212. paddingTop: 12,
  213. paddingRight:12,
  214. alignSelf: 'flex-end'
  215. },
  216. containerJamImpresi: {
  217. flex: 1,
  218. flexDirection: 'row',
  219. position: 'absolute',
  220. alignItems: 'center',
  221. justifyContent: 'center',
  222. marginTop: 175,
  223. marginHorizontal: 100,
  224. flexDirection: 'row'
  225. },
  226. viewJam: {
  227. flex: 1,
  228. alignItems: 'center',
  229. flexDirection: 'row'
  230. },
  231. iconHeadlineJam: {
  232. color: '#FF7F00',
  233. fontSize: 17
  234. },
  235. iconHeadlineEye: {
  236. color: '#5BC97F',
  237. fontSize: 17
  238. },
  239. textHeadlineJam: {
  240. color: '#FF7F00',
  241. fontSize: 10,
  242. marginLeft: 10,
  243. fontWeight: '400',
  244. textTransform: 'capitalize'
  245. },
  246. textHeadlineEye: {
  247. color: '#5BC97F',
  248. fontSize: 10,
  249. marginLeft: 10,
  250. fontWeight: '400'
  251. },
  252. viewImpresi: {
  253. flex: 1,
  254. alignItems: 'center',
  255. justifyContent: 'center',
  256. flexDirection: 'row'
  257. },
  258. body : {
  259. marginTop: -15
  260. },
  261. judulDesc: {
  262. fontSize: 15,
  263. color: 'white',
  264. fontWeight: '500'
  265. },
  266. linkDesc: {
  267. fontSize: 12,
  268. },
  269. footerDesc: {
  270. flex: 1,
  271. backgroundColor: 'transparent',
  272. marginVertical: -20,
  273. marginBottom: -30,
  274. marginLeft: -17
  275. },
  276. buttonJam: {
  277. flex: 1,
  278. marginRight: 105,
  279. marginTop: 8
  280. },
  281. iconDescJam: {
  282. fontSize: 15,
  283. color: '#FF7F00',
  284. },
  285. iconDescEye: {
  286. fontSize: 15,
  287. color: '#5BC97F'
  288. },
  289. textDescJam: {
  290. right: 27,
  291. fontSize: 9,
  292. color: '#FF7F00',
  293. fontWeight: '500',
  294. textTransform: 'capitalize'
  295. },
  296. textDescEye: {
  297. right: 27,
  298. fontSize: 10,
  299. color: '#5BC97F',
  300. fontWeight: 'normal',
  301. textTransform: 'capitalize'
  302. },
  303. buttonImpresi: {
  304. flex: 1,
  305. right: 105,
  306. marginTop: 8
  307. }
  308. })
  309.  
  310. const lightStyles = StyleSheet.create({
  311. container: {
  312. flex: 1,
  313. },
  314. imageHeadline: {
  315. height: 220,
  316. width: null,
  317. flex: 1
  318. },
  319. judulHeadline: {
  320. fontSize: 30 ,
  321. color: 'white',
  322. position: 'absolute',
  323. textAlign: 'center',
  324. lineHeight: 145,
  325. alignSelf: 'center',
  326. marginHorizontal: 5
  327. },
  328. sumberHeadline: {
  329. fontSize: 14 ,
  330. position: 'absolute',
  331. textAlign: 'center',
  332. lineHeight: 205,
  333. alignSelf: 'center',
  334. fontWeight: '500'
  335. },
  336. containerJamImpresi: {
  337. flex: 1,
  338. flexDirection: 'row',
  339. position: 'absolute',
  340. alignItems: 'center',
  341. justifyContent: 'center',
  342. marginTop: 140,
  343. marginHorizontal: 100,
  344. flexDirection: 'row'
  345. },
  346. viewJam: {
  347. flex: 1,
  348. alignItems: 'center',
  349. flexDirection: 'row'
  350. },
  351. iconHeadlineJam: {
  352. color: '#FF7F00',
  353. fontSize: 17
  354. },
  355. iconHeadlineEye: {
  356. color: '#5BC97F',
  357. fontSize: 17
  358. },
  359. textHeadlineJam: {
  360. color: '#FF7F00',
  361. fontSize: 10,
  362. marginLeft: 10,
  363. fontWeight: '400'
  364. },
  365. textHeadlineEye: {
  366. color: '#5BC97F',
  367. fontSize: 10,
  368. marginLeft: 10,
  369. fontWeight: '400'
  370. },
  371. viewImpresi: {
  372. flex: 1,
  373. alignItems: 'center',
  374. justifyContent: 'center',
  375. flexDirection: 'row'
  376. },
  377. body : {
  378. marginTop: -15
  379. },
  380. judulDesc: {
  381. fontSize: 15,
  382. fontWeight: '500'
  383. },
  384. linkDesc: {
  385. fontSize: 12,
  386. },
  387. footerDesc: {
  388. flex: 1,
  389. backgroundColor: 'transparent',
  390. marginVertical: -20,
  391. marginBottom: -30,
  392. marginLeft: -17
  393. },
  394. buttonJam: {
  395. flex: 1,
  396. marginRight: 105,
  397. marginTop: 8
  398. },
  399. iconDescJam: {
  400. fontSize: 15,
  401. color: '#FF7F00',
  402. fontWeight: 'bold'
  403. },
  404. iconDescEye: {
  405. fontSize: 15,
  406. color: '#5BC97F',
  407. fontWeight: 'bold'
  408. },
  409. textDescJam: {
  410. right: 27,
  411. fontSize: 9,
  412. color: '#FF7F00',
  413. fontWeight: 'bold'
  414. },
  415. textDescEye: {
  416. right: 27,
  417. fontSize: 10,
  418. color: '#5BC97F',
  419. fontWeight: 'normal'
  420. },
  421. buttonImpresi: {
  422. flex: 1,
  423. right: 105,
  424. marginTop: 8
  425. }
  426. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement