@@ -27,16 +27,6 @@ public struct SUInputField<FocusValue: Hashable>: View {
27
27
28
28
@Environment ( \. colorScheme) private var colorScheme
29
29
30
- private var titlePosition : InputFieldTitlePosition {
31
- if self . model. placeholder. isNilOrEmpty,
32
- self . text. isEmpty,
33
- self . globalFocus != self . localFocus {
34
- return . center
35
- } else {
36
- return . top
37
- }
38
- }
39
-
40
30
// MARK: Initialization
41
31
42
32
/// Initializer.
@@ -60,19 +50,14 @@ public struct SUInputField<FocusValue: Hashable>: View {
60
50
// MARK: Body
61
51
62
52
public var body : some View {
63
- ZStack ( alignment: Alignment (
64
- horizontal: . leading,
65
- vertical: self . titlePosition == . top ? . top : . center
66
- ) ) {
67
- Text ( self . model. attributedTitle ( for: self . titlePosition) )
68
- . font ( self . model. titleFont ( for: self . titlePosition) . font)
69
- . foregroundStyle (
70
- self . model
71
- . titleColor ( for: self . titlePosition)
72
- . color ( for: self . colorScheme)
73
- )
74
- . padding ( . top, self . titlePosition == . top ? self . model. verticalPadding : 0 )
75
- . animation ( . linear( duration: 0.1 ) , value: self . titlePosition)
53
+ HStack ( spacing: self . model. spacing) {
54
+ if self . model. title. isNotNilAndEmpty {
55
+ Text ( self . model. attributedTitle ( for: . center) )
56
+ . font ( self . model. preferredFont. font)
57
+ . foregroundStyle (
58
+ self . model. foregroundColor. color ( for: self . colorScheme)
59
+ )
60
+ }
76
61
77
62
Group {
78
63
if self . model. isSecureInput {
@@ -96,11 +81,9 @@ public struct SUInputField<FocusValue: Hashable>: View {
96
81
. submitLabel ( self . model. submitType. submitLabel)
97
82
. autocorrectionDisabled ( !self . model. isAutocorrectionEnabled)
98
83
. textInputAutocapitalization ( self . model. autocapitalization. textInputAutocapitalization)
99
- . frame ( height: self . model. inputFieldHeight)
100
- . padding ( . bottom, self . model. verticalPadding)
101
- . padding ( . top, self . model. inputFieldTopPadding)
102
84
}
103
85
. padding ( . horizontal, self . model. horizontalPadding)
86
+ . frame ( height: self . model. height)
104
87
. background ( self . model. backgroundColor. color ( for: self . colorScheme) )
105
88
. onTapGesture {
106
89
self . globalFocus = self . localFocus
@@ -110,11 +93,6 @@ public struct SUInputField<FocusValue: Hashable>: View {
110
93
cornerRadius: self . model. cornerRadius. value ( )
111
94
)
112
95
)
113
- . onChange ( of: self . globalFocus) { _ in
114
- // NOTE: Workaround to force `globalFocus` value update properly
115
- // Without this workaround the title position changes to `center`
116
- // when the text is cleared
117
- }
118
96
}
119
97
}
120
98
0 commit comments