@momo-kits/native-kits 0.160.1-lottie.2-debug → 0.160.1-scrolltotop.10-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/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +8 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +1 -1
- 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/components/LazyColumnWithBouncing.kt +6 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +1 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +6 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +5 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +13 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +66 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -3
- package/gradle.properties +1 -1
- package/ios/Extensions/ScrollToTop.swift +94 -0
- package/ios/Input/Input.swift +33 -4
- package/package.json +1 -1
package/compose/build.gradle.kts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
|
|
5
|
+
@Composable
|
|
6
|
+
internal actual fun RegisterScrollToTop(navigator: Navigator, callback: (() -> Unit)?) {
|
|
7
|
+
// No-op on Android: status bar tap doesn't trigger scroll-to-top on this platform.
|
|
8
|
+
}
|
|
@@ -70,7 +70,7 @@ 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(
|
|
@@ -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
|
}
|
|
@@ -55,6 +55,8 @@ import androidx.compose.ui.unit.dp
|
|
|
55
55
|
import kotlinx.coroutines.flow.collect
|
|
56
56
|
import kotlinx.coroutines.flow.combine
|
|
57
57
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
58
|
+
import kotlinx.coroutines.launch
|
|
59
|
+
import androidx.compose.runtime.rememberCoroutineScope
|
|
58
60
|
import vn.momo.kits.const.Spacing
|
|
59
61
|
import vn.momo.kits.modifier.conditional
|
|
60
62
|
import vn.momo.kits.platform.getPlatformName
|
|
@@ -96,10 +98,12 @@ fun LazyColumnWithBouncing(
|
|
|
96
98
|
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
|
|
97
99
|
userScrollEnabled: Boolean = true,
|
|
98
100
|
pullRefreshState: PullToRefreshCustomState? = null,
|
|
101
|
+
scrollToTopOnStatusBarTap: Boolean = true,
|
|
99
102
|
content: LazyListScope.() -> Unit,
|
|
100
103
|
) {
|
|
101
104
|
val height = remember { mutableIntStateOf(0) }
|
|
102
105
|
val maxConstraint = remember { mutableIntStateOf(0) }
|
|
106
|
+
val scope = rememberCoroutineScope()
|
|
103
107
|
|
|
104
108
|
LaunchedEffect(Unit) {
|
|
105
109
|
val addOn = 1
|
|
@@ -119,6 +123,8 @@ fun LazyColumnWithBouncing(
|
|
|
119
123
|
}.collect()
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
|
|
127
|
+
|
|
122
128
|
val measureLayout =
|
|
123
129
|
remember<MeasureScope.(Measurable, Constraints) -> MeasureResult>(maxConstraint) {
|
|
124
130
|
{ m, c ->
|
|
@@ -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
|
|
@@ -150,6 +150,8 @@ internal fun StackScreen(
|
|
|
150
150
|
val footerHeightPx = remember { mutableIntStateOf(0) }
|
|
151
151
|
val headerRightWidthPx = remember { mutableIntStateOf(0) }
|
|
152
152
|
|
|
153
|
+
RegisterScrollToTop(navigator, options.scrollData.scrollToTopCallback)
|
|
154
|
+
|
|
153
155
|
BackHandler(true) { navigator.onBackSafe() }
|
|
154
156
|
|
|
155
157
|
CompositionLocalProvider(
|
|
@@ -166,7 +168,7 @@ internal fun StackScreen(
|
|
|
166
168
|
.conditional(options.keyboardOptions.keyboardShouldPersistTaps) {
|
|
167
169
|
hideKeyboardOnTap()
|
|
168
170
|
}
|
|
169
|
-
.conditional(options.keyboardOptions.useAvoidKeyboard &&
|
|
171
|
+
.conditional(options.keyboardOptions.useAvoidKeyboard && supportsImePadding()) {
|
|
170
172
|
imePadding()
|
|
171
173
|
}
|
|
172
174
|
) {
|
|
@@ -550,3 +552,4 @@ internal fun getInputSearchType(options: NavigationOptions): InputSearchType{
|
|
|
550
552
|
else -> InputSearchType.None
|
|
551
553
|
}
|
|
552
554
|
}
|
|
555
|
+
|
|
@@ -30,7 +30,19 @@ 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(
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.DisposableEffect
|
|
5
|
+
import androidx.compose.runtime.remember
|
|
6
|
+
|
|
7
|
+
@Composable
|
|
8
|
+
internal actual fun RegisterScrollToTop(navigator: Navigator, callback: (() -> Unit)?) {
|
|
9
|
+
val token = remember { Any() }
|
|
10
|
+
DisposableEffect(navigator, callback) {
|
|
11
|
+
if (callback != null) {
|
|
12
|
+
ScrollToTopRegistry.push(navigator, token, callback)
|
|
13
|
+
} else {
|
|
14
|
+
ScrollToTopRegistry.remove(navigator, token)
|
|
15
|
+
}
|
|
16
|
+
onDispose { ScrollToTopRegistry.remove(navigator, token) }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* iOS-only scroll-to-top dispatch.
|
|
22
|
+
*
|
|
23
|
+
* Per-Navigator stack of screen callbacks, plus a module-level stack of owners
|
|
24
|
+
* (Navigators). The host project's Navigator-of-Navigators (e.g.
|
|
25
|
+
* `ComposeNavigatorManager`) must call [pushOwner] / [removeOwner] when its
|
|
26
|
+
* top Navigator changes, so [trigger] hits the visually topmost screen.
|
|
27
|
+
*
|
|
28
|
+
* Call [trigger] from Swift on status-bar tap.
|
|
29
|
+
*/
|
|
30
|
+
object ScrollToTopRegistry {
|
|
31
|
+
private data class Entry(val token: Any, val callback: () -> Unit)
|
|
32
|
+
|
|
33
|
+
private val stacksByOwner = mutableMapOf<Any, MutableList<Entry>>()
|
|
34
|
+
private val ownerStack = mutableListOf<Any>()
|
|
35
|
+
|
|
36
|
+
fun pushOwner(owner: Any) {
|
|
37
|
+
ownerStack.remove(owner)
|
|
38
|
+
ownerStack.add(owner)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fun removeOwner(owner: Any) {
|
|
42
|
+
ownerStack.remove(owner)
|
|
43
|
+
stacksByOwner.remove(owner)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
internal fun push(owner: Any, token: Any, callback: () -> Unit) {
|
|
47
|
+
val stack = stacksByOwner.getOrPut(owner) { mutableListOf() }
|
|
48
|
+
stack.removeAll { it.token === token }
|
|
49
|
+
stack.add(Entry(token, callback))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
internal fun remove(owner: Any, token: Any) {
|
|
53
|
+
stacksByOwner[owner]?.removeAll { it.token === token }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fun trigger() {
|
|
57
|
+
val owner = ownerStack.lastOrNull() ?: run {
|
|
58
|
+
// Fallback: no owner registered yet — fire the only owner if there's exactly one.
|
|
59
|
+
if (stacksByOwner.size == 1) {
|
|
60
|
+
stacksByOwner.values.first().lastOrNull()?.callback?.invoke()
|
|
61
|
+
}
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
stacksByOwner[owner]?.lastOrNull()?.callback?.invoke()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -87,9 +87,9 @@ actual fun getScreenHeight(): Dp {
|
|
|
87
87
|
return getScreenDimensions().height.dp
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
actual fun getOSVersion():
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
actual fun getOSVersion(): OSVersion = OSVersion.IOS(
|
|
91
|
+
major = UIDevice.currentDevice.systemVersion.substringBefore(".").toIntOrNull() ?: 0
|
|
92
|
+
)
|
|
93
93
|
|
|
94
94
|
@OptIn(ExperimentalForeignApi::class, ExperimentalComposeUiApi::class)
|
|
95
95
|
@Composable
|
package/gradle.properties
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ScrollToTop.swift
|
|
3
|
+
//
|
|
4
|
+
//
|
|
5
|
+
// Created by Thành Lê on 26/5/26.
|
|
6
|
+
//
|
|
7
|
+
import Foundation
|
|
8
|
+
import SwiftUI
|
|
9
|
+
import Combine
|
|
10
|
+
extension UIStatusBarManager {
|
|
11
|
+
public static var statusBarTappedNotification: Notification.Name = {
|
|
12
|
+
if let originalMethod = class_getInstanceMethod(UIStatusBarManager.self, Selector(("handleTapAction:"))),
|
|
13
|
+
let swizzledMethod = class_getInstanceMethod(UIStatusBarManager.self, #selector(_handleTapAction)) {
|
|
14
|
+
method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
15
|
+
}
|
|
16
|
+
return .init("statusBarSelected")
|
|
17
|
+
}()
|
|
18
|
+
|
|
19
|
+
@objc private func _handleTapAction(_ action: Any?) {
|
|
20
|
+
_handleTapAction(action) // Call the original implementation
|
|
21
|
+
NotificationCenter.default.post(name: UIStatusBarManager.statusBarTappedNotification, object: nil)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public struct StatusBarTapModifier: ViewModifier {
|
|
26
|
+
|
|
27
|
+
let action: () -> Void
|
|
28
|
+
|
|
29
|
+
@State private var observer: AnyCancellable?
|
|
30
|
+
|
|
31
|
+
public init(action: @escaping () -> Void) {
|
|
32
|
+
self.action = action
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public func body(content: Content) -> some View {
|
|
36
|
+
content
|
|
37
|
+
.onAppear {
|
|
38
|
+
observer = NotificationCenter.default
|
|
39
|
+
.publisher(for: UIStatusBarManager.statusBarTappedNotification)
|
|
40
|
+
.sink { _ in
|
|
41
|
+
action()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
.onDisappear {
|
|
45
|
+
observer = nil
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
extension View {
|
|
51
|
+
public func onStatusBarTap(_ action: @escaping () -> Void) -> some View {
|
|
52
|
+
modifier(StatusBarTapModifier(action: action))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
extension UIViewController {
|
|
57
|
+
|
|
58
|
+
private static var statusBarTapActionKey: UInt8 = 0
|
|
59
|
+
private static var statusBarTapObserverKey: UInt8 = 0
|
|
60
|
+
|
|
61
|
+
private var statusBarTapAction: (() -> Void)? {
|
|
62
|
+
get { objc_getAssociatedObject(self, &Self.statusBarTapActionKey) as? () -> Void }
|
|
63
|
+
set { objc_setAssociatedObject(self, &Self.statusBarTapActionKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC) }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private var statusBarTapObserver: NSObjectProtocol? {
|
|
67
|
+
get { objc_getAssociatedObject(self, &Self.statusBarTapObserverKey) as? NSObjectProtocol }
|
|
68
|
+
set { objc_setAssociatedObject(self, &Self.statusBarTapObserverKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// Register a callback fired when the user taps the status bar / notch.
|
|
72
|
+
/// Host app wires `action` to its scroll-to-top bridge (e.g. Navigation.scrollData.scrollToTopCallback).
|
|
73
|
+
public func registerStatusBarTap(_ action: @escaping () -> Void) {
|
|
74
|
+
unregisterStatusBarTap()
|
|
75
|
+
statusBarTapAction = action
|
|
76
|
+
statusBarTapObserver = NotificationCenter.default.addObserver(
|
|
77
|
+
forName: UIStatusBarManager.statusBarTappedNotification,
|
|
78
|
+
object: nil,
|
|
79
|
+
queue: .main
|
|
80
|
+
) { [weak self] _ in
|
|
81
|
+
self?.statusBarTapAction?()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public func unregisterStatusBarTap() {
|
|
86
|
+
if let observer = statusBarTapObserver {
|
|
87
|
+
NotificationCenter.default.removeObserver(observer)
|
|
88
|
+
}
|
|
89
|
+
statusBarTapObserver = nil
|
|
90
|
+
statusBarTapAction = nil
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
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
|
|