Task Management Screen
Screen is created using these React Native Core Components: <View />, <SafeAreaView />, <ScrollView />, <Text />, <TouchableOpacity />, <Image />
import React from 'react';
import {
StyleSheet,
View,
SafeAreaView,
ScrollView,
Text,
TouchableOpacity,
Image,
} from 'react-native';
import FontAwesome from 'react-native-vector-icons/FontAwesome5''@expo/vector-icons/FontAwesome5';
import FeatherIcon from 'react-native-vector-icons/Feather''@expo/vector-icons/Feather';
const data = [
{
label: '📅 Create project timeline',
date: new Date('2024-12-12'),
completed: true,
},
{
label: '🎯 Define project goals',
date: new Date('2025-01-05'),
completed: false,
},
{
label: '👥 Identify project stakeholders',
date: new Date('2025-01-09'),
completed: true,
},
{
label: '📝 Gather project requirements',
date: new Date('2025-01-12'),
completed: false,
},
{
label: '💰 Create project budget',
date: new Date('2025-01-15'),
completed: false,
},
];
const collaborators = [
{
name: 'David Z. (you)',
avatar:
'https://images.unsplash.com/photo-1633332755192-727a05c4013d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2.5&w=256&h=256&q=80',
},
{
name: 'Sierra K.',
avatar:
'https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2.5&w=256&h=256&q=80',
},
{
name: 'Jack W.',
avatar:
'https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=facearea&facepad=2.5&w=256&h=256&q=80',
},
];
export default function Example() {
const [tasks, setTasks] = React.useState(data);
const handleUpdateTask = index => {
setTasks(value => {
value[index].completed = !value[index].completed;
return [...value];
});
};
return (
<View style={{ flex: 1 }}>
<SafeAreaView style={{ flex: 1, backgroundColor: '#f6f6f6' }}>
<View style={styles.header}>
<View style={styles.headerAction}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<FeatherIcon
color="#000"
name="chevron-left"
size={20} />
</TouchableOpacity>
</View>
<Text numberOfLines={1} style={styles.headerTitle}>
My Tasks
</Text>
<View style={[styles.headerAction, { alignItems: 'flex-end' }]}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<FeatherIcon
color="#000"
name="more-vertical"
size={20} />
</TouchableOpacity>
</View>
</View>
<ScrollView contentContainerStyle={styles.content}>
<View style={styles.section}>
<Text style={styles.title}>Project Planning</Text>
<View style={styles.row}>
<Text style={styles.rowField}>Due Date</Text>
<Text style={styles.rowValue}>May 23, 2023</Text>
</View>
<View style={styles.row}>
<Text style={styles.rowField}>Status</Text>
<View style={styles.badge}>
<Text style={styles.badgeText}>In Progress</Text>
</View>
</View>
<View style={[styles.row, { alignItems: 'flex-start' }]}>
<Text style={styles.rowField}>Collaborators</Text>
<View>
{collaborators.map(({ name, avatar }, index) => (
<TouchableOpacity
key={index}
onPress={() => {
// handle onPress
}}
style={styles.collaborator}>
<Image
alt=""
source={{ uri: avatar }}
style={styles.avatar} />
<Text style={styles.collaboratorText}>{name}</Text>
</TouchableOpacity>
))}
</View>
</View>
</View>
<View style={styles.section}>
<Text style={styles.sectionTitle}>Description</Text>
<Text style={styles.sectionText}>
This task involves reviewing and providing feedback on the design
concepts and prototypes created by the design team. It includes
evaluating the aesthetic appeal, functionality, usability, and
alignment with project requirements.
</Text>
</View>
<View style={styles.section}>
<Text style={styles.sectionTitle}>Tasks</Text>
{tasks.map(({ label, date, completed }, index) => {
const isActive = completed === true;
const dateFormatted = date.toLocaleDateString('en-US', {
day: 'numeric',
month: 'short',
year: 'numeric',
});
const description = completed
? `Completed on ${dateFormatted}`
: `Started on ${dateFormatted}`;
return (
<TouchableOpacity
key={index}
onPress={() => {
handleUpdateTask(index);
}}
style={styles.task}>
<View
style={[
styles.taskIcon,
isActive ? { backgroundColor: '#eb3333' } : {},
]}>
<FontAwesome
color="#fff"
name="check"
style={!isActive && { display: 'none' }}
size={11} />
</View>
<View>
<Text style={styles.taskLabel}>{label}</Text>
<Text style={styles.taskDescription}>{description}</Text>
</View>
</TouchableOpacity>
);
})}
</View>
</ScrollView>
</SafeAreaView>
<View style={styles.overlay}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}
style={{ flex: 1, paddingHorizontal: 24 }}>
<View style={styles.btn}>
<Text style={styles.btnText}>Save</Text>
</View>
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
content: {
paddingBottom: 80,
},
title: {
fontSize: 23,
fontWeight: '600',
color: '#1e1e1e',
marginBottom: 10,
},
avatar: {
width: 18,
height: 18,
borderRadius: 9999,
},
overlay: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
backgroundColor: '#fff',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingTop: 12,
paddingHorizontal: 16,
paddingBottom: 48,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 1,
},
shadowOpacity: 0.22,
shadowRadius: 2.22,
elevation: 3,
},
/** Header */
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 16,
},
headerAction: {
width: 40,
height: 40,
alignItems: 'flex-start',
justifyContent: 'center',
},
headerTitle: {
fontSize: 16,
fontWeight: '500',
color: '#1d1d1d',
flexGrow: 1,
flexShrink: 1,
flexBasis: 0,
textAlign: 'center',
},
/** Section */
section: {
paddingHorizontal: 16,
borderTopWidth: 1,
borderBottomWidth: 1,
borderColor: '#D7D7D7',
backgroundColor: '#fff',
paddingTop: 8,
marginBottom: 12,
},
sectionTitle: {
fontSize: 19,
fontWeight: '600',
color: '#1e1e1e',
marginBottom: 8,
},
sectionText: {
fontSize: 14,
lineHeight: 20,
color: '#444444',
marginBottom: 16,
},
/** Row */
row: {
marginVertical: 8,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
borderBottom: 1,
borderColor: '#D7D7D7',
backgroundColor: '#fff',
},
rowField: {
fontSize: 15,
fontWeight: '600',
color: '#0e0e0e',
width: 130,
},
rowValue: {
fontSize: 15,
fontWeight: '500',
color: '#171717',
},
/** Badge */
badge: {
paddingVertical: 4,
paddingHorizontal: 8,
borderRadius: 4,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ffa500',
},
badgeText: {
fontSize: 15,
fontWeight: '600',
color: '#fff',
},
/** Collaborator */
collaborator: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 10,
},
collaboratorText: {
fontSize: 13,
fontWeight: '500',
color: '#171717',
marginLeft: 6,
},
/** Task */
task: {
position: 'relative',
paddingTop: 12,
paddingRight: 16,
paddingBottom: 14,
paddingLeft: 0,
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'flex-start',
},
taskIcon: {
marginTop: 4,
marginRight: 12,
marginBottom: 0,
marginLeft: 6,
width: 24,
height: 24,
borderColor: '#eb3333',
borderRadius: 9999,
alignItems: 'center',
justifyContent: 'center',
borderWidth: 1,
},
taskLabel: {
fontSize: 16,
fontWeight: '500',
marginBottom: 5,
color: '#000',
},
taskDescription: {
fontSize: 14,
fontWeight: '400',
color: '#959595',
},
/** Button */
btn: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 8,
paddingVertical: 10,
paddingHorizontal: 20,
borderWidth: 1,
backgroundColor: '#24232A',
borderColor: '#24232A',
},
btnText: {
fontSize: 18,
lineHeight: 26,
fontWeight: '600',
color: '#fff',
},
});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.plistfile.
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.gradlefor 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