-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscoverScreen.js
126 lines (107 loc) · 2.76 KB
/
DiscoverScreen.js
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
import { StyleSheet, Text, View, Dimensions, TouchableOpacity, Image } from 'react-native'
import React,{useContext} from 'react'
import Carousel from 'react-native-snap-carousel'
import { NewsContext } from './contextapi';
import {categories, sources} from './api'
const DiscoverScreen = () => {
const { setCategory,setSource } = useContext(NewsContext)
const windowWidth = Dimensions.get('window').width;
const slideWidth = Math.round(windowWidth/2.5)
return (
<View style={styles.discover}>
{/* Search */}
{/* Category */}
<Text style={styles.subtitle}>Categories</Text>
<Carousel
layout={'default'}
data= {categories}
renderItem={({item, index})=>{
return(<View style={styles.slideContainer}>
<TouchableOpacity style={styles.slide} onPress={()=>setCategory(item.name)}>
<Image source={{uri:item.pic}} style={styles.categoryImage}/>
<Text style={styles.categoryText}>{item.name.toUpperCase()}</Text>
</TouchableOpacity>
</View>)
}}
sliderWidth={windowWidth}
itemWidth = {slideWidth}
activeSlideAlignment={'start'}
inactiveSlideScale={1}
inactiveSlideOpacity={1}
/>
{/* Sources */}
<Text style={styles.subtitle}>Sources</Text>
<View style={styles.source}>
{
sources.map((item)=>(
<TouchableOpacity
key={item.id}
onPress={()=>setSource(item.id)}
style={styles.sourceContainer}>
<Image source={{uri:item.pic}} style={styles.sourceImage}/>
</TouchableOpacity>
))
}
</View>
</View>
)
}
export default DiscoverScreen
const styles = StyleSheet.create({
discover:{
padding:10,
alignItems:'center',
},
subtitle:{
fontSize:24,
color:'black',
fontWeight:'bold',
alignSelf:'flex-start'
},
categoryImage:{
height:40,
width:40,
margin:10,
},
categoryText:{
fontSize:15,
color:'black',
fontWeight:'600',
textTransform: 'capitalize',
},
slideContainer:{
flexDirection:'column',
height:130,
justifyContent:'center',
alignItems:'center',
padding:10,
},
slide:{
height:'100%',
width:"100%",
backgroundColor:'#F2F2F2',
flexDirection:'column',
alignItems:'center',
justifyContent:'center',
borderRadius:10,
elevation:10,
},
sourceContainer:{
height:150,
width:'40%',
borderRadius:10,
margin:15,
backgroundColor:'#F2F2F2',
},
sourceImage:{
height:"100%",
borderRadius:10,
resizeMode:'cover',
},
source:{
flexDirection:'row',
flexWrap:'wrap',
paddingVertical:15,
justifyContent:'space-around'
}
})