React native calender

In this article, we will be learning to add calendar features to react native app.

So before creating the calendar, we do need to install a few packages or add some packages. This feature is important. This feature is one of the essential features to learn because we find a date picker in almost every app, the purpose of having a date picker can be different, but after all, it's a date picker. We can create interesting date pickers using some methods and styling. Still, here we will be learning about the basic structure of the calendar, and you can create a lot of attractive date pickers after learning the basic creating method.

Installing required packages

  1. npm install react-big-calendar
  2. npm install react-date picker
  3. npm install date-fnsnpm install --save react-native-calendar

The basic calender object contains date,month,year and timestamp.

let s create one datepicker using react native calender

App.js code:

import React, {useState} from 'react';
import {
  Text,
  SafeAreaView,
  View,
  StyleSheet,
} from 'react-native';
import DatePicker from 'react-native-datepicker';
 const App = () => {
  const [Date, setDate] = useState('09-10-2020');
 
  return (
    <SafeAreaView style={styles.container}>
      <View style={styles.container}>
        <Text style={{color:"#aa80ff",fontWeight:'bold',fontSize: 50}}>Tutorial and example </Text>
        <Text style={styles.title}>
          pick your birthday date
        </Text>
        <DatePicker
          style={styles.datePickerStyle}
          date={date}
          mode="date"
          placeholder="select date"
          format="DD-MM-YYYY"
          minDate="01-01-2016"
          maxDate="12-05-2022"
          confirmBtnText="Confirm"
          cancelBtnText="Cancel"
         
        />
      </View>
    </SafeAreaView>
  );
};


 export default App;
 const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 10,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor:'#003326'
  },


  title: {
    textAlign: 'center',
    fontSize: 30,
    fontWeight: 'bold',
    padding: 20,
    marginTop: 200,
    color:'#80ff80'
  },


  datePickerStyle: {
    width: 200,
    marginTop: 100,
    backgroundColor:'#80ff80',
    borderColor : 'white',
    borderWidth: 20
  },


});

Output:

React native calendar

Explanation: let's understand some important parts of the code above.

Import DatePicker from 'react-native-date picker;

Through this, we have imported the DatePicker from the react-native-datepicker package.

 const [date, setDate] = useState('09-10-2020');

Here we have used usestate for the date, and setdate will be used to alter the date. We are using useState because it's not fixed. It is supposed to change as per the user's requirement.

<DatePicker
          style={styles.datePickerStyle}
          date={Date}
          mode="date"
          placeholder="select date"
          format="DD-MM-YYYY"
          minDate="01-01-2016"
          maxDate="12-05-2022"
          confirmBtnText="Confirm"
          cancelBtnText="Cancel"
         
        />

The format represents the how Date will be represented. Here date is initialized by Date ( where useState is used). We have already discussed placeholder previously. Whatever text is written in placeHolder will be visible to the user for their convenience, so they know what they actually have to fill on that blank part. minDate is the minimum date that this date picker can pick. The date before the min date cannot be picked. The same goes for maxDate. We cannot pick a date greater than the maxDate. confirmBtnText is for confirming the Date and cancel is for not making any change means you do not want to pick the Date, so you choose to cancel instead of picking.

The rest is the styling part and some text component which is easy to understand. If you are having any problem styling or in any component, kindly check that component's tutorial or styling tutorial part. It would definitely be helpful for you.

I hope you have learned about the react-native calender.


Related Topics

React Native Tutorial

Introduction to react native : React-native is an open-source javascript framework that can be used to develop native mobile apps for IOS and android. It is released by Facebook in 2015...

4 minutes read.

React Native Creating Components

React elements are where all React codes reside. The React elements are very similar to the regular React components, which have a unique style and offer contrast. Working with views When you...

3 minutes read.

Basic knowledge of firebase for React Native

Firebase for react-native : Firebase is a mobile and web application development platform which is created in 2014 by google. It is a product of google which is offered to developers...

7 minutes read.

React Native Side Drawer

In this part of the react-native tutorial, we will be learning about the react-native side drawer. We have already studied the status bar and various parts of react-native navigation, including...

5 minutes read.

React Native Status Bar

What is the status bar? The simplest and easiest answer to this question can be answered by looking at your mobile phone's top section. What can you see? Most probably, it's...

4 minutes read.

React Native navigation bar and button

Here we will be focusing on header navigation. We will add buttons to the header, which is the best way to interact with a header. We have already learned about...

4 minutes read.

React Native Fonts

The font is one of the important essences of any good UI(User Interface). It is very important to have a clear and beautiful font in your app. In this module,...

4 minutes read.

Redux in React Native

 It is a really amazing library of javascript, react, and react-native. It is very popular in react native domain. Every react and react native developer must know the redux it...

7 minutes read.

React Native Components

React Native components are the same as ordinary react components, but they are different in terms of rendering and styling. All react code lives in react components. They are independent...

16 minutes read.

React Native Toast

Introduction: It is a message that will be displayed on the screen for a short span of time to interrupt the user. Primarily it is displayed by any user action....

5 minutes read.

Lifecycle of React Native Components

We are familiar with the word “lifecycle”. In human life, the lifecycle has three phases - birthlifedeath In react native its component lifecycle is almost the same as the human lifecycle. The...

6 minutes read.

How Does React Native Work

Working of React Native React Native is a framework that lets us write android and iOS mobile applications using JavaScript. It is interesting to see how easy it is to develop...

4 minutes read.

States in React Native

We can control data of components of react-native by state and props. We are familiar with props and used them multiple times previously. Props: This is used to customize components and...

3 minutes read.

React Native Pressable

It manages all the touch inputs, and it is one of the core wrappers introduced in July 2022. The Two important features of pressable are listed below- onPressInonPressOut onpressIn: We already know the...

3 minutes read.

React Native Animations

Animation: animation is a method in which puppets, figures, drawings, etc., appear as moving creatures, making an illusion that things are moving. It is a unique way of expressing something...

6 minutes read.

React Native Sound

It is a great way to connect to the user. Just a tiny "ting" of any email received, or some sound for deleting a file or sound for sending a...

8 minutes read.

React native calender

In this article, we will be learning to add calendar features to react native app. So before creating the calendar, we do need to install a few packages or add some...

3 minutes read.

TouchableOpacity in React Native

Touchable opacity is the most suited example if you want to make views respond to proper touch. If you want to control the opacity then it can be done by...

3 minutes read.

React Native indicator

React native activity indicator : React native activity indicator is one of the react-native components. We all have seen it several times. It's the loader. Look at the picture below - So now...

4 minutes read.

Why to Learn React Native

The demand for smartphone applications is ever-changing. The elder ones disappear from our remembrances, and smartphones and new applications come each day. In this turbulent ecosystem, it is struggling for...

4 minutes read.