Skip to content

Latest commit

 

History

History
252 lines (193 loc) · 7.17 KB

README.md

File metadata and controls

252 lines (193 loc) · 7.17 KB

CalendarJetpackCompose

A Jetpack Compose Calendar library to easily add calendar functionality to your Android app.

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Contribute
  5. License

Getting Started

Prerequisites

In order to be able to use CalendarJetpackCompose, it requires you to configure your environment to support Jetpack Compose. To do so, you can follow these steps.

Compatibility

CalendarJetpackCompose only works for projects with minumum Android SDKs >= 26.

Installation

In your project build.gradle, add:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

In your module build.gradle, add:

dependencies {
  implementation 'com.github.fvalela1:CalendarJetpackCompose:$version'
}

Usage

Single Month Calendar

Result Source
Screenshot
// defaults to your current year + month
CalendarJetpackCompose() 

Sample: SingleMonthCalendar.kt

Default Calendar With Vertical Padding

Result Source
Screenshot
CalendarJetpackCompose(
    verticalPadding = 10.dp
)

Sample: DefaultWithIncreasedVerticalPaddingCalendar.kt

Default Calendar With Month Navigation

Result Source
Screenshot
CalendarJetpackCompose(
    // true if month nav arrows are visible or not
    canNavigateMonths = true, 
    // function that triggers when a month nav arrow is pressed
    onNavigateMonthPressed = viewModel::updateSelectedMonth, 
    year = year, // year in view
    month = month, // month in view
)

Sample: DefaultWithMonthNavigationCalendar.kt

Custom Month Navigation Arrows

Result Source
Screenshot
CalendarJetpackCompose(
    year = year,
    month = month,
    onNavigateMonthPressed = viewModel::updateSelectedMonth,
    canNavigateMonths = true,
    // add your own drawables to replace the default arrows
    navigateMonthDrawableIds = 
      Pair(
        R.drawable.ic_launcher_background, 
        R.drawable.ic_launcher_foreground
      ), 
)

Sample: CustomMonthNavArrowsCalendar.kt

Selected Dates

The library has a model - CalendarDate.kt - that you can use to customize the selected dates. The model takes in three parameters:

  • dateInMilli: Long - the date in milliseconds from epoch.
  • backgroundColour: Color - the colour of the background when selected.
  • textStyle: TextStyle? - the style of the number (i.e. bold, font, etc...) when it is selected.

The below samples are a showcase of using either a single colour or multiple colours as backgrounds for the selected dates.

convertSelectedDatesToCalendarDates() can be found in any of the samples. updateSelectedDate(newDate: Long) can be found in ViewModel.kt

Select Date with Background Colours

Result: Single Colour Result: Multi Colour
Screenshot
Source
CalendarJetpackCompose(
    year = year,
    month = month,
    selectedDates = convertSelectedDatesToCalendarDates(dates = selectedDates),
    // function to trigger when a day is pressed. Param - date in milliseconds: Long
    onDayPressed = viewModel::updateSelectedDate, 
    onNavigateMonthPressed = viewModel::updateSelectedMonth,
    canNavigateMonths = true,
)

Samples:

Contribute

  1. Ensure your environment supports Jetpack Compose (see Prerequisites).

  2. Clone the repo

    HTTPS

    git clone https://github.com/fvalela1/CalendarJetpackCompose.git

    SSH

    git clone [email protected]:fvalela1/CalendarJetpackCompose.git
  3. Open Android Studio and import the CalendarJetpackCompose project

  4. Make necessary changes

  5. Submit a PR

  6. Eat a slice of cake because you're awesome!

License

Copyright 2020 Francesco Valela

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.