@momo-kits/native-kits 0.160.1-searchBackground.3-debug → 0.160.1-searchBackground.5-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compose/build.gradle.kts +1 -1
- package/compose/compose.podspec +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +2 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +6 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +4 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +5 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +5 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +19 -14
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +14 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +11 -7
- package/gradle.properties +1 -1
- package/ios/Input/Input.swift +33 -4
- package/package.json +1 -1
package/compose/build.gradle.kts
CHANGED
package/compose/compose.podspec
CHANGED
|
@@ -70,13 +70,14 @@ actual fun getScreenHeight(): Dp {
|
|
|
70
70
|
return getScreenDimensions().height.dp + if (getOSVersion() >= 35) 0.dp else AppStatusBar.current + AppNavigationBar.current
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
actual fun getOSVersion():
|
|
73
|
+
actual fun getOSVersion(): OSVersion = OSVersion.Android(sdk = Build.VERSION.SDK_INT)
|
|
74
74
|
|
|
75
75
|
@Composable
|
|
76
76
|
actual fun LottieAnimation(
|
|
77
77
|
path: String,
|
|
78
78
|
tintColor: Color?,
|
|
79
79
|
bgColor: Color?,
|
|
80
|
+
placedAsOverlay: Boolean,
|
|
80
81
|
modifier: Modifier
|
|
81
82
|
) {
|
|
82
83
|
val json = readJson(path)
|
|
@@ -63,6 +63,7 @@ import androidx.compose.ui.platform.LocalDensity
|
|
|
63
63
|
import androidx.compose.ui.platform.LocalFocusManager
|
|
64
64
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
65
65
|
import androidx.compose.ui.text.style.TextOverflow
|
|
66
|
+
import androidx.compose.ui.text.TextStyle
|
|
66
67
|
import androidx.compose.ui.unit.Constraints
|
|
67
68
|
import androidx.compose.ui.unit.Dp
|
|
68
69
|
import androidx.compose.ui.unit.IntOffset
|
|
@@ -300,7 +301,7 @@ private fun LiteScreenHeader(
|
|
|
300
301
|
color = headerColor.borderColor,
|
|
301
302
|
shape = CircleShape,
|
|
302
303
|
)
|
|
303
|
-
|
|
304
|
+
.background(color = headerColor.backgroundButton)
|
|
304
305
|
}
|
|
305
306
|
.noFeedbackClickable(onClick = onGoBack)
|
|
306
307
|
.setAutomationId("btn_navigation_back")
|
|
@@ -522,11 +523,11 @@ data class LiteInputSearchProps(
|
|
|
522
523
|
val disabled: Boolean = false,
|
|
523
524
|
|
|
524
525
|
val placeHolder: String? = null,
|
|
525
|
-
|
|
526
|
+
|
|
526
527
|
val customBackIcon: @Composable (() -> Unit)? = null,
|
|
527
528
|
val customSearchIcon: @Composable (() -> Unit)? = null,
|
|
528
529
|
val customPlaceHolder: @Composable (() -> Unit)? = null,
|
|
529
|
-
|
|
530
|
+
val customTextStyle: TextStyle? = null,
|
|
530
531
|
val iconRightTextField: @Composable ((Modifier) -> Unit)? = null,
|
|
531
532
|
)
|
|
532
533
|
|
|
@@ -568,7 +569,6 @@ private fun LiteInputSearch(
|
|
|
568
569
|
val textFieldModifier = remember(inputSearchProps.modifier) {
|
|
569
570
|
inputSearchProps.modifier
|
|
570
571
|
.weight(1f)
|
|
571
|
-
.sizeIn(minHeight = 36.dp)
|
|
572
572
|
}
|
|
573
573
|
BasicTextField(
|
|
574
574
|
value = textState,
|
|
@@ -577,7 +577,7 @@ private fun LiteInputSearch(
|
|
|
577
577
|
keyboardOptions = inputSearchProps.keyboardOptions,
|
|
578
578
|
keyboardActions = inputSearchProps.keyboardActions,
|
|
579
579
|
modifier = textFieldModifier,
|
|
580
|
-
textStyle = inputFieldStyle,
|
|
580
|
+
textStyle = inputSearchProps.customTextStyle ?: inputFieldStyle,
|
|
581
581
|
singleLine = true,
|
|
582
582
|
interactionSource = interactionSource,
|
|
583
583
|
decorationBox = { innerTextField ->
|
|
@@ -615,10 +615,6 @@ private fun LiteInputSearch(
|
|
|
615
615
|
|
|
616
616
|
Row(
|
|
617
617
|
modifier = Modifier
|
|
618
|
-
.background(
|
|
619
|
-
color = theme.colors.background.surface,
|
|
620
|
-
shape = RoundedCornerShape(Radius.XL),
|
|
621
|
-
)
|
|
622
618
|
.padding(
|
|
623
619
|
horizontal = Spacing.M,
|
|
624
620
|
vertical = Spacing.S,
|
|
@@ -639,7 +635,7 @@ private fun LiteInputSearch(
|
|
|
639
635
|
if (!placeHolder.isNullOrEmpty()) {
|
|
640
636
|
inputSearchProps.customPlaceHolder?.invoke() ?: Text(
|
|
641
637
|
text = placeHolder ?: "",
|
|
642
|
-
style = Typography.bodyDefaultRegular,
|
|
638
|
+
style = inputSearchProps.customTextStyle ?: Typography.bodyDefaultRegular,
|
|
643
639
|
maxLines = 1,
|
|
644
640
|
color = theme.colors.text.hint,
|
|
645
641
|
overflow = TextOverflow.Ellipsis
|
|
@@ -59,8 +59,9 @@ import vn.momo.kits.modifier.DeprecatedModifier
|
|
|
59
59
|
import vn.momo.kits.modifier.conditional
|
|
60
60
|
import vn.momo.kits.modifier.shadow
|
|
61
61
|
import vn.momo.kits.navigation.component.SnackBar
|
|
62
|
-
import vn.momo.kits.platform.
|
|
62
|
+
import vn.momo.kits.platform.supportsImePadding
|
|
63
63
|
import vn.momo.kits.utils.getAppStatusBarHeight
|
|
64
|
+
import vn.momo.kits.utils.getNavigationBarHeight
|
|
64
65
|
|
|
65
66
|
enum class HeaderType {
|
|
66
67
|
DEFAULT,
|
|
@@ -102,7 +103,7 @@ fun Screen(
|
|
|
102
103
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
103
104
|
|
|
104
105
|
val isKeyboardVisible = isKeyboardVisible()
|
|
105
|
-
val indicator =
|
|
106
|
+
val indicator = getNavigationBarHeight()
|
|
106
107
|
val bottomPadding = if (isKeyboardVisible) 0.dp else indicator
|
|
107
108
|
|
|
108
109
|
val headerHeight = if (animatedHeader !== null)
|
|
@@ -134,7 +135,7 @@ fun Screen(
|
|
|
134
135
|
Box(
|
|
135
136
|
Modifier.fillMaxSize()
|
|
136
137
|
.background(backgroundColor ?: AppTheme.current.colors.background.default)
|
|
137
|
-
.conditional(useAvoidKeyboard &&
|
|
138
|
+
.conditional(useAvoidKeyboard && supportsImePadding()) {
|
|
138
139
|
imePadding()
|
|
139
140
|
}.then(DeprecatedModifier())
|
|
140
141
|
) {
|
|
@@ -221,6 +221,7 @@ fun Input(
|
|
|
221
221
|
onBlur: () -> Unit = {},
|
|
222
222
|
loading: Boolean = false,
|
|
223
223
|
required: Boolean = false,
|
|
224
|
+
maxLength: Int? = null,
|
|
224
225
|
fontWeight: InputFontWeight = InputFontWeight.REGULAR,
|
|
225
226
|
keyboardType: KeyboardType = KeyboardType.Text,
|
|
226
227
|
modifier: Modifier = Modifier,
|
|
@@ -319,7 +320,10 @@ fun Input(
|
|
|
319
320
|
onBlur()
|
|
320
321
|
}
|
|
321
322
|
},
|
|
322
|
-
onValueChange =
|
|
323
|
+
onValueChange = { newText ->
|
|
324
|
+
val limitedText = maxLength?.let { newText.take(it) } ?: newText
|
|
325
|
+
onChangeText(limitedText)
|
|
326
|
+
},
|
|
323
327
|
decorationBox = { innerTextField ->
|
|
324
328
|
// Floating label
|
|
325
329
|
if (floatingValue.isNotEmpty() || floatingIcon.isNotEmpty()) {
|
|
@@ -8,6 +8,7 @@ import androidx.compose.animation.core.rememberInfiniteTransition
|
|
|
8
8
|
import androidx.compose.animation.core.tween
|
|
9
9
|
import androidx.compose.foundation.background
|
|
10
10
|
import androidx.compose.foundation.border
|
|
11
|
+
import androidx.compose.ui.draw.alpha
|
|
11
12
|
import androidx.compose.foundation.clickable
|
|
12
13
|
import androidx.compose.foundation.layout.Arrangement
|
|
13
14
|
import androidx.compose.foundation.layout.Box
|
|
@@ -129,8 +130,11 @@ fun InputOTP(
|
|
|
129
130
|
if (!it.isFocused && isBlurred) onBlur()
|
|
130
131
|
if (it.isFocused && !isBlurred) isBlurred = true
|
|
131
132
|
},
|
|
132
|
-
decorationBox = {
|
|
133
|
+
decorationBox = { innerTextField ->
|
|
133
134
|
Box {
|
|
135
|
+
Box(
|
|
136
|
+
modifier = Modifier.fillMaxWidth().height(56.dp).alpha(0f)
|
|
137
|
+
) { innerTextField() }
|
|
134
138
|
if (floatingValue.isNotEmpty()) {
|
|
135
139
|
Box(
|
|
136
140
|
modifier = Modifier.wrapContentSize()
|
|
@@ -105,6 +105,8 @@ data class InputSearchProps(
|
|
|
105
105
|
val iconModifier: Modifier = Modifier,
|
|
106
106
|
val onClearPress: () -> Unit = {},
|
|
107
107
|
val leftPosition: Dp? = null,
|
|
108
|
+
val placeholderCustomRender: (@Composable () -> Unit)? = null,
|
|
109
|
+
val searchIcon: (@Composable () -> Unit)? = null
|
|
108
110
|
)
|
|
109
111
|
|
|
110
112
|
@Composable
|
|
@@ -145,12 +147,13 @@ fun InputSearch(
|
|
|
145
147
|
)
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
Row(
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
Row(
|
|
151
|
+
verticalAlignment = Alignment.CenterVertically, modifier = Modifier
|
|
152
|
+
.fillMaxWidth()
|
|
153
|
+
.height(36.dp)
|
|
154
|
+
.conditional(IsShowBaseLineDebug) {
|
|
155
|
+
border(1.dp, Colors.blue_03)
|
|
156
|
+
}
|
|
154
157
|
) {
|
|
155
158
|
BasicTextField(
|
|
156
159
|
enabled = !inputSearchProps.disabled,
|
|
@@ -184,13 +187,14 @@ fun InputSearch(
|
|
|
184
187
|
horizontalArrangement = Arrangement.Start,
|
|
185
188
|
verticalAlignment = Alignment.CenterVertically
|
|
186
189
|
) {
|
|
190
|
+
|
|
187
191
|
Row(
|
|
188
192
|
modifier = Modifier.padding(
|
|
189
193
|
horizontal = Spacing.M
|
|
190
194
|
),
|
|
191
195
|
verticalAlignment = Alignment.CenterVertically
|
|
192
196
|
) {
|
|
193
|
-
Icon(
|
|
197
|
+
inputSearchProps.searchIcon?.invoke() ?: Icon(
|
|
194
198
|
source = "navigation_search",
|
|
195
199
|
modifier = Modifier.padding(end = Spacing.XS),
|
|
196
200
|
size = 24.dp,
|
|
@@ -198,13 +202,14 @@ fun InputSearch(
|
|
|
198
202
|
)
|
|
199
203
|
Box(Modifier.weight(1f)) {
|
|
200
204
|
if (inputSearchProps.text.value.isEmpty()) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
inputSearchProps.placeholderCustomRender?.invoke()
|
|
206
|
+
?: Text(
|
|
207
|
+
text = inputSearchProps.placeholder,
|
|
208
|
+
style = placeHolderStyle,
|
|
209
|
+
maxLines = 1,
|
|
210
|
+
color = placeholderColor,
|
|
211
|
+
overflow = TextOverflow.Ellipsis
|
|
212
|
+
)
|
|
208
213
|
}
|
|
209
214
|
innerTextField()
|
|
210
215
|
}
|
|
@@ -62,7 +62,7 @@ import vn.momo.kits.navigation.component.HeaderRight
|
|
|
62
62
|
import vn.momo.kits.navigation.component.HeaderType
|
|
63
63
|
import vn.momo.kits.navigation.component.InputSearchType
|
|
64
64
|
import vn.momo.kits.platform.BackHandler
|
|
65
|
-
import vn.momo.kits.platform.
|
|
65
|
+
import vn.momo.kits.platform.supportsImePadding
|
|
66
66
|
import vn.momo.kits.navigation.tracking.ScreenTracker
|
|
67
67
|
import vn.momo.kits.navigation.tracking.ScreenTrackingState
|
|
68
68
|
import kotlinx.coroutines.delay
|
|
@@ -166,7 +166,7 @@ internal fun StackScreen(
|
|
|
166
166
|
.conditional(options.keyboardOptions.keyboardShouldPersistTaps) {
|
|
167
167
|
hideKeyboardOnTap()
|
|
168
168
|
}
|
|
169
|
-
.conditional(options.keyboardOptions.useAvoidKeyboard &&
|
|
169
|
+
.conditional(options.keyboardOptions.useAvoidKeyboard && supportsImePadding()) {
|
|
170
170
|
imePadding()
|
|
171
171
|
}
|
|
172
172
|
) {
|
|
@@ -30,13 +30,26 @@ expect fun ProvideNavigationEventDispatcherOwner(content: @Composable () -> Unit
|
|
|
30
30
|
@Composable
|
|
31
31
|
expect fun getScreenHeight(): Dp
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
sealed interface OSVersion {
|
|
34
|
+
val value: Int
|
|
35
|
+
data class Android(val sdk: Int) : OSVersion { override val value: Int get() = sdk }
|
|
36
|
+
data class IOS(val major: Int) : OSVersion { override val value: Int get() = major }
|
|
37
|
+
|
|
38
|
+
operator fun compareTo(other: Int): Int = value.compareTo(other)
|
|
39
|
+
}
|
|
40
|
+
expect fun getOSVersion(): OSVersion
|
|
41
|
+
|
|
42
|
+
fun supportsImePadding(): Boolean = when (val v = getOSVersion()) {
|
|
43
|
+
is OSVersion.Android -> v.sdk > 29
|
|
44
|
+
is OSVersion.IOS -> true
|
|
45
|
+
}
|
|
34
46
|
|
|
35
47
|
@Composable
|
|
36
48
|
expect fun LottieAnimation(
|
|
37
49
|
path: String,
|
|
38
50
|
tintColor: Color? = null,
|
|
39
51
|
bgColor: Color? = null,
|
|
52
|
+
placedAsOverlay: Boolean = false,
|
|
40
53
|
modifier: Modifier = Modifier
|
|
41
54
|
)
|
|
42
55
|
|
|
@@ -12,17 +12,19 @@ import androidx.compose.runtime.getValue
|
|
|
12
12
|
import androidx.compose.runtime.mutableStateOf
|
|
13
13
|
import androidx.compose.runtime.remember
|
|
14
14
|
import androidx.compose.runtime.setValue
|
|
15
|
+
import androidx.compose.ui.ExperimentalComposeUiApi
|
|
15
16
|
import androidx.compose.ui.InternalComposeUiApi
|
|
16
17
|
import androidx.compose.ui.Modifier
|
|
17
18
|
import androidx.compose.ui.backhandler.LocalCompatNavigationEventDispatcherOwner
|
|
18
19
|
import androidx.compose.ui.graphics.Color
|
|
19
20
|
import androidx.compose.ui.graphics.NativePaint
|
|
20
21
|
import androidx.compose.ui.graphics.toArgb
|
|
21
|
-
import androidx.compose.ui.interop.UIKitView
|
|
22
22
|
import androidx.compose.ui.semantics.SemanticsPropertyKey
|
|
23
23
|
import androidx.compose.ui.semantics.semantics
|
|
24
24
|
import androidx.compose.ui.unit.Dp
|
|
25
25
|
import androidx.compose.ui.unit.dp
|
|
26
|
+
import androidx.compose.ui.viewinterop.UIKitInteropProperties
|
|
27
|
+
import androidx.compose.ui.viewinterop.UIKitView
|
|
26
28
|
import cocoapods.lottie_ios.CompatibleAnimation
|
|
27
29
|
import cocoapods.lottie_ios.CompatibleAnimationKeypath
|
|
28
30
|
import cocoapods.lottie_ios.CompatibleAnimationView
|
|
@@ -85,16 +87,17 @@ actual fun getScreenHeight(): Dp {
|
|
|
85
87
|
return getScreenDimensions().height.dp
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
actual fun getOSVersion():
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
actual fun getOSVersion(): OSVersion = OSVersion.IOS(
|
|
91
|
+
major = UIDevice.currentDevice.systemVersion.substringBefore(".").toIntOrNull() ?: 0
|
|
92
|
+
)
|
|
91
93
|
|
|
92
|
-
@OptIn(ExperimentalForeignApi::class)
|
|
94
|
+
@OptIn(ExperimentalForeignApi::class, ExperimentalComposeUiApi::class)
|
|
93
95
|
@Composable
|
|
94
96
|
actual fun LottieAnimation(
|
|
95
97
|
path: String,
|
|
96
98
|
tintColor: Color?,
|
|
97
99
|
bgColor: Color?,
|
|
100
|
+
placedAsOverlay: Boolean,
|
|
98
101
|
modifier: Modifier
|
|
99
102
|
) {
|
|
100
103
|
var animation by remember { mutableStateOf<CompatibleAnimation?>(null) }
|
|
@@ -112,11 +115,12 @@ actual fun LottieAnimation(
|
|
|
112
115
|
Box(modifier) {
|
|
113
116
|
UIKitView(
|
|
114
117
|
modifier = Modifier.fillMaxSize(),
|
|
118
|
+
properties = UIKitInteropProperties(placedAsOverlay = placedAsOverlay),
|
|
115
119
|
factory = {
|
|
116
120
|
CompatibleAnimationView(value).apply {
|
|
117
121
|
translatesAutoresizingMaskIntoConstraints = true
|
|
118
122
|
|
|
119
|
-
setBackgroundColor(bgColor?.toUIColor() ?: UIColor.
|
|
123
|
+
setBackgroundColor(bgColor?.toUIColor() ?: UIColor.clearColor)
|
|
120
124
|
|
|
121
125
|
setLoopAnimationCount(-1.0)
|
|
122
126
|
setAnimationSpeed(1.0)
|
|
@@ -137,7 +141,7 @@ actual fun LottieAnimation(
|
|
|
137
141
|
},
|
|
138
142
|
|
|
139
143
|
update = { view ->
|
|
140
|
-
view.setBackgroundColor(bgColor?.toUIColor() ?: UIColor.
|
|
144
|
+
view.setBackgroundColor(bgColor?.toUIColor() ?: UIColor.clearColor)
|
|
141
145
|
|
|
142
146
|
if (tintColor != null) {
|
|
143
147
|
val uiColor = tintColor.toUIColor()
|
package/gradle.properties
CHANGED
package/ios/Input/Input.swift
CHANGED
|
@@ -22,6 +22,7 @@ public struct Input: View {
|
|
|
22
22
|
public var leadingIconColor: Color
|
|
23
23
|
public var loading: Bool
|
|
24
24
|
public var required: Bool
|
|
25
|
+
public var maxLength: Int?
|
|
25
26
|
public var fontWeight: InputFontWeight
|
|
26
27
|
public var keyboardType: UIKeyboardType
|
|
27
28
|
public var autofocus: Bool
|
|
@@ -52,6 +53,7 @@ public struct Input: View {
|
|
|
52
53
|
leadingIconColor: Color = Colors.black12,
|
|
53
54
|
loading: Bool = false,
|
|
54
55
|
required: Bool = false,
|
|
56
|
+
maxLength: Int? = nil,
|
|
55
57
|
fontWeight: InputFontWeight = .regular,
|
|
56
58
|
keyboardType: UIKeyboardType = .default,
|
|
57
59
|
autofocus: Bool = false,
|
|
@@ -78,6 +80,7 @@ public struct Input: View {
|
|
|
78
80
|
self.leadingIconColor = leadingIconColor
|
|
79
81
|
self.loading = loading
|
|
80
82
|
self.required = required
|
|
83
|
+
self.maxLength = maxLength
|
|
81
84
|
self.fontWeight = fontWeight
|
|
82
85
|
self.keyboardType = keyboardType
|
|
83
86
|
self.autofocus = autofocus
|
|
@@ -93,10 +96,10 @@ public struct Input: View {
|
|
|
93
96
|
get: { self.text },
|
|
94
97
|
set: { newValue in
|
|
95
98
|
self.text = newValue
|
|
96
|
-
self.onChangeText?(newValue)
|
|
99
|
+
self.onChangeText?(limitText(newValue))
|
|
97
100
|
}
|
|
98
101
|
)
|
|
99
|
-
|
|
102
|
+
|
|
100
103
|
VStack(alignment: .leading, spacing: 4) {
|
|
101
104
|
ZStack(alignment: .topLeading) {
|
|
102
105
|
// Floating label
|
|
@@ -142,6 +145,7 @@ public struct Input: View {
|
|
|
142
145
|
fontWeight: fontWeight == .bold ? .bold : .regular,
|
|
143
146
|
textColor: UIColor(getTextColor()),
|
|
144
147
|
isDisabled: disabled || readOnly,
|
|
148
|
+
maxLength: maxLength,
|
|
145
149
|
onFocusChange: { focused in
|
|
146
150
|
handleFocusChange(focused)
|
|
147
151
|
},
|
|
@@ -156,6 +160,12 @@ public struct Input: View {
|
|
|
156
160
|
.foregroundColor(getTextColor())
|
|
157
161
|
.disabled(disabled || readOnly)
|
|
158
162
|
.applyPrimaryCursorColor()
|
|
163
|
+
.onChange(of: text) { newValue in
|
|
164
|
+
let limited = limitText(newValue)
|
|
165
|
+
if limited != newValue {
|
|
166
|
+
text = limited
|
|
167
|
+
}
|
|
168
|
+
}
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
|
|
@@ -239,6 +249,13 @@ public struct Input: View {
|
|
|
239
249
|
isPasswordHidden.toggle()
|
|
240
250
|
onRightIconPressed?()
|
|
241
251
|
}
|
|
252
|
+
|
|
253
|
+
private func limitText(_ value: String) -> String {
|
|
254
|
+
guard let maxLength = maxLength else {
|
|
255
|
+
return value
|
|
256
|
+
}
|
|
257
|
+
return String(value.prefix(maxLength))
|
|
258
|
+
}
|
|
242
259
|
|
|
243
260
|
private func borderColor() -> Color {
|
|
244
261
|
if disabled {
|
|
@@ -279,6 +296,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
279
296
|
var fontWeight: UIFont.Weight
|
|
280
297
|
var textColor: UIColor
|
|
281
298
|
var isDisabled: Bool
|
|
299
|
+
var maxLength: Int?
|
|
282
300
|
var onFocusChange: (Bool) -> Void
|
|
283
301
|
var onChangeText: ((String) -> Void)?
|
|
284
302
|
|
|
@@ -307,6 +325,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
307
325
|
}
|
|
308
326
|
|
|
309
327
|
func updateUIView(_ textField: UITextField, context: Context) {
|
|
328
|
+
context.coordinator.parent = self
|
|
310
329
|
if textField.text != text {
|
|
311
330
|
textField.text = text
|
|
312
331
|
}
|
|
@@ -342,7 +361,7 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
342
361
|
}
|
|
343
362
|
|
|
344
363
|
func textFieldDidEndEditing(_ textField: UITextField) {
|
|
345
|
-
parent.text = textField.text ?? ""
|
|
364
|
+
parent.text = limitText(textField.text ?? "")
|
|
346
365
|
parent.onFocusChange(false)
|
|
347
366
|
}
|
|
348
367
|
|
|
@@ -357,7 +376,10 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
357
376
|
|
|
358
377
|
@objc func textFieldDidChange(_ textField: UITextField) {
|
|
359
378
|
if isResettingText { return }
|
|
360
|
-
let newText = textField.text ?? ""
|
|
379
|
+
let newText = limitText(textField.text ?? "")
|
|
380
|
+
if textField.text != newText {
|
|
381
|
+
textField.text = newText
|
|
382
|
+
}
|
|
361
383
|
parent.text = newText
|
|
362
384
|
parent.onChangeText?(newText)
|
|
363
385
|
}
|
|
@@ -366,6 +388,13 @@ private struct SecureInputField: UIViewRepresentable {
|
|
|
366
388
|
textField.resignFirstResponder()
|
|
367
389
|
return true
|
|
368
390
|
}
|
|
391
|
+
|
|
392
|
+
private func limitText(_ value: String) -> String {
|
|
393
|
+
guard let maxLength = parent.maxLength else {
|
|
394
|
+
return value
|
|
395
|
+
}
|
|
396
|
+
return String(value.prefix(maxLength))
|
|
397
|
+
}
|
|
369
398
|
}
|
|
370
399
|
}
|
|
371
400
|
|