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

[Question] Setting the initial week #80

Closed nikqig closed 5 months ago

nikqig commented 5 months ago

I have a question regarding setting the initial week view based on a selected date.

I noticed the CalendarData class has a weekCameraDate property, which seems to control the starting point of the week view. I'm trying to figure out how to set this property so that the calendar displays the week containing a specific date that the user has selected. In the application, there are two instances where the user interacts with the calendar. Initially, the user selects a date from a monthly calendar view. Later, in a different part of the app, I need to display a weekly calendar view. I want this weekly calendar to open showing the week that includes the previously selected date.

My initial attempt at implementing this functionality. Here's the relevant code snippet:

@Composable
fun CalendarWeek(
    calendarState: UseCaseState,
    calendarViewModel: CalendarViewModel,
    onSelectDate: (LocalDate) -> Unit,
) {
    val danishLocale = Locale("da", "DK") // Danish Locale
    val headerText by calendarViewModel.currentHeaderText.observeAsState("")

    CalendarDialog(
        state = calendarState,
        selection = CalendarSelection.Date(
            selectedDate = calendarViewModel.selectedDate.value, //this 
            onSelectDate = onSelectDate,
            positiveButton = SelectionButton(text = "Vælg"),
            negativeButton = SelectionButton(text = "Annuller"),
            onNegativeClick = { calendarViewModel.resetSelectedEndDate() }
        ),
        header = Header.Custom { CustomCalendarHeader(headerText) },
        config = CalendarConfig(
            locale = danishLocale,
            style = CalendarStyle.WEEK,
        )
    )
}

And here's how I use CalendarWeek:

CalendarWeek(
    calendarState = calendarViewModel.calendarState,
    calendarViewModel = calendarViewModel,
    onSelectDate = { date ->

    }
)

With this implementation, the calendar opens to the correct week based on the selectedDate from calendarViewModel. However, this approach also highlights the selectedDate when the weekly calendar opens, which I would like to avoid. I'd prefer the calendar to open to the week of the selected date without highlighting any specific date.

Again great work! Sorry for spamming you with questions.

maxkeppeler commented 5 months ago

I would like to understand and help. With highlighting, you mean the selectedDate is displayed/ marked as highlighted? But the only way to not highlight them, is to not display any selectedDate. 🤔

maxkeppeler commented 5 months ago

Oh. So currently it's not possible to have a custom camera date. I will support it with the next version. :)