-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
HomeDesignCourse.tsx
210 lines (197 loc) · 5.69 KB
/
HomeDesignCourse.tsx
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import React, { useState } from 'react';
import {
StyleSheet,
View,
Text,
StatusBar,
Image,
TextInput,
useWindowDimensions,
FlatList,
} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useNavigation } from '@react-navigation/native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import CategoryListView from './CategoryListView';
import PopulerCourseListView from './PopulerCourseListView';
import MyPressable from '../components/MyPressable';
import { CATEGORY_LIST, POPULAR_COURSE_LIST } from './model/category';
import { AppImages } from '../assets';
import Config from '../Config';
interface CategoryBtn {
text: string;
selectedCat: string;
onPress: () => void;
}
const CATEGORIES = ['Ui/Ux', 'Coding', 'Basic UI'];
const CategoryButton = ({ text, selectedCat, onPress }: CategoryBtn) => (
<>
<View style={styleCatrgory(selectedCat === text).categoryBtnContainer}>
<MyPressable touchOpacity={0.6} onPress={onPress}>
<Text style={styleCatrgory(selectedCat === text).categoryBtnText}>
{text}
</Text>
</MyPressable>
</View>
{text !== CATEGORIES[2] && <View style={{ width: 16 }} />}
</>
);
const HomeDesignCourse: React.FC = () => {
const { width } = useWindowDimensions();
const insets = useSafeAreaInsets();
const navigation = useNavigation<any>();
const [selectedCategory, setSelectedCategory] = useState('Ui/Ux');
const paddingTop = Config.isIos
? Math.max(insets.top, 20)
: StatusBar.currentHeight;
const renderScrollableHeader = (
<>
<View style={[styles.searchInputMainContainer, { width: width * 0.75 }]}>
<View style={styles.searchInputContainer}>
<TextInput
style={[
styles.searchInput,
!Config.isAndroid && { paddingVertical: 16 },
]}
autoCapitalize="none"
selectionColor="dodgerblue"
placeholderTextColor="#B9BABC"
placeholder="Search for course"
/>
<Icon name="search" size={25} color="#B9BABC" />
</View>
</View>
<Text style={styles.sectionHeaderText}>Category</Text>
<View style={styles.categoryRowContainer}>
{CATEGORIES.map(text => (
<CategoryButton
{...{ text, key: text }}
selectedCat={selectedCategory}
onPress={() => setSelectedCategory(text)}
/>
))}
</View>
<FlatList
contentContainerStyle={{ padding: 16 }}
horizontal
showsHorizontalScrollIndicator={false}
data={CATEGORY_LIST}
renderItem={data => (
<CategoryListView
{...{ data }}
onScreenClicked={() => navigation.navigate('CourseInfo')}
/>
)}
keyExtractor={item => item.id.toString()}
/>
<Text style={styles.sectionHeaderText}>Popular Course</Text>
</>
);
return (
<View style={{ flex: 1, backgroundColor: 'white', paddingTop }}>
<StatusBar backgroundColor="white" barStyle="dark-content" />
<View style={styles.header}>
<View style={{ flex: 1, justifyContent: 'center' }}>
<Text style={styles.headerTextNormal}>Choose your</Text>
<Text style={styles.headerTextBold}>Design Course</Text>
</View>
<Image
style={{ width: 60, height: 60 }}
source={AppImages.design_header_image}
/>
</View>
<FlatList
contentContainerStyle={{
flexGrow: 1,
paddingBottom: 16 + insets.bottom,
}}
columnWrapperStyle={{ paddingHorizontal: 8 }}
showsVerticalScrollIndicator={false}
numColumns={2}
data={POPULAR_COURSE_LIST}
ListHeaderComponent={renderScrollableHeader}
ItemSeparatorComponent={() => <View style={{ height: 32 }} />}
renderItem={data => (
<PopulerCourseListView
{...{ data }}
onScreenClicked={() => navigation.navigate('CourseInfo')}
/>
)}
keyExtractor={item => item.id.toString()}
/>
</View>
);
};
const styles = StyleSheet.create({
searchInputMainContainer: {
marginTop: 8,
marginLeft: 18,
height: 64,
},
searchInputContainer: {
flexDirection: 'row',
backgroundColor: '#F8FAFB',
marginVertical: 8,
borderRadius: 13,
paddingHorizontal: 16,
alignItems: 'center',
},
searchInput: {
flex: 1,
fontSize: 16,
fontFamily: 'WorkSans-SemiBold',
color: 'dodgerblue',
},
sectionHeaderText: {
color: 'black',
fontSize: 22,
fontFamily: 'WorkSans-SemiBold',
letterSpacing: 0.27,
paddingTop: 8,
paddingLeft: 18,
paddingRight: 16,
marginBottom: 16,
},
categoryRowContainer: {
flexDirection: 'row',
paddingHorizontal: 16,
marginBottom: 8,
},
header: {
flexDirection: 'row',
paddingTop: 8,
paddingHorizontal: 18,
},
headerTextNormal: {
color: 'grey',
fontFamily: 'WorkSans-Regular',
letterSpacing: 0.2,
},
headerTextBold: {
color: 'black',
fontSize: 22,
fontFamily: 'WorkSans-Bold',
letterSpacing: 0.2,
},
});
const styleCatrgory = (selected: boolean) =>
StyleSheet.create({
categoryBtnContainer: {
flex: 1,
overflow: 'hidden',
borderRadius: 24,
borderColor: 'rgb(0, 182, 240)',
borderWidth: 1,
backgroundColor: selected ? 'rgb(0, 182, 240)' : 'transparent',
},
categoryBtnText: {
padding: 18,
paddingVertical: 12,
fontSize: 12,
fontFamily: 'WorkSans-SemiBold',
letterSpacing: 0.27,
alignSelf: 'center',
color: selected ? 'white' : 'rgb(0, 182, 240)',
},
});
export default HomeDesignCourse;