Skip to content

Commit eb00cf8

Browse files
authored
Features/add enabled controls (#36)
* Add isEnabled to pilot switch * add is enabled on picker and textfield
1 parent 84b5d7d commit eb00cf8

9 files changed

Lines changed: 65 additions & 44 deletions

File tree

components/android/material3/src/main/kotlin/com/mirego/pilot/components/ui/material3/PilotPicker.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public fun <LABEL : Any, ITEM : Any> PilotPicker(
3030
labelView: @Composable (label: LABEL) -> Unit,
3131
item: @Composable (item: ITEM) -> Unit,
3232
) {
33+
val isEnabled by pilotPicker.isEnabled.collectAsState()
3334
Box {
3435
Box(
3536
modifier = modifier
3637
.clickable(
38+
enabled = isEnabled,
3739
onClick = { onExpandedChange(!expanded) },
3840
role = Role.DropdownList,
3941
),

components/android/material3/src/main/kotlin/com/mirego/pilot/components/ui/material3/PilotTextField.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public fun PilotTextField(
5050
) {
5151
val textValue by pilotTextField.text.collectAsState()
5252
val placeHolder by pilotTextField.placeholder.collectAsState()
53+
val isEnabledFlow by pilotTextField.isEnabled.collectAsState()
5354
val autoCapitalization by pilotTextField.autoCapitalization.collectAsState()
5455
val autoCorrect by pilotTextField.autoCorrect.collectAsState()
5556
val keyboardType by pilotTextField.keyboardType.collectAsState()
@@ -100,7 +101,7 @@ public fun PilotTextField(
100101
interactionSource = interactionSource,
101102
shape = shape,
102103
colors = colors,
103-
enabled = enabled,
104+
enabled = enabled && isEnabledFlow,
104105
readOnly = readOnly,
105106
singleLine = singleLine,
106107
)

components/common/api/components.api

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ public abstract interface class com/mirego/pilot/components/PilotImageResource {
1515
public abstract fun getName ()Ljava/lang/String;
1616
}
1717

18-
public final class com/mirego/pilot/components/PilotPicker {
18+
public class com/mirego/pilot/components/PilotPicker {
1919
public static final field $stable I
20-
public fun <init> (Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function1;)V
21-
public final fun getItems ()Lkotlinx/coroutines/flow/StateFlow;
22-
public final fun getLabel ()Lkotlinx/coroutines/flow/StateFlow;
23-
public final fun getOnSelectedIndex ()Lkotlin/jvm/functions/Function1;
20+
public fun <init> (Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function1;)V
21+
public synthetic fun <init> (Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
22+
public fun getItems ()Lkotlinx/coroutines/flow/StateFlow;
23+
public fun getLabel ()Lkotlinx/coroutines/flow/StateFlow;
24+
public fun getOnSelectedIndex ()Lkotlin/jvm/functions/Function1;
25+
public fun isEnabled ()Lkotlinx/coroutines/flow/StateFlow;
2426
}
2527

2628
public final class com/mirego/pilot/components/PilotRemoteImage {
@@ -154,31 +156,33 @@ public final class com/mirego/pilot/components/PilotRichTextSpan$Style : com/mir
154156
public fun toString ()Ljava/lang/String;
155157
}
156158

157-
public final class com/mirego/pilot/components/PilotSwitch {
159+
public class com/mirego/pilot/components/PilotSwitch {
158160
public static final field $stable I
159-
public fun <init> (Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)V
160-
public synthetic fun <init> (Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
161-
public final fun getLabel ()Ljava/lang/Object;
162-
public final fun getOnCheckedChange ()Lkotlin/jvm/functions/Function1;
163-
public final fun isOn ()Lkotlinx/coroutines/flow/StateFlow;
161+
public fun <init> (Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function1;)V
162+
public synthetic fun <init> (Lkotlinx/coroutines/flow/StateFlow;Ljava/lang/Object;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
163+
public fun getLabel ()Ljava/lang/Object;
164+
public fun getOnCheckedChange ()Lkotlin/jvm/functions/Function1;
165+
public fun isEnabled ()Lkotlinx/coroutines/flow/StateFlow;
166+
public fun isOn ()Lkotlinx/coroutines/flow/StateFlow;
164167
}
165168

166169
public class com/mirego/pilot/components/PilotTextField {
167170
public static final field $stable I
168-
public fun <init> (Lkotlinx/coroutines/flow/MutableStateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
169-
public synthetic fun <init> (Lkotlinx/coroutines/flow/MutableStateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
170-
public final fun getAutoCapitalization ()Lkotlinx/coroutines/flow/StateFlow;
171-
public final fun getAutoCorrect ()Lkotlinx/coroutines/flow/StateFlow;
172-
public final fun getContentType ()Lkotlinx/coroutines/flow/StateFlow;
173-
public final fun getFormatText ()Lkotlin/jvm/functions/Function1;
174-
public final fun getKeyboardReturnKeyType ()Lkotlinx/coroutines/flow/StateFlow;
175-
public final fun getKeyboardType ()Lkotlinx/coroutines/flow/StateFlow;
176-
public final fun getOnReturnKeyTap ()Lkotlin/jvm/functions/Function0;
177-
public final fun getPlaceholder ()Lkotlinx/coroutines/flow/StateFlow;
171+
public fun <init> (Lkotlinx/coroutines/flow/MutableStateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
172+
public synthetic fun <init> (Lkotlinx/coroutines/flow/MutableStateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlinx/coroutines/flow/StateFlow;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
173+
public fun getAutoCapitalization ()Lkotlinx/coroutines/flow/StateFlow;
174+
public fun getAutoCorrect ()Lkotlinx/coroutines/flow/StateFlow;
175+
public fun getContentType ()Lkotlinx/coroutines/flow/StateFlow;
176+
public fun getFormatText ()Lkotlin/jvm/functions/Function1;
177+
public fun getKeyboardReturnKeyType ()Lkotlinx/coroutines/flow/StateFlow;
178+
public fun getKeyboardType ()Lkotlinx/coroutines/flow/StateFlow;
179+
public fun getOnReturnKeyTap ()Lkotlin/jvm/functions/Function0;
180+
public fun getPlaceholder ()Lkotlinx/coroutines/flow/StateFlow;
178181
public final fun getText ()Lkotlinx/coroutines/flow/StateFlow;
179-
public final fun getTextObfuscationMode ()Lkotlinx/coroutines/flow/StateFlow;
180-
public final fun getTransformText ()Lkotlin/jvm/functions/Function1;
181-
public final fun getUnformatText ()Lkotlin/jvm/functions/Function1;
182+
public fun getTextObfuscationMode ()Lkotlinx/coroutines/flow/StateFlow;
183+
public fun getTransformText ()Lkotlin/jvm/functions/Function1;
184+
public fun getUnformatText ()Lkotlin/jvm/functions/Function1;
185+
public fun isEnabled ()Lkotlinx/coroutines/flow/StateFlow;
182186
public final fun onValueChange (Ljava/lang/String;)V
183187
}
184188

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.mirego.pilot.components
22

3+
import kotlinx.coroutines.flow.MutableStateFlow
34
import kotlinx.coroutines.flow.StateFlow
45

5-
public class PilotPicker<LABEL : Any, ITEM : Any>(
6-
public val label: StateFlow<LABEL>,
7-
public val items: StateFlow<List<ITEM>>,
8-
public val onSelectedIndex: (Int) -> Unit,
6+
public open class PilotPicker<LABEL : Any, ITEM : Any>(
7+
public open val label: StateFlow<LABEL>,
8+
public open val items: StateFlow<List<ITEM>>,
9+
public open val isEnabled: StateFlow<Boolean> = MutableStateFlow(true),
10+
public open val onSelectedIndex: (Int) -> Unit,
911
)
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.mirego.pilot.components
22

3+
import kotlinx.coroutines.flow.MutableStateFlow
34
import kotlinx.coroutines.flow.StateFlow
45

5-
public class PilotSwitch<T : Any>(
6-
public val isOn: StateFlow<Boolean>,
7-
public val label: T,
8-
public val onCheckedChange: (Boolean) -> Unit = {},
6+
public open class PilotSwitch<T : Any>(
7+
public open val isOn: StateFlow<Boolean>,
8+
public open val label: T,
9+
public open val isEnabled: StateFlow<Boolean> = MutableStateFlow(true),
10+
public open val onCheckedChange: (Boolean) -> Unit = {},
911
)

components/common/src/commonMain/kotlin/com/mirego/pilot/components/PilotTextField.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ import kotlinx.coroutines.flow.StateFlow
1010

1111
public open class PilotTextField(
1212
private val textFlow: MutableStateFlow<String>,
13-
public val placeholder: StateFlow<String>,
14-
public val keyboardType: StateFlow<PilotKeyboardType> = MutableStateFlow(PilotKeyboardType.Default),
15-
public val keyboardReturnKeyType: StateFlow<PilotKeyboardReturnKeyType> = MutableStateFlow(PilotKeyboardReturnKeyType.Default),
16-
public val contentType: StateFlow<PilotTextContentType> = MutableStateFlow(PilotTextContentType.NotSet),
17-
public val textObfuscationMode: StateFlow<PilotTextObfuscationMode> = MutableStateFlow(PilotTextObfuscationMode.Visible),
18-
public val autoCorrect: StateFlow<Boolean> = MutableStateFlow(true),
19-
public val autoCapitalization: StateFlow<PilotKeyboardAutoCapitalization> = MutableStateFlow(PilotKeyboardAutoCapitalization.Sentences),
20-
public val onReturnKeyTap: () -> Unit = {},
21-
public val formatText: (text: String) -> String = { it },
22-
public val unformatText: (text: String) -> String = { it },
23-
public val transformText: (text: String) -> String = { it },
13+
public open val placeholder: StateFlow<String>,
14+
public open val isEnabled: StateFlow<Boolean> = MutableStateFlow(true),
15+
public open val keyboardType: StateFlow<PilotKeyboardType> = MutableStateFlow(PilotKeyboardType.Default),
16+
public open val keyboardReturnKeyType: StateFlow<PilotKeyboardReturnKeyType> = MutableStateFlow(PilotKeyboardReturnKeyType.Default),
17+
public open val contentType: StateFlow<PilotTextContentType> = MutableStateFlow(PilotTextContentType.NotSet),
18+
public open val textObfuscationMode: StateFlow<PilotTextObfuscationMode> = MutableStateFlow(PilotTextObfuscationMode.Visible),
19+
public open val autoCorrect: StateFlow<Boolean> = MutableStateFlow(true),
20+
public open val autoCapitalization: StateFlow<PilotKeyboardAutoCapitalization> = MutableStateFlow(PilotKeyboardAutoCapitalization.Sentences),
21+
public open val onReturnKeyTap: () -> Unit = {},
22+
public open val formatText: (text: String) -> String = { it },
23+
public open val unformatText: (text: String) -> String = { it },
24+
public open val transformText: (text: String) -> String = { it },
2425
) {
2526

2627
public val text: StateFlow<String> = textFlow

components/ios/base/PilotPickerView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public struct PilotPickerView<Label, LabelView, Item, ItemView>: View where Labe
99

1010
@ObservedObject private var label: StateObservable<Label>
1111
@ObservedObject private var items: StateObservable<[Item]>
12+
@ObservedObject private var isEnabled: StateObservable<KotlinBoolean>
1213

1314
public init(
1415
_ picker: PilotPicker<Label, Item>,
@@ -21,6 +22,7 @@ public struct PilotPickerView<Label, LabelView, Item, ItemView>: View where Labe
2122

2223
_label = ObservedObject(wrappedValue: StateObservable(picker.label))
2324
_items = ObservedObject(wrappedValue: StateObservable(picker.items))
25+
_isEnabled = ObservedObject(wrappedValue: StateObservable(picker.isEnabled))
2426
}
2527

2628
public var body: some View {
@@ -35,5 +37,6 @@ public struct PilotPickerView<Label, LabelView, Item, ItemView>: View where Labe
3537
} label: {
3638
labelBuilder(label.value)
3739
}
40+
.disabled(!isEnabled.value.boolValue)
3841
}
3942
}

components/ios/base/PilotSwitchView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ public struct PilotSwitchView<Content, Label>: View where Content: AnyObject, La
66
private let labelBuilder: (Content) -> Label
77

88
@ObservedObject private var isOn: StateObservable<KotlinBoolean>
9+
@ObservedObject private var isEnabled: StateObservable<KotlinBoolean>
910

1011
public init(_ pilotSwitch: PilotSwitch<Content>, labelBuilder: @escaping (Content) -> Label) {
1112
self.pilotSwitch = pilotSwitch
1213
self.labelBuilder = labelBuilder
1314
_isOn = ObservedObject(wrappedValue: StateObservable(pilotSwitch.isOn))
15+
_isEnabled = ObservedObject(wrappedValue: StateObservable(pilotSwitch.isEnabled))
1416
}
1517

1618
public var body: some View {
@@ -25,5 +27,6 @@ public struct PilotSwitchView<Content, Label>: View where Content: AnyObject, La
2527
) {
2628
labelBuilder(pilotSwitch.label)
2729
}
30+
.disabled(!isEnabled.value.boolValue)
2831
}
2932
}

components/ios/base/PilotTextFieldView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public struct PilotTextFieldView<Label>: View where Label: View {
77

88
@ObservedObject private var text: StateObservable<String>
99
@ObservedObject private var placeholder: StateObservable<String>
10+
@ObservedObject private var isEnabled: StateObservable<KotlinBoolean>
1011
@ObservedObject private var keyboardType: StateObservable<PilotKeyboardType>
1112
@ObservedObject private var keyboardReturnKeyType: StateObservable<PilotKeyboardReturnKeyType>
1213
@ObservedObject private var contentType: StateObservable<PilotTextContentType>
@@ -28,6 +29,7 @@ public struct PilotTextFieldView<Label>: View where Label: View {
2829

2930
_text = ObservedObject(wrappedValue: StateObservable(pilotTextField.text))
3031
_placeholder = ObservedObject(wrappedValue: StateObservable(pilotTextField.placeholder))
32+
_isEnabled = ObservedObject(wrappedValue: StateObservable(pilotTextField.isEnabled))
3133
_keyboardType = ObservedObject(wrappedValue: StateObservable(pilotTextField.keyboardType))
3234
_keyboardReturnKeyType = ObservedObject(wrappedValue: StateObservable(pilotTextField.keyboardReturnKeyType))
3335
_contentType = ObservedObject(wrappedValue: StateObservable(pilotTextField.contentType))
@@ -50,6 +52,7 @@ public struct PilotTextFieldView<Label>: View where Label: View {
5052
.textContentType(contentType.value.uiTextContentType)
5153
#endif
5254
.disableAutocorrection(!autoCorrect.value.boolValue)
55+
.disabled(!isEnabled.value.boolValue)
5356
.textFieldStyle(ExtendedTapAreaTextFieldStyle())
5457
.onChange(of: text.value) { newValue in
5558
textFieldText = pilotTextField.formatText(newValue)

0 commit comments

Comments
 (0)