Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] DEFAULT_RANGE is internal and cannot be used when creating composable functions #44

Closed
Nek-12 opened this issue Mar 26, 2023 · 4 comments

Comments

@Nek-12
Copy link

Nek-12 commented Mar 26, 2023

Constants.DEFAULT_RANGE is internal, as such, it cannot be used to create composables which wrap the CalendarDialog.

Sample:


@Composable
fun calendarDialog(
    title: String?,
    style: CalendarStyle,
    dateRange: ClosedRange<LocalDate>? = null,
    onSelectDate: (LocalDate) -> Unit,
    initialDate: LocalDate = LocalDate.now(TimeZone.currentSystemDefault()),
): UseCaseState {
    val state = rememberUseCaseState()

    CalendarDialog(
        state = state,
        selection = remember(initialDate) {
            CalendarSelection.Date(
                withButtonView = true,
                selectedDate = initialDate.toJavaLocalDate(),
            ) { onSelectDate(it.toKotlinLocalDate()) }
        },
        config = remember(style, dateRange) {
            CalendarConfig(
                style = style,
                monthSelection = true,
                yearSelection = true,
                boundary = dateRange ?: DEFAULT_RANGE,
                icons = LibIcons.Rounded,
            )
        },
        header = remember(title) { title?.let { Header.Default(title = it) } },
        properties = DialogProperties(),
    )
    return state
}
@maxkeppeler
Copy link
Owner

I don't see any issue here. You can define your own default range and utilize it for both the CalendarDialog and your wrapper composable function. If the standard range needs to remain the same, you can easily copy and paste it those constants, allowing you thus easily to change the range if desired. I will keep the constant files and the respective constants internal.
Why would you define the state inside your wrapper function instead of passing it along?

@Nek-12
Copy link
Author

Nek-12 commented Mar 27, 2023

Alright, I see. For now I used the approach you suggested, just thought you would consider providing sensible defaults for people to use, however user-defined-defaults work too
I'm making these helper functions for the dialogs because I want to streamline the process of composing and showing the dialog. I've noticed that all of the usecases I've encountered involve declaring the state and immediately calling the Dialog composable, so I've merged those operations together. I'm passing the state as a return value of the function and using it later in the parent composable.

P.S. Github is experiencing serious issues :D

@Nek-12

This comment was marked as duplicate.

1 similar comment
@Nek-12

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants