Show Timeline using React Native Timeline ListView

React Native Timeline ListView

This is an Example to Show Timeline using React Native Timeline ListView in Android and IOS. A timeline is very useful to show event activity or progress. The timeline list can be used in many places. For this example, we have used Timeline component provided by react-native-timeline-flatlist.

As ListView has been deprecated in React Native 0.60+ we have updated this example for the FlatList. Enjoy ūüôā

If we think about the practical use of Timeline then the best example which comes to my mind is the delivery process of any product from online purchase to doorstep delivery. Other than that you can also use Timeline to make a School event calendar or any function calendar with dates and times. There can be many more places where we can use Timeline. If you want to share some more places where we can use Timeline then comment below to help other readers.

Now coming back to the example. In this example, we are making a view with buttons in a horizontal scroll view on top and the main view which will hold the different types of Timeline components. With the click of the top buttons, we will change the component in the main area. It is a kind of Activity holding different fragments for those who have no idea about the last line don’t worry you can visit How to Make a View Like Android Fragment in React Native¬†to have an idea about that.

Types of Timeline ListView

The post contains the following Timeline ListView

  1. Basic TimeLine.
  2. Custom TimeLine.
  3. Dot TimeLine.
  4. Icon TimeLine.
  5. Override Render TimeLine.
  6. Refresh and Load More data in TimeLine.
  7. Right  Side Single TimeLine.
  8. Template TimeLine.
  9. Capture onPress on the TimeLine.
  10. Two Column TimeLine.

So let’s start with an example.

To Make a React Native App

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react native command line interface to make our React Native App.

If you have previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:

npm uninstall -g react-native-cli @react-native-community/cli

Run the following commands to create a new React Native project

npx react-native init ProjectName

If you want to start a new project with a specific React Native version, you can use the --version argument:

npx react-native init ProjectName --version X.XX.X

Note If the above command is failing, you may have old version of react-native or react-native-cli installed globally on your pc. Try uninstalling the cli and run the cli using npx.

This will make a project structure with an index file named App.js in your project directory.

Installation of Dependency

To use Timeline we need to install react-native-timeline-flatlist dependency.

To install this open the terminal and jump into your project using

cd ProjectName

Run the following command to install

npm install react-native-timeline-flatlist --save

This command will copy all the dependencies into your node_module directory. –save is optional, it is just to update the react-native-timeline-flatlist dependency in your package.json file.

As the example has 10 different screens and is very long I am making an App.js which will be the main screen and other screens are like independent components so I’ll post the code and then a screenshot of it. If you are facing any issues with that then you can comment below so that I can update the post accordingly.

Project Structure

For this project, you have to create a project structure as shown below.

Code for Timeline ListView

App.js

This will be our main landing screen which has some buttons on the top in the horizontal scroll view. On pressing the buttons, we are returning different views to show.

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React, {useState} from 'react';

// import all the components we are going to use
import {
  SafeAreaView,
  Text,
  View,
  StyleSheet,
  TouchableOpacity,
  ScrollView,
} from 'react-native';

import BasicTimeLine from './components/BasicTimeLine';
import CustomTimeLine from './components/CustomTimeLine';
import DotTimeLine from './components/DotTimeLine';
import IconTimeLine from './components/IconTimeLine';
import
  OverrideRenderTimeLine
from './components/OverrideRenderTimeLine';
import
  RefreshLoadMoreTimeLine
from './components/RefreshLoadMoreTimeLine';
import SingleRightTimeLine from './components/SingleRightTimeLine';
import TemplateTimeLine from './components/TemplateTimeLine';
import TimeLinePress from './components/TimeLinePress';
import TwoColumnTimeLine from './components/TwoColumnTimeLine';

const App = () => {
  const [val, setVal] = useState(1);

  const renderElement = () => {
    //You can add N number of Views here in if-else condition
    if (val === 1) {
      return <BasicTimeLine />;
    } else if (val === 2) {
      return <CustomTimeLine />;
    } else if (val === 3) {
      return <DotTimeLine />;
    } else if (val === 4) {
      return <IconTimeLine />;
    } else if (val === 5) {
      return <OverrideRenderTimeLine />;
    } else if (val === 6) {
      return <RefreshLoadMoreTimeLine />;
    } else if (val === 7) {
      return <SingleRightTimeLine />;
    } else if (val === 8) {
      return <TemplateTimeLine />;
    } else if (val === 9) {
      return <TimeLinePress />;
    } else if (val === 10) {
      return <TwoColumnTimeLine />;
    }
  };

  const tabName = [
    'Basic TimeLine',
    'Custom TimeLine',
    'Dot TimeLine',
    'Icon TimeLine',
    'Override Render TimeLine',
    'Refresh Load More TimeLine',
    'Single Right TimeLine',
    'Template TimeLine',
    'TimeLine Press',
    'Two Column TimeLine',
  ];

  return (
    <SafeAreaView style={styles.container}>
      <View style={styles.container}>
        <View>
          <ScrollView horizontal>
            <View style={{flexDirection: 'row'}}>
              {tabName.map((item, index) => {
                return (
                  <TouchableOpacity
                    key={index + 1}
                    style={[
                      styles.buttonStyle,
                      {
                        backgroundColor:
                          val == index + 1 ? 'orange' : '#808080',
                      },
                    ]}
                    onPress={() => setVal(index + 1)}>
                    <Text style={{color: '#ffffff'}}>
                      {item}
                    </Text>
                  </TouchableOpacity>
                );
              })}
            </View>
          </ScrollView>
        </View>
        {/*View to hold the child screens 
        which can be changed on the click of a button*/}
        <View style={styles.childContainer}>
          {renderElement()}
        </View>
      </View>
    </SafeAreaView>
  );
};
export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ffffff',
  },
  buttonStyle: {
    flex: 1,
    alignItems: 'center',
    padding: 10,
    margin: 2,
  },
  childContainer: {
    backgroundColor: '#f9f9f9',
    flex: 1,
    padding: 10,
  },
});

After creating the main screen now you can see the screenshot and the code for different Timelines.

BasicTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const BasicTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '12:00',
      title: 'Event 3',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '14:00',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '16:30',
      title: 'Event 5',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
  ];

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Basic TimeLine Example</Text>
      <Timeline data={data} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default BasicTimeLine;

CustomTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const CustomTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      circleColor: '#009688',
      lineColor: '#009688',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {time: '12:00', title: 'Event 2'},
    {
      time: '14:00',
      title: 'Event 3',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
    },
    {
      time: '16:30',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      circleColor: '#009688',
    },
  ];

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Custom TimeLine Example</Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgb(45,156,219)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default CustomTimeLine;

DotTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const DotTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      circleColor: '#009688',
      lineColor: '#009688',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '14:00',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
    },
    {
      time: '16:30',
      title: 'Event 5',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      circleColor: '#009688',
    },
  ];

  //'rgb(45,156,219)'
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Dot TimeLine Example</Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgb(45,156,219)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
        innerCircle={'dot'}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default DotTimeLine;

IconTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const IconTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '12:00',
      title: 'Lunch',
      icon: require('../img/place_holder.png')
    },
    {
      time: '14:00',
      title: 'Event 3',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '16:30',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
  ];

  //'rgb(45,156,219)'
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Icon TimeLine Example</Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgba(0,0,0,0)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
        innerCircle={'icon'}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default IconTimeLine;

OverrideRenderTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View, Image} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const OverrideRenderTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '12:00',
      title: 'Event 3',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '14:00',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '16:30',
      title: 'Event 5',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
  ];

  const renderDetail = (rowData, sectionID, rowID) => {
    let title = <Text style={[styles.rowTitle]}>{rowData.title}</Text>;
    var desc = null;
    if (rowData.description && rowData.imageUrl)
      desc = (
        <View style={styles.descriptionContainer}>
          <Image
            source={{uri: rowData.imageUrl}}
            style={styles.imageStyle}
          />
          <Text style={[styles.textDescriptionStyle]}>
            {rowData.description}
          </Text>
        </View>
      );

    return (
      <View style={{flex: 1}}>
        {title}
        {desc}
      </View>
    );
  };

  return (
    <View style={styles.container}>
      <Text style={styles.title}>
        Override Render TimeLine Example
      </Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgba(0,0,0,0)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
        innerCircle={'icon'}
        onEventPress={(item) => 
          alert(`${item.title} at ${item.time}`)
        }
        renderDetail={renderDetail}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
  rowTitle: {
    fontSize: 16,
    fontWeight: 'bold',
  },
  descriptionContainer: {
    flexDirection: 'row',
    paddingRight: 50,
  },
  imageStyle: {
    width: 50,
    height: 50,
    borderRadius: 25,
  },
  textDescriptionStyle: {
    marginLeft: 10,
    color: 'gray',
  },
});

export default OverrideRenderTimeLine;

RefreshLoadMoreTimeLine.js

  
// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React, {useState} from 'react';

// import all the components we are going to use
import {
  StyleSheet,
  Text,
  View,
  RefreshControl,
  ActivityIndicator,
} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const RefreshLoadMoreTimeLine = () => {
  let timeLineContent = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '12:00',
      title: 'Lunch',
      icon: require('../img/place_holder.png')
    },
    {
      time: '14:00',
      title: 'Event 3',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
    {
      time: '16:30',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
    },
  ];

  // Setting up state
  const [isRefreshing, setIsRefreshing] = useState(false);
  const [waiting, setWaiting] = useState(false);
  const [data, setData] = useState(timeLineContent);

  const onRefresh = () => {
    setIsRefreshing(true);
    //refresh to initial data
    setTimeout(() => {
      //refresh to initial data
      setData(data);
      setIsRefreshing(false);
    }, 2000);
  };

  const onEndReached = () => {
    if (!waiting) {
      setWaiting(true);
      //fetch and concat data
      setTimeout(() => {
        //refresh to initial data
        let timeLineContent = data.concat([
          {
            time: '18:00',
            title: 'More Loaded Event 5',
            description:
              'Lorem Ipsum is simply dummy text of the printing.',
          },
          {
            time: '18:00',
            title: 'More Loaded Event 6',
            description:
              'Lorem Ipsum is simply dummy text of the printing.',
          },
          {
            time: '18:00',
            title: 'More Loaded Event 7',
            description:
              'Lorem Ipsum is simply dummy text of the printing.',
          },
          {
            time: '18:00',
            title: 'More Loaded Event 8',
            description:
              'Lorem Ipsum is simply dummy text of the printing.',
          },
          {
            time: '18:00',
            title: 'More Loaded Event 9',
            description:
              'Lorem Ipsum is simply dummy text of the printing.',
          },
        ]);
        setWaiting(false);
        setData(timeLineContent);
      }, 2000);
    }
  };

  const renderFooter = () => {
    if (waiting) {
      return <ActivityIndicator />;
    } else {
      return <Text>~</Text>;
    }
  };

  //'rgb(45,156,219)'
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Refresh Load More Example</Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgb(45,156,219)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
          refreshControl: (
            <RefreshControl
              refreshing={isRefreshing}
              onRefresh={onRefresh}
            />
          ),
          renderFooter: renderFooter,
          onEndReached: onEndReached,
        }}
        innerCircle={'dot'}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default RefreshLoadMoreTimeLine;

SingleRightTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View, Image} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const SingleRightTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '12:00',
      title: 'Event 3',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '14:00',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '16:30',
      title: 'Event 5',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
  ];

  const renderDetail = (rowData, sectionID, rowID) => {
    let title =
      <Text style={[styles.rowTitle]}>
        {rowData.title}
      </Text>;
    var desc = null;
    if (rowData.description && rowData.imageUrl)
      desc = (
        <View style={styles.descriptionContainer}>
          <Image
            source={{uri: rowData.imageUrl}}
            style={styles.imageStyle}
          />
          <Text style={[styles.textDescriptionStyle]}>
            {rowData.description}
          </Text>
        </View>
      );
    return (
      <View style={{flex: 1}}>
        {title}
        {desc}
      </View>
    );
  };

  return (
    <View style={styles.container}>
      <Text style={styles.title}>
        Right Side Single TImeline Example
      </Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgba(0,0,0,0)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
        innerCircle={'icon'}
        onEventPress={(item) =>
          alert(`${item.title} at ${item.time}`)
        }
        renderDetail={renderDetail}
        separator={false}
        detailContainerStyle={{
          marginBottom: 20,
          paddingLeft: 5,
          paddingRight: 5,
          backgroundColor: '#BBDAFF',
          borderRadius: 10,
        }}
        columnFormat="single-column-right"
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
  rowTitle: {
    fontSize: 16,
    fontWeight: 'bold',
  },
  descriptionContainer: {
    flexDirection: 'row',
    paddingRight: 50,
  },
  imageStyle: {
    width: 50,
    height: 50,
    borderRadius: 25,
  },
  textDescriptionStyle: {
    marginLeft: 10,
    color: 'gray',
  },
});

export default SingleRightTimeLine;

TemplateTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const TemplateTimeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Archery Training',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '12:00',
      title: 'Event 3',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '14:00',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '16:30',
      title: 'Event 5',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
  ];

  //'rgb(45,156,219)'
  return (
    <View style={styles.container}>
      <Text style={styles.title}>Template Timeline Example</Text>
      <Timeline
        data={data}
        //separator={true}
        circleSize={20}
        circleColor="rgba(0,0,0,0)"
        //circleStyle={{borderWidth:1}}
        //dotColor='yellow'
        //lineWidth={2}
        //lineColor='rgb(45,156,219)'
        //timeTextStyle={{color:'green'}}
        //timeContainerStyle={{minWidth: 65}}
        //titleStyle={{color:'green'}}
        //descriptionStyle={{color:'red'}}
        innerCircle={'icon'}
        //iconStyle={{backgroundColor:'white'}}
        //separatorStyle={{backgroundColor: 'green'}}
        //scrollEnabled={false}
        options={{}}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});
export default TemplateTimeLine;

TimeLinePress.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const TimeLinePress = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '12:00',
      title: 'Lunch',
      icon: require('../img/place_holder.png')
    },
    {
      time: '14:00',
      title: 'Event 3',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '16:30',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
    },
  ];

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Timeline Press Example</Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgba(0,0,0,0)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
        innerCircle={'icon'}
        onEventPress={(item) =>
          alert(`${item.title} at ${item.time}`)
        }
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default TimeLinePress;

TwoColumnTimeLine.js

// Show Timeline using React Native Timeline ListView
// https://aboutreact.com/react-native-timeline-listview/

// import React in our code
import React from 'react';

// import all the components we are going to use
import {StyleSheet, Text, View} from 'react-native';

// import Timeline
import Timeline from 'react-native-timeline-flatlist';

const TwoColumnTmeLine = () => {
  const data = [
    {
      time: '09:00',
      title: 'Event 1',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '10:45',
      title: 'Event 2',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '12:00',
      title: 'Event 3',
      icon: require('../img/place_holder.png'),
    },
    {
      time: '14:00',
      title: 'Event 4',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      lineColor: '#009688',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
    {
      time: '16:30',
      title: 'Event 5',
      description:
        'Lorem Ipsum is simply dummy text of the printing.',
      icon: require('../img/place_holder.png'),
      imageUrl:
        'https://images.pexels.com/photos/2250394/pexels-photo-2250394.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=250&w=250',
    },
  ];

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Two Column TimeLine Example</Text>
      <Timeline
        data={data}
        circleSize={20}
        circleColor="rgba(0,0,0,0)"
        lineColor="rgb(45,156,219)"
        timeContainerStyle={{minWidth: 52, marginTop: -5}}
        timeStyle={{
          textAlign: 'center',
          backgroundColor: '#ff9797',
          color: 'white',
          padding: 5,
          borderRadius: 13,
        }}
        descriptionStyle={{color: 'gray'}}
        options={{
          style: {paddingTop: 5},
        }}
        innerCircle={'icon'}
        onEventPress={(item) => 
          alert(`${item.title} at ${item.time}`)
        }
        separator={false}
        detailContainerStyle={{
          marginBottom: 20,
          paddingLeft: 5,
          paddingRight: 5,
          backgroundColor: '#BBDAFF',
          borderRadius: 10,
        }}
        columnFormat="two-column"
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  title: {
    padding: 16,
    fontSize: 20,
    textAlign: 'center',
    fontWeight: 'bold',
  },
});

export default TwoColumnTmeLine;

To Run the React Native App

Open the terminal again and jump into your project using.

cd ProjectName

1. Start Metro Bundler

First, you will need to start Metro, the JavaScript bundler that ships with React Native. To start Metro bundler run following command

npx react-native start

Once you start Metro Bundler it will run forever on your terminal until you close it. Let Metro Bundler run in its own terminal. Open a new terminal and run the application.

2. Start React Native Application

To run the project on an Android Virtual Device or on real debugging device

npx react-native run-android

or on the iOS Simulator by running (macOS only)

npx react-native run-ios

Output Screenshots

               .   .   .   .  .  

Output in Online Emulator


This is how you can show Timeline using React Native Timeline ListView / Flat list in Android and IOS. If you have any doubts or want to share something about the topic you can comment below or contact us here. There will be more posts coming soon. Stay tuned!

Hope you liked it. ūüôā

3 thoughts on “Show Timeline using React Native Timeline ListView”

    • Hello Ayodele,
      They do not provide that much customization. So if you want to add those things you have to create your own.
      Can you please clarify what you want. maybe I can help you to make your own component.

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.