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 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.

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.

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.

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.

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.

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.

React Native API

API API stands for an Application programming interface. API allows communication between two software and is also responsible for data sharing. It takes the asked data from the server and delivers...

6 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.

Advantages and Disadvantages of React Native

Advantages of using React Native It is observed that React Native stands out from most of the existing methods of cross-platform application development, like Ionic or Cordova, because React Native renders...

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.

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.

TouchableHighlight in React Native

It is just a wrapper for making touch work properly, and it is the conventional way of handling touch gestures. Today's most future-proof solution is pressable API. pressable manages all...

2 minutes read.

Difference Between React.js and React Native

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

3 minutes read.

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 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 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.

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.

HTTP in React Native

Networking HTTP in React-native: we all are aware that react native is a javascript framework.HTTP is nothing but an API request, and you might think that what is the need for an...

4 minutes read.

What is a Bridge in React Native?

A React Native is generally composed of two fields or two parts: The first part is the code of JavaScript.The second one is native code. The ability to build a bridge between...

3 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.