maxkeppeler / sheets-compose-dialogs

✨ Enhancing Android UIs: A Jetpack Compose Library supporting a wide range of common use-cases with Material Design 3 Dialogs, Popups, and Bottom Sheets. ✨
https://maxkeppeler.github.io/sheets-compose-dialogs/
Apache License 2.0
780 stars 32 forks source link

Prevent user from picking Future Dates with disabledDates CalendarConfig parameter #48

Closed Tonnie-Dev closed 1 year ago

Tonnie-Dev commented 1 year ago

In the CalendarConfig constructor, there is disabledDates parameter. How can you use it to prevent user from selecting future dates?

Before version 1.1.1 we used a constant - something like this ....

disabledTimeline = CalendarTimeline.FUTURE

However, this is not being resolved on my end when I upgrade to **version 1.1.1*** error

I see the disabledDates takes a list of LocalDates so I came up with this work-around but it is not helping.

val startRange = LocalDate.now().minusYears(10) // allow dates up to 1 year in the past
    val disabledDates = startRange..LocalDate.now()
    val disabledDatesList = disabledDates.toList

I will appreciate any leads to hack this.

Cheers.

maxkeppeler commented 1 year ago

Hi Tonnie,

I wanted to inform you that CalendarTimeline has been discontinued. However, defining the date boundaries for display has become much simpler.

Below is an example that uses a local date range:

Copy code
val boundary = LocalDate.now().minusYears(1)..LocalDate.now()
CalendarDialog(
    ...
    config = CalendarConfig(
        boundary = boundary,
        ...
    ),
    ...
)

With this code, only dates from one year ago to the present day will be displayed.

Let me know if you have any questions & feel free to showcase your app in the README when using the library.

Tonnie-Dev commented 1 year ago

Wow, thanks Max,

Was using disabledDates instead of boundary

Many thanks for clarifying.