rememberNepaliDatePickerState

fun rememberNepaliDatePickerState(initialSelectedDate: SimpleDate? = null, initialDisplayedMonth: SimpleDate? = initialSelectedDate, yearRange: IntRange = NepaliCalendarDefaults.NepaliYearRange, initialDisplayMode: DisplayMode = DisplayMode.Picker, nepaliSelectableDates: NepaliSelectableDates = NepaliDatePickerDefaults.AllDates, locale: NepaliDateLocale = NepaliDatePickerDefaults.DefaultLocale): NepaliDatePickerState(source)

Creates a NepaliDatePickerState for a NepaliDatePicker that is remembered across compositions.

To create a date picker state outside composition, see the NepaliDatePickerState function.

Parameters

initialSelectedDate

SimpleDate that represents an initial selection of a date. Provide a null to indicate no selection.

initialDisplayedMonth

SimpleDate that represents an initial selection of a month to be displayed to the user. By default, in case an initialSelectedDate is provided, the initial displayed month would be the month of the selected date. Otherwise, in case null is provided, the displayed month would be the current one.

yearRange

an IntRange that holds the year range that the date picker will be limited to

nepaliSelectableDates

a NepaliSelectableDates that is consulted to check if a date is allowed. In case a date is not allowed to be selected, it will appear disabled in the UI. You can checkout helper functions BeforeDateSelectable, AfterDateSelectable, and DateRangeSelectable in NepaliDateConverter.

locale

an instance of NepaliDateLocale that is used to localize the date picker. It holds the preference for the date picker formatted date and the language of the date picker.

Out-of-range or invalid initial values are coerced rather than rejected: the displayed month is clamped into yearRange, and an out-of-range or non-existent initial selected date resolves to no selection.

Example usage:

val defaultNepaliDatePickerState = rememberNepaliDatePickerState()
val customizedDatePickerState =
rememberNepaliDatePickerState(
locale = NepaliDateLocale(language = NepaliDatePickerLang.NEPALI),
nepaliSelectableDates = object : NepaliSelectableDates {
override fun isSelectableDate(customCalendar: CustomCalendar)
: Boolean {
return customCalendar.dayOfWeek != 7
|| customCalendar.dayOfMonth != 12
}

override fun isSelectableYear(year: Int): Boolean {
return (year % 5 != 0)
}
}
)

// Or you can utilize helper function (BeforeDateSelectable or AfterDateSelectable or DateRangeSelectable) to disable and enable dates

val datePickerStateWithDateLimiter =
rememberNepaliDatePickerState(
nepaliSelectableDates = NepaliDatePickerDefaults.BeforeDate(
SimpleDate(2081, 3, 21)
)
)

// For Range, minDate and maxDate should make sense i.e., minDate should be less than or equal to maxDate
val nepaliDatePickerStateWithRangeSelectable = rememberNepaliDatePickerState(
nepaliSelectableDates = DateRangeSelectableDates(
SimpleDate(2081, 2, 11),
SimpleDate(2082, 1, 29)
)
)

NepaliDatePicker(state = defaultNepaliDatePickerState)

NepaliDatePicker(
state = customizedDatePickerState,
colors = NepaliDatePickerDefaults.colors().copy(
containerColor = MaterialTheme.colorScheme.surface
)
)

NepaliDatePicker(state = datePickerStateWithDateLimiter)

NepaliDatePicker(state = nepaliDatePickerStateWithRangeSelectable)