Two-Line List with Circular Thumbnails
Screen is created using these React Native Core Components: <SafeAreaView />
, <ScrollView />
, <Text />
, <TouchableOpacity />
, <View />
, <Image />
import React from 'react';
import {
StyleSheet,
SafeAreaView,
ScrollView,
Text,
TouchableOpacity,
View,
Image,
} from 'react-native';
import FeatherIcon from 'react-native-vector-icons/Feather''@expo/vector-icons/Feather';
const lessons = [
{
img: 'https://images.unsplash.com/photo-1536922246289-88c42f957773?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2404&q=80',
name: 'Squat',
cal: 22,
duration: 10,
},
{
img: 'https://images.unsplash.com/photo-1597347316205-36f6c451902a?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2340&q=80',
name: 'Pull-up',
cal: 12,
duration: 15,
},
{
img: 'https://images.unsplash.com/photo-1616803689943-5601631c7fec?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2340&q=80',
name: 'Push-up',
cal: 12,
duration: 5,
},
{
img: 'https://images.unsplash.com/photo-1598266663439-2056e6900339?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2342&q=80',
name: 'Calisthenics',
cal: 33,
duration: 12,
},
{
img: 'https://images.unsplash.com/photo-1632167764165-74a3d686e9f8?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2342&q=80',
name: 'Lunge',
cal: 44,
duration: 10,
},
{
img: 'https://images.unsplash.com/photo-1536922246289-88c42f957773?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2404&q=80',
name: 'Squat',
cal: 22,
duration: 10,
},
{
img: 'https://images.unsplash.com/photo-1597347316205-36f6c451902a?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2340&q=80',
name: 'Pull-up',
cal: 12,
duration: 15,
},
{
img: 'https://images.unsplash.com/photo-1616803689943-5601631c7fec?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2340&q=80',
name: 'Push-up',
cal: 12,
duration: 5,
},
{
img: 'https://images.unsplash.com/photo-1598266663439-2056e6900339?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2342&q=80',
name: 'Calisthenics',
cal: 33,
duration: 12,
},
{
img: 'https://images.unsplash.com/photo-1632167764165-74a3d686e9f8?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2342&q=80',
name: 'Lunge',
cal: 44,
duration: 10,
},
];
export default function Example() {
return (
<SafeAreaView style={{ backgroundColor: '#fff' }}>
<ScrollView contentContainerStyle={styles.container}>
<Text style={styles.title}>Day 1 💪</Text>
{lessons.map(({ name, cal, duration, img }, index) => {
return (
<TouchableOpacity
key={index}
onPress={() => {
// handle onPress
}}>
<View style={styles.card}>
<Image
alt=""
resizeMode="cover"
style={styles.cardImg}
source={{ uri: img }} />
<View>
<Text style={styles.cardTitle}>{name}</Text>
<View style={styles.cardStats}>
<View style={styles.cardStatsItem}>
<FeatherIcon color="#636a73" name="clock" />
<Text style={styles.cardStatsItemText}>
{duration} mins
</Text>
</View>
<View style={styles.cardStatsItem}>
<FeatherIcon color="#636a73" name="zap" />
<Text style={styles.cardStatsItemText}>{cal} cals</Text>
</View>
</View>
</View>
<View style={styles.cardAction}>
<FeatherIcon
color="#9ca3af"
name="chevron-right"
size={22} />
</View>
</View>
</TouchableOpacity>
);
})}
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
padding: 24,
},
title: {
fontSize: 32,
fontWeight: '700',
color: '#1d1d1d',
marginBottom: 12,
},
/** Card */
card: {
paddingVertical: 14,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
},
cardImg: {
width: 50,
height: 50,
borderRadius: 9999,
marginRight: 12,
},
cardTitle: {
fontSize: 15,
fontWeight: '600',
color: '#000',
marginBottom: 8,
},
cardStats: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
cardStatsItem: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
marginRight: 8,
},
cardStatsItemText: {
fontSize: 13,
fontWeight: '500',
color: '#636a73',
marginLeft: 2,
},
cardAction: {
marginLeft: 'auto',
},
});
Dependencies
Before getting started, make sure you have all the necessary dependencies for this component. Follow the steps below to install any missing dependencies.
-
Install the package.
npm install --save react-native-vector-icons
-
Link the native packages for iOS.
npx pod-install
In React Native 0.60+ the CLI autolink feature links the module while building the app.
-
Add Fonts to the
Info.plist
file.
Open your XCode project, right click on the Info.plist
, and select Open As -> Source Code
.
Next, copy the fonts below into your Info.plist
.
<key>UIAppFonts</key>
<array>
<string>AntDesign.ttf</string>
<string>Entypo.ttf</string>
<string>EvilIcons.ttf</string>
<string>Feather.ttf</string>
<string>FontAwesome.ttf</string>
<string>FontAwesome5_Brands.ttf</string>
<string>FontAwesome5_Regular.ttf</string>
<string>FontAwesome5_Solid.ttf</string>
<string>FontAwesome6_Brands.ttf</string>
<string>FontAwesome6_Regular.ttf</string>
<string>FontAwesome6_Solid.ttf</string>
<string>Foundation.ttf</string>
<string>Ionicons.ttf</string>
<string>MaterialIcons.ttf</string>
<string>MaterialCommunityIcons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Octicons.ttf</string>
<string>Zocial.ttf</string>
<string>Fontisto.ttf</string>
</array>
Note: You can only select the fonts you would like to use in your React Native Application.
After you added these fonts the Info.plist
file should look like this:
-
Add
fonts.gradle
for Android.
Open android/app/build.gradle
(NOT android/build.gradle
) and add the following code to the bottom:
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
If you want to customize fonts, use:
project.ext.vectoricons = [
iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ]
]
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
Original instructions can be found on Github: https://github.com/oblador/react-native-vector-icons