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

Feature/add readme #16

Merged
merged 11 commits into from
Oct 16, 2022
Prev Previous commit
Next Next commit
Add README for time picker.
  • Loading branch information
marosseleng committed Oct 13, 2022
commit aba26ce2c7fd5d74946df0c69b6a39dd1e7a5d53
9 changes: 0 additions & 9 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added README.md
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.marosseleng.compose.material3.datetimepickers.time.domain.TimePickerC
import com.marosseleng.compose.material3.datetimepickers.time.domain.TimePickerDefaults
import com.marosseleng.compose.material3.datetimepickers.time.domain.TimePickerShapes
import com.marosseleng.compose.material3.datetimepickers.time.domain.TimePickerTypography
import com.marosseleng.compose.material3.datetimepickers.time.domain.noSeconds
import com.marosseleng.compose.material3.datetimepickers.time.ui.TimePicker
import java.time.LocalTime

Expand All @@ -40,7 +41,7 @@ public fun TimePickerDialog(
onDismissRequest: () -> Unit,
onTimeChange: (LocalTime) -> Unit,
modifier: Modifier = Modifier,
initialTime: LocalTime = LocalTime.now(),
initialTime: LocalTime = LocalTime.now().noSeconds(),
colors: TimePickerColors = TimePickerDefaults.colors,
shapes: TimePickerShapes = TimePickerDefaults.shapes,
typography: TimePickerTypography = TimePickerDefaults.typography,
Expand Down
59 changes: 59 additions & 0 deletions docs/timepicker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Time picker

A highly customizable time picker for Jetpack Compose. Material3 theme-compatible.
![demo-video](resources/timepicker-demo.webm)

## Usage

A base composable `fun TimePicker()` displays the time picker. It is recommended to wrap the time picker in an `(Alert)Dialog` composable.

An example of such usage can be seen in `fun TimePickerDialog()`.

There are 2 mandatory parameters for `TimePickerDialog`:

- `onDismissRequest`: called when user wants to dismiss the dialog without selecting the time;
- `onTimeChange`: called when user taps the confirmation button, the parameter is the `LocalTime` representing the selected time.

Example of `TimePickerDialog` usage:

```kotlin
var isDialogShown: Boolean by rememberSaveable {
mutableStateOf(false)
}
val (selectedTime, setSelectedTime) = rememberSaveable {
mutableStateOf(LocalTime.now().noSeconds())
}
if (isDialogShown) {
TimePickerDialog(
onDismissRequest = { isDialogShown = false },
initialTime = selectedTime,
onTimeChange = {
setSelectedTime(it)
isDialogShown = false
},
title = { Text(text = "Select time") }
)
}
```

## Customization
The time picker is a highly customizable component. It allows to customize colors, shapes and typography.
You can pass custom shapes of the digit-box as well as the AM/PM box:

_It is not recommended to pass an anonymous instance of `TimePickerShapes`. Instead, create an implementation separately and use that to prevent creating a new instance each time the component is recomposed._

```kotlin
TimePickerDialog(
// ...
shapes = object : TimePickerShapes {
override val clockDigitsShape: Shape
get() = CutCornerShape(topStart = 16.dp, topEnd = 3.dp, bottomStart = 0.dp, bottomEnd = 24.dp)
override val amPmSwitchShape: Shape
get() = CircleShape
}
)
```
produces
![custom-shapes](resources/time-picker-day-custom-shapes.png)

For default values see [TimePickerDefaults](../../datetimepickers/src/main/java/com/marosseleng/compose/material3/datetimepickers/time/domain/TimePickerDefaults.kt).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/timepicker/resources/time-picker-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/timepicker/resources/time-picker-night.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.