File tree Expand file tree Collapse file tree 7 files changed +41
-10
lines changed
app/src/main/java/com/edorex/mobile/composeForm
src/main/java/ch/benlu/composeform Expand file tree Collapse file tree 7 files changed +41
-10
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ dependencyResolutionManagement {
2323
24242 . Add the dependency in your build.gradle file.
2525``` kotlin
26- implementation ' com.github.benjamin-luescher:compose-form:0.2.2 '
26+ implementation ' com.github.benjamin-luescher:compose-form:0.2.3 '
2727```
2828
2929## Easy example
Original file line number Diff line number Diff line change @@ -95,6 +95,14 @@ fun FormPage() {
9595 fieldState = viewModel.form.country
9696 ).Field ()
9797
98+ PickerField (
99+ modifier = Modifier .padding(bottom = 8 .dp),
100+ label = " Country Not searchable" ,
101+ form = viewModel.form,
102+ fieldState = viewModel.form.countryNotSearchable,
103+ isSearchable = false
104+ ).Field ()
105+
98106 DateField (
99107 modifier = Modifier .padding(bottom = 8 .dp),
100108 label = " Start Date" ,
Original file line number Diff line number Diff line change @@ -75,6 +75,23 @@ class MainForm(resourcesProvider: ResourcesProvider): Form() {
7575 )
7676 )
7777
78+ @FormField
79+ val countryNotSearchable = FieldState (
80+ state = mutableStateOf<Country ?>(null ),
81+ options = mutableListOf (
82+ null ,
83+ Country (code = " CH" , name = " Switzerland" ),
84+ Country (code = " DE" , name = " Germany" )
85+ ),
86+ optionItemFormatter = {
87+ if (it != null ) {
88+ " ${it.name} (${it.code} )"
89+ } else {
90+ " All"
91+ }
92+ }
93+ )
94+
7895 @FormField
7996 val startDate = FieldState (
8097 state = mutableStateOf<Date ?>(null ),
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ publishing {
6969 release(MavenPublication ) {
7070 groupId = ' com.github.benjamin-luescher'
7171 artifactId = ' compose-form'
72- version = ' 0.2.2 '
72+ version = ' 0.2.3 '
7373
7474 afterEvaluate {
7575 from components. release
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ fun <T>RadioButtonComponent(
2323 Modifier
2424 .fillMaxWidth()
2525 .selectable(
26- selected = (( value ? : label) == selectedValue) ,
26+ selected = value == selectedValue,
2727 onClick = {
2828 onClickListener(value)
2929 }
@@ -33,7 +33,7 @@ fun <T>RadioButtonComponent(
3333 modifier = Modifier
3434 .padding(start = 16 .dp)
3535 .align(alignment = Alignment .CenterVertically ),
36- selected = (( value ? : label) == selectedValue) ,
36+ selected = value == selectedValue,
3737 onClick = {
3838 onClickListener(value)
3939 }
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ fun <T> SingleSelectDialogComponent(
2222 optionsList : MutableList <T ?>,
2323 defaultSelected : T ? ,
2424 submitButtonText : String ,
25- onSubmitButtonClick : (T ) -> Unit ,
25+ onSubmitButtonClick : (T ? ) -> Unit ,
2626 onDismissRequest : () -> Unit ,
2727 optionItemFormatter : ((T ? ) -> String )? = null,
2828 search : ((options: MutableList <T ?>, query: String ) -> List <T ?>)? = null
@@ -102,7 +102,7 @@ fun <T> SingleSelectDialogComponent(
102102 Button (
103103 onClick = {
104104 if (selectedOption.value >= 0 && optionsList.size > selectedOption.value) {
105- onSubmitButtonClick.invoke(optionsList[selectedOption.value]!! )
105+ onSubmitButtonClick.invoke(optionsList[selectedOption.value])
106106 }
107107 onDismissRequest.invoke()
108108 },
Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ class PickerField<T: PickerValue>(
2828 isVisible : Boolean = true ,
2929 isEnabled : Boolean = true ,
3030 imeAction : ImeAction = ImeAction .Next ,
31- formatter : ((raw: T ? ) -> String )? = null
31+ formatter : ((raw: T ? ) -> String )? = null ,
32+ private val isSearchable : Boolean = true
3233) : Field<T>(
3334 label = label,
3435 form = form,
@@ -86,10 +87,15 @@ class PickerField<T: PickerValue>(
8687 onDismissRequest = {
8788 isDialogVisible = false
8889 focusManager.clearFocus()
90+ },
91+ search = if (isSearchable) {
92+ { options, query ->
93+ options.filter { c -> c?.searchFilter(query) == true }
94+ }
95+ } else {
96+ null
8997 }
90- ) { options, query ->
91- options.filter { c -> c?.searchFilter(query) == true }
92- }
98+ )
9399 }
94100 }
95101
You can’t perform that action at this time.
0 commit comments