Convert Figma logo to code with AI

kizitonwose logoCalendar

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

4,636
502
4,636
10

Top Related Projects

An easily internationalizable, mobile-friendly datepicker library for the web

React Native Calendar Components 🗓️ 📆

Full-sized drag & drop event calendar in JavaScript

React Calendar

An elegant calendar and datepicker plugin for Vue.

A datepicker for twitter bootstrap (@twbs)

Quick Overview

Calendar is a highly customizable, feature-rich calendar library for Android. It provides a flexible and efficient way to implement various calendar views in Android applications, supporting both month and week views with customizable day cells.

Pros

  • Highly customizable with support for custom day views and layouts
  • Efficient scrolling and recycling of calendar views
  • Supports both month and week views
  • Extensive documentation and sample code available

Cons

  • Limited to Android platform
  • May require additional setup for complex use cases
  • Learning curve for advanced customizations
  • Dependency on other Android libraries

Code Examples

  1. Basic setup of a MonthCalendarView:
val calendarView = findViewById<CalendarView>(R.id.calendarView)
val currentMonth = YearMonth.now()
val startMonth = currentMonth.minusMonths(10)
val endMonth = currentMonth.plusMonths(10)
val daysOfWeek = daysOfWeek()
calendarView.setup(startMonth, endMonth, daysOfWeek.first())
calendarView.scrollToMonth(currentMonth)
  1. Customizing day view:
class DayViewContainer(view: View) : ViewContainer(view) {
    val textView = view.findViewById<TextView>(R.id.calendarDayText)
}

calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}
  1. Handling date selection:
var selectedDate: LocalDate? = null
calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
        container.view.setOnClickListener {
            selectedDate = day.date
            calendarView.notifyDateChanged(day.date)
        }
    }
}

Getting Started

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.kizitonwose.calendar:view:2.3.0'
}
  1. Add the CalendarView to your layout XML:
<com.kizitonwose.calendar.view.CalendarView
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
  1. Initialize the CalendarView in your Activity or Fragment:
val calendarView = findViewById<CalendarView>(R.id.calendarView)
val currentMonth = YearMonth.now()
val startMonth = currentMonth.minusMonths(10)
val endMonth = currentMonth.plusMonths(10)
val daysOfWeek = daysOfWeek()
calendarView.setup(startMonth, endMonth, daysOfWeek.first())
calendarView.scrollToMonth(currentMonth)

Competitor Comparisons

An easily internationalizable, mobile-friendly datepicker library for the web

Pros of react-dates

  • More comprehensive date-picking functionality, including range selection
  • Extensive customization options for appearance and behavior
  • Well-established with a large community and extensive documentation

Cons of react-dates

  • Larger bundle size due to more features and dependencies
  • Steeper learning curve for basic implementation
  • Less flexible for non-standard calendar layouts or custom date representations

Code Comparison

react-dates:

import { DateRangePicker } from 'react-dates';

<DateRangePicker
  startDate={this.state.startDate}
  startDateId="start_date_id"
  endDate={this.state.endDate}
  endDateId="end_date_id"
  onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })}
  focusedInput={this.state.focusedInput}
  onFocusChange={focusedInput => this.setState({ focusedInput })}
/>

Calendar:

CalendarView(CalendarDay.today())
    .dayBinder(dayBinder)
    .monthHeaderBinder(monthHeaderBinder)
    .monthScrollListener { month ->
        // Handle month change
    }

The Calendar library offers a more lightweight and flexible approach, suitable for custom calendar implementations in Android applications. It provides a clean API for binding day and month views, allowing for greater customization of the calendar's appearance and behavior. However, it lacks some of the advanced date-picking features found in react-dates, making it more suitable for simpler calendar display use cases or as a foundation for building custom date selection functionality.

React Native Calendar Components 🗓️ 📆

Pros of react-native-calendars

  • Cross-platform support for both iOS and Android
  • Extensive customization options for calendar appearance
  • Built-in support for various calendar types (e.g., range, agenda)

Cons of react-native-calendars

  • Larger bundle size due to additional features
  • Steeper learning curve for complex customizations
  • Limited support for custom date management libraries

Code Comparison

react-native-calendars:

<Calendar
  onDayPress={(day) => {console.log('selected day', day)}}
  markedDates={{
    '2023-05-16': {selected: true, marked: true, selectedColor: 'blue'}
  }}
/>

Calendar:

val calendar = CalendarView(context)
calendar.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

Both libraries offer robust calendar functionality, but react-native-calendars is more suited for React Native projects with its cross-platform support and extensive customization options. Calendar, on the other hand, is a Kotlin-based library that provides more flexibility for custom date management and potentially better performance for Android-specific projects.

Full-sized drag & drop event calendar in JavaScript

Pros of FullCalendar

  • More comprehensive feature set, including support for various calendar views (month, week, day, list)
  • Extensive documentation and community support
  • Better integration with popular JavaScript frameworks (React, Vue, Angular)

Cons of FullCalendar

  • Larger file size and potentially heavier performance impact
  • Steeper learning curve due to more complex API
  • Commercial license required for some features

Code Comparison

FullCalendar:

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: 'dayGridMonth',
    events: [
      { title: 'Event', start: '2023-05-01' }
    ]
  });
  calendar.render();
});

Calendar:

val calendarView = findViewById<CalendarView>(R.id.calendarView)
calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

Note: Calendar is primarily for Android, while FullCalendar is for web applications, making a direct code comparison challenging. The examples show basic setup for each library in their respective environments.

React Calendar

Pros of Calendar

  • Built specifically for React, offering seamless integration with React applications
  • Provides a wide range of customization options and props for flexibility
  • Supports internationalization out of the box

Cons of Calendar

  • Less actively maintained compared to Calendar, with fewer recent updates
  • Documentation is not as comprehensive or well-organized
  • Limited support for advanced features like custom date ranges or multi-view calendars

Code Comparison

Calendar (react-component):

import Calendar from 'rc-calendar';

<Calendar
  onSelect={this.onSelect}
  disabledDate={disabledDate}
/>

Calendar (kizitonwose):

val calendarView = findViewById<CalendarView>(R.id.calendarView)
calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        // Bind data to the container
    }
}

The Calendar (react-component) example shows a simple React component implementation, while the Calendar (kizitonwose) example demonstrates the Kotlin-based approach with more granular control over day binding and customization.

An elegant calendar and datepicker plugin for Vue.

Pros of v-calendar

  • More comprehensive feature set, including date pickers and custom calendars
  • Better documentation and examples for easier implementation
  • Supports both Vue 2 and Vue 3, offering wider compatibility

Cons of v-calendar

  • Larger bundle size due to more features, potentially impacting performance
  • Steeper learning curve for developers due to its extensive API
  • Less customizable in terms of core calendar layout and structure

Code Comparison

v-calendar:

<v-calendar
  :attributes="attributes"
  @dayclick="onDayClick"
  :is-expanded="false"
  :columns="$screens({ default: 1, lg: 2 })"
/>

Calendar:

val currentMonth = YearMonth.now()
val startDate = currentMonth.minusMonths(10).atStartOfMonth()
val endDate = currentMonth.plusMonths(10).atEndOfMonth()
val daysOfWeek = daysOfWeek()

CalendarView(
    startDate = startDate,
    endDate = endDate,
    daysOfWeek = daysOfWeek
)

Summary

v-calendar offers a more feature-rich solution for Vue.js applications, with better documentation and wider Vue version support. However, it comes at the cost of a larger bundle size and potentially more complex implementation. Calendar, on the other hand, provides a more lightweight and customizable option for Kotlin/Android development, but with a more focused feature set. The choice between the two depends on the specific project requirements, target platform, and desired level of customization.

A datepicker for twitter bootstrap (@twbs)

Pros of bootstrap-datepicker

  • Extensive browser compatibility, including older versions
  • Well-established with a large user base and community support
  • Integrates seamlessly with Bootstrap, providing consistent styling

Cons of bootstrap-datepicker

  • Less modern and flexible compared to Calendar
  • Heavier dependency on jQuery and Bootstrap
  • Limited customization options for advanced use cases

Code Comparison

bootstrap-datepicker:

$('#datepicker').datepicker({
    format: 'mm/dd/yyyy',
    startDate: '-3d'
});

Calendar:

val calendarView = findViewById<CalendarView>(R.id.calendarView)
calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

The code snippets demonstrate the initialization and basic usage of each library. bootstrap-datepicker uses a jQuery-style approach with options, while Calendar employs a more modern, object-oriented pattern with custom binders for flexibility.

bootstrap-datepicker is easier to set up for simple use cases, especially within Bootstrap projects. However, Calendar offers more granular control and a more native feel for Android applications, albeit with a steeper learning curve.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Calendar

A highly customizable calendar library for Android and Compose Multiplatform, backed by RecyclerView for the view system, and LazyRow/LazyColumn for compose.

Tests License Twitter

Android Library Android Library Beta Multiplatform Library Multiplatform Library Alpha

With this library, your calendar will look however you want it to.

Preview

Features

  • Week, month, or year modes - Show a week-based calendar, or the typical month calendar, or a year-based calendar.
  • Single, multiple, or range selection - Total flexibility to implement the date selection whichever way you like.
  • Disable desired dates - Prevent selection of some dates by disabling them.
  • Boundary dates - Limit the calendar date range.
  • Custom date view/composable - Make your day cells look however you want, with any functionality you want.
  • Custom calendar view/composable - Make your calendar look however you want, with whatever functionality you want.
  • Custom first day of the week - Use any day as the first day of the week.
  • Horizontal or vertical scrolling calendar.
  • HeatMap calendar - Suitable for showing how data changes over time, like GitHub's contribution chart.
  • Year/Month/Week headers and footers - Add headers/footers of any kind on each year/month/week.
  • Easily scroll to any date/week/month/year on the calendar via swipe actions or programmatically.
  • Use all RecyclerView/LazyRow/LazyColumn customizations since the calendar extends from RecyclerView for the view system and uses LazyRow/LazyColumn for compose.
  • Design your calendar however you want. The library provides the logic, you provide the views/composables.

Sample project

It's important to check out the sample app. There are lots of examples provided for both view and compose implementations. Most techniques that you would want to implement are already done in the examples.

Download the Android sample app here

View the Android sample app's source code here

View the multiplatform sample project online at https://calendar.kizitonwose.dev

View the multiplatform sample project's source code here

Setup

The library provides two compose artifacts: com.kizitonwose.calendar:compose which uses the java.time APIs for pure Android projects and com.kizitonwose.calendar:compose-multiplatform which uses the kotlinx-datetime library for Compose Multiplatform projects.

The Android view library artifact com.kizitonwose.calendar:view also uses the java.time APIs and can exist alongside the Android compose artifact in an Android project if needed.

Step 1

This step is required ONLY if your Android app's minSdkVersion is below 26. Jump to step 2 if this does not apply to you.

Android apps with minSdkVersion below 26 have to enable Java 8+ API desugaring for backward compatibility since java.time classes were added in Java 8 which is supported natively starting from Android SDK 26. To set up your project for desugaring, you need to first ensure that you are using Android Gradle plugin 4.0.0 or higher.

Then include the following in your app's build.gradle file:

android {
  defaultConfig {
    // Required ONLY if your minSdkVersion is below 21
    multiDexEnabled true
  }

  compileOptions {
    // Enable support for the new language APIs
    coreLibraryDesugaringEnabled true
    // Set Java compatibility (version can be higher if desired)
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  kotlinOptions {
    // Also add this for Kotlin projects (version can be higher if desired)
    jvmTarget = "1.8"
  }
}

dependencies {
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:<latest-version>'
}

You can find the latest version of desugar_jdk_libs here.

Step 2A - For pure Android projects without multiplatform setup

Add the desired calendar library (view or compose) to your app's build.gradle.kts:

dependencies {
  // The view calendar library for Android
  implementation("com.kizitonwose.calendar:view:<latest-version>")

  // The compose calendar library for Android
  implementation("com.kizitonwose.calendar:compose:<latest-version>")
}

Step 2B - For Compose Multiplatform projects

Add the multiplatform calendar library to your project's build.gradle.kts:

commonMain.dependencies {
  implementation("com.kizitonwose.calendar:compose-multiplatform:<latest-version>")
}

You can find the latest version of the library on the maven central badge above.

Snapshots of the development version are available in Sonatype’s snapshots repository.

Compose UI version compatibility

For the compose calendar library, ensure that you are using the library version that matches the Compose UI version in your project. If you use a version of the library that has a higher version of Compose UI than the one in your project, gradle will upgrade the Compose UI version in your project via transitive dependency.

Compose UIAndroid Calendar LibraryMultiplatform Calendar Library
1.2.x2.0.x-
1.3.x2.1.x - 2.2.x-
1.4.x2.3.x-
1.5.x2.4.x-
1.6.x2.5.x2.5.x
1.7.x2.6.x2.6.x

Usage

You can find the relevant documentation for the library in the links below.

View-based documentationCompose documentation

Migration

If you're upgrading from calendar library version 1.x.x to 2.x.x, see the migration guide.

Share your creations

Made a cool calendar with this library? Share an image here.

Contributing

Found a bug? feel free to fix it and send a pull request or open an issue.

License

Calendar library is distributed under the MIT license. See LICENSE for details.