Skip to content

Commit 1e42526

Browse files
committed
Extend DateField with a themeResId to support different picker styles
1 parent e120433 commit 1e42526

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencyResolutionManagement {
2323
2424
2. Add the dependency in your build.gradle file.
2525
```kotlin
26-
implementation 'com.github.benjamin-luescher:compose-form:0.2.0'
26+
implementation 'com.github.benjamin-luescher:compose-form:0.2.1'
2727
```
2828

2929
## Easy example

app/src/main/java/com/edorex/mobile/composeForm/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ fun FormPage() {
108108
label = "End Date",
109109
form = viewModel.form,
110110
fieldState = viewModel.form.endDate,
111+
themeResId = R.style.customDatePickerStyle,
111112
formatter = ::dateLong
112113
).Field()
113114

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="customDatePickerStyle" parent="android:Theme.Material.Dialog.Alert">
4+
<item name="android:datePickerStyle">@style/customDatePicker</item>
5+
</style>
6+
7+
<style name="customDatePicker" parent="@android:style/Widget.Material.Light.DatePicker">
8+
<item name="android:datePickerMode">spinner</item>
9+
<item name="android:calendarViewShown">false</item>
10+
</style>
11+
</resources>

app/src/main/res/values/styles.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="customDatePickerStyle" parent="android:Theme.Material.Light.Dialog.Alert">
4+
<item name="android:datePickerStyle">@style/customDatePicker</item>
5+
</style>
6+
7+
<style name="customDatePicker" parent="@android:style/Widget.Material.Light.DatePicker">
8+
<item name="android:datePickerMode">spinner</item>
9+
<item name="android:calendarViewShown">false</item>
10+
</style>
11+
</resources>

composeform/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ publishing {
6969
release(MavenPublication) {
7070
groupId = 'com.github.benjamin-luescher'
7171
artifactId = 'compose-form'
72-
version = '0.2.0'
72+
version = '0.2.1'
7373

7474
afterEvaluate {
7575
from components.release

composeform/src/main/java/ch/benlu/composeform/fields/DateField.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class DateField(
2424
isVisible: Boolean = true,
2525
isEnabled: Boolean = true,
2626
imeAction: ImeAction = ImeAction.Next,
27-
formatter: ((raw: Date?) -> String)? = null
27+
formatter: ((raw: Date?) -> String)? = null,
28+
private val themeResId: Int = 0
2829
) : Field<Date>(
2930
label = label,
3031
form = form,
@@ -62,6 +63,7 @@ class DateField(
6263
val date = remember { mutableStateOf("") }
6364
val datePickerDialog = DatePickerDialog(
6465
context,
66+
themeResId,
6567
{ _: DatePicker, yyyy: Int, mm: Int, dd: Int ->
6668
val c = Calendar.getInstance()
6769
c.set(yyyy, mm, dd, 0, 0);

0 commit comments

Comments
 (0)