1515import OUDSTokensSemantic
1616import SwiftUI
1717
18- // MARK: - PIN Code Input Container
19-
2018struct PinCodeInputContainer : View {
2119
22- // MARK: Properties
20+ // MARK: - Properties
2321
2422 /// The `Binding` exposing the final result when everything is written
2523 @Binding private var value : String
@@ -38,7 +36,7 @@ struct PinCodeInputContainer: View {
3836 @Environment ( \. colorScheme) private var colorScheme
3937 @Environment ( \. theme) private var theme
4038
41- // MARK: Black magic
39+ // MARK: - Black magic
4240
4341 // These properties prevent double backspace processing by tracking which field was cleared and when.
4442 // When a backspace occurs, we mark the field index and timestamp, then skip onChange events
@@ -52,7 +50,7 @@ struct PinCodeInputContainer: View {
5250 @State private var lastBackspaceTime : Date = . distantPast
5351 // swiftlint:enable implicit_optional_initialization
5452
55- // MARK: Initializer
53+ // MARK: - Initializer
5654
5755 init ( _ value: Binding < String > ,
5856 length: OUDSPinCodeInput . Length ,
@@ -68,7 +66,7 @@ struct PinCodeInputContainer: View {
6866 _digits = State ( initialValue: empty)
6967 }
7068
71- // MARK: Body
69+ // MARK: - Body
7270
7371 // swiftlint:disable accessibility_trait_for_button
7472 var body : some View {
@@ -83,15 +81,9 @@ struct PinCodeInputContainer: View {
8381 . background (
8482 RoundedRectangle ( cornerRadius: theme. textInput. borderRadiusDefault)
8583 . fill ( backgroundColor) )
86- . overlay (
87- RoundedRectangle ( cornerRadius: theme. textInput. borderRadiusDefault)
88- . oudsBorder (
89- style: theme. borders. styleDefault,
90- width: theme. textInput. borderWidthDefault,
91- radius: theme. textInput. borderRadiusDefault,
92- color: borderColor) )
9384 . contentShape ( Rectangle ( ) )
94- . foregroundColor ( backgroundColor)
85+ . foregroundColor ( foregroundColor)
86+ . modifier ( PinCodeInputBorderModifier ( isOutlined: isOutlined, isError: isError, isFocused: focusedIndex == index) )
9587 . onTapGesture {
9688 // Focus on the first empty field or the last one
9789 if let firstEmpty = digits. firstIndex ( where: { $0. isEmpty } ) {
@@ -112,22 +104,38 @@ struct PinCodeInputContainer: View {
112104
113105 // swiftlint:enable accessibility_trait_for_button
114106
115- // MARK: Helpers
107+ // MARK: - Colors
108+
109+ private var foregroundColor : Color {
110+ if isOutlined {
111+ . red
112+ } else if isError {
113+ theme. colors. surfaceStatusNegativeMuted. color ( for: colorScheme)
114+ } else { // Not oulined, no error
115+ theme. colors. actionSupportEnabled. color ( for: colorScheme)
116+ }
117+ }
116118
117119 private var backgroundColor : Color {
118120 if isOutlined {
119121 . clear
120122 } else if isError {
121123 theme. colors. surfaceStatusNegativeMuted. color ( for: colorScheme)
122- } else {
124+ } else { // Not oulined, no error
123125 theme. colors. actionSupportEnabled. color ( for: colorScheme)
124126 }
125127 }
126128
127129 private var borderColor : MultipleColorSemanticToken {
128- isError ? theme. colors. actionNegativeEnabled : theme. colors. actionSupportEnabled
130+ if isError {
131+ theme. colors. actionNegativeEnabled
132+ } else { // Same color of border for both outlined and not outlined layouts
133+ theme. textInput. colorBorderEnabled
134+ }
129135 }
130136
137+ // MARK: - Digits fields
138+
131139 private func digitField( at index: Int ) -> some View {
132140 BackspaceDetectingTextField (
133141 text: $digits [ index] ,
@@ -136,6 +144,7 @@ struct PinCodeInputContainer: View {
136144 handleBackspace ( at: index)
137145 } )
138146 . oudsForegroundColor ( theme. colors. contentDefault)
147+ . oudsAccentColor ( theme. colors. contentDefault)
139148 . focused ( $focusedIndex, equals: index)
140149 . padding ( . vertical, theme. textInput. spacePaddingBlockDefault)
141150 . padding ( . horizontal, theme. textInput. spacePaddingInlineDefault)
0 commit comments