Skip to content

Commit 76413cd

Browse files
feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2718] Mandatory Field Styling (SAP#900)
[JIRA: HCPSDKFIORIUIKIT-2718] Mandatory Field Styling for Input Controls Co-authored-by: I824136 <[email protected]>
1 parent 4785ad1 commit 76413cd

File tree

7 files changed

+144
-28
lines changed

7 files changed

+144
-28
lines changed

Apps/Examples/Examples/FioriSwiftUICore/SignatureView/SignatureCaptureViewExample.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct SignatureCaptureViewExample: View {
1717

1818
struct SignatureCaptureViewExample2: View {
1919
@State var isRequired = false
20+
@State var isCustomizedIndicator = false
21+
2022
let startAction = _Action(actionText: "Sign Here", didSelectAction: nil)
2123
let restartAction = _Action(actionText: "Sign Again", didSelectAction: nil)
2224
let cancelAction = _Action(actionText: "Cancel2")
@@ -26,6 +28,10 @@ struct SignatureCaptureViewExample2: View {
2628
Toggle("Mandatory Field", isOn: self.$isRequired)
2729
.padding(.leading, 16)
2830
.padding(.trailing, 16)
31+
Toggle("Customized Mandatory Field", isOn: self.$isCustomizedIndicator)
32+
.padding(.leading, 16)
33+
.padding(.trailing, 16)
34+
2935
SignatureCaptureView(title: "Long Long Long Long Long Long Long Signature",
3036
startAction: self.startAction,
3137
restartAction: self.restartAction,
@@ -39,6 +45,8 @@ struct SignatureCaptureViewExample2: View {
3945
})
4046
.titleFont(.callout)
4147
.titleColor(.red)
48+
.indicatorFont(self.isCustomizedIndicator ? .headline : .subheadline)
49+
.indicatorColor(self.isCustomizedIndicator ? .red : .preferredColor(.primaryLabel))
4250
.cropsImage(true)
4351
.strokeWidth(10)
4452
.strokeColor(.red)

Sources/FioriSwiftUICore/Models/ModelDefinitions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ public protocol UserConsentPageModel: TitleComponent, BodyAttributedTextComponen
323323
// sourcery: virtualPropIsReenterTapped = "@State var isReenterTapped = false"
324324
// sourcery: virtualPropTitleFont = "var titleFont = Font.fiori(forTextStyle: .subheadline).weight(.semibold)"
325325
// sourcery: virtualPropTitleColor = "var titleColor = Color.preferredColor(.primaryLabel)"
326+
// sourcery: virtualPropIndicatorFont = "var indicatorFont = Font.fiori(forTextStyle: .subheadline).weight(.semibold)"
327+
// sourcery: virtualPropIndicatorColor = "var indicatorColor = Color.preferredColor(.primaryLabel)"
326328
// sourcery: virtualPropStrokeWidth = "var strokeWidth: CGFloat = 3.0"
327329
// sourcery: virtualPropStrokeColor = "var strokeColor = Color.preferredColor(.primaryLabel)"
328330
// sourcery: virtualPropDrawingViewBackgroundColor = "var drawingViewBackgroundColor = Color.preferredColor(.primaryBackground)"
@@ -346,6 +348,10 @@ public protocol SignatureCaptureViewModel: AnyObject {
346348
// sourcery: default.value = nil
347349
// sourcery: no_view
348350
var title: String? { get }
351+
352+
// sourcery: default.value = ""*""
353+
// sourcery: no_view
354+
var mandatoryIndicator: String? { get }
349355

350356
// sourcery: genericParameter.name = StartActionView
351357
// sourcery: default.value = _TapToSignActionDefault()

Sources/FioriSwiftUICore/Views/SignatureCaptureView+View.swift

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ extension SignatureCaptureView: View {
7777
VStack(spacing: 0) {
7878
HStack {
7979
Text(self.getKeyName())
80-
.font(titleFont)
81-
.foregroundColor(titleColor)
8280
.padding(.top, 11)
8381
.padding(.bottom, 11)
8482
.accessibilityLabel(self.getTitleAccessibilityLabel())
@@ -250,15 +248,21 @@ extension SignatureCaptureView: View {
250248
}
251249
}
252250

253-
func getKeyName() -> String {
251+
func getKeyName() -> AttributedString {
254252
var titleString = _title
255253
if (titleString?.isEmpty) == nil {
256254
titleString = NSLocalizedString("Signature", tableName: "FioriSwiftUICore", bundle: Bundle.accessor, comment: "")
257255
}
256+
var titleAttributedText = AttributedString(titleString ?? "")
257+
titleAttributedText.foregroundColor = titleColor
258+
titleAttributedText.font = titleFont
258259
if isRequired {
259-
return (titleString ?? "") + "*"
260+
var indicatorAttributedText = AttributedString(_mandatoryIndicator ?? "*")
261+
indicatorAttributedText.foregroundColor = indicatorColor
262+
indicatorAttributedText.font = indicatorFont
263+
return titleAttributedText + indicatorAttributedText
260264
}
261-
return titleString ?? ""
265+
return titleAttributedText
262266
}
263267

264268
func getTitleAccessibilityLabel() -> String {
@@ -315,8 +319,6 @@ public extension SignatureCaptureView {
315319
A view modifier to set the title font.
316320

317321
The default is `Font.body`.
318-
319-
- parameter width: The desired stroke width.
320322
*/
321323
func titleFont(_ font: Font?) -> Self {
322324
guard let font else {
@@ -331,8 +333,6 @@ public extension SignatureCaptureView {
331333
A view modifier to set the title text color.
332334

333335
The default is `Color.preferredColor(.primaryLabel)`.
334-
335-
- parameter width: The desired stroke width.
336336
*/
337337
func titleColor(_ color: Color?) -> Self {
338338
guard let color else {
@@ -343,6 +343,34 @@ public extension SignatureCaptureView {
343343
return newSelf
344344
}
345345

346+
/**
347+
A view modifier to set the mandatory field font.
348+
349+
The default is `Font.body`.
350+
*/
351+
func indicatorFont(_ font: Font?) -> Self {
352+
guard let font else {
353+
return self
354+
}
355+
var newSelf = self
356+
newSelf.indicatorFont = font
357+
return newSelf
358+
}
359+
360+
/**
361+
A view modifier to set the mandatory field text color.
362+
363+
The default is `Color.preferredColor(.primaryLabel)`.
364+
*/
365+
func indicatorColor(_ color: Color?) -> Self {
366+
guard let color else {
367+
return self
368+
}
369+
var newSelf = self
370+
newSelf.indicatorColor = color
371+
return newSelf
372+
}
373+
346374
/**
347375
A view modifier to set the stroke width.
348376

Sources/FioriSwiftUICore/_generated/ViewModels/API/SignatureCaptureView+API.generated.swift

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public struct SignatureCaptureView<StartActionView: View, RestartActionView: Vie
1111
@Environment(\.saveActionModifier) private var saveActionModifier
1212

1313
let _title: String?
14+
let _mandatoryIndicator: String?
1415
let _startAction: StartActionView
1516
let _restartAction: RestartActionView
1617
let _cancelAction: CancelActionView
@@ -19,36 +20,39 @@ public struct SignatureCaptureView<StartActionView: View, RestartActionView: Vie
1920
let _signatureImage: UIImage?
2021
let _onSave: ((UIImage) -> Void)?
2122
let _onDelete: (() -> Void)?
23+
var watermarkText: String?
24+
var titleFont = Font.fiori(forTextStyle: .subheadline).weight(.semibold)
25+
var xmarkColor = Color.preferredColor(.quaternaryLabel)
2226
public private(set) var _heightDidChangePublisher = CurrentValueSubject<CGFloat, Never>(0)
2327
var drawingViewBackgroundColor = Color.preferredColor(.primaryBackground)
24-
@State var currentDrawing = Drawing()
25-
var cropsImage = false
2628
var isRequired = false
27-
@State var isSaved = false
28-
@State var isEditing = false
29-
@State var fullSignatureImage: UIImage?
30-
let _drawingViewMinHeight: CGFloat = 256
29+
var indicatorColor = Color.preferredColor(.primaryLabel)
30+
@State var currentDrawing = Drawing()
3131
var watermarkTextFont: UIFont = .preferredFont(forTextStyle: .caption1)
3232
var hidesSignatureLine = false
33-
var titleFont = Font.fiori(forTextStyle: .subheadline).weight(.semibold)
34-
var timestampFormatter: DateFormatter?
35-
var _drawingViewMaxHeight: CGFloat?
33+
@State var isEditing = false
34+
var hidesXmark = false
35+
@State var drawings = [Drawing]()
36+
var cropsImage = false
37+
@State var isReenterTapped = false
38+
var strokeWidth: CGFloat = 3.0
39+
let _drawingViewMinHeight: CGFloat = 256
40+
var strokeColor = Color.preferredColor(.primaryLabel)
3641
var titleColor = Color.preferredColor(.primaryLabel)
42+
@State var fullSignatureImage: UIImage?
43+
var signatureLineColor = Color.preferredColor(.quaternaryLabel)
44+
var timestampFormatter: DateFormatter?
3745
var addsTimestampInImage: Bool = false
38-
var strokeColor = Color.preferredColor(.primaryLabel)
39-
@State var isReenterTapped = false
40-
var watermarkText: String?
46+
@State var isSaved = false
47+
var _drawingViewMaxHeight: CGFloat?
4148
var appliesTintColorToImage = true
42-
var hidesXmark = false
4349
var watermarkTextColor: Color = .preferredColor(.tertiaryLabel)
44-
var signatureLineColor = Color.preferredColor(.quaternaryLabel)
45-
@State var drawings = [Drawing]()
46-
var strokeWidth: CGFloat = 3.0
47-
var xmarkColor = Color.preferredColor(.quaternaryLabel)
4850
var watermarkTextAlignment: NSTextAlignment = .natural
51+
var indicatorFont = Font.fiori(forTextStyle: .subheadline).weight(.semibold)
4952

5053
private var isModelInit: Bool = false
5154
private var isTitleNil: Bool = false
55+
private var isMandatoryIndicatorNil: Bool = false
5256
private var isStartActionNil: Bool = false
5357
private var isRestartActionNil: Bool = false
5458
private var isCancelActionNil: Bool = false
@@ -60,6 +64,7 @@ public struct SignatureCaptureView<StartActionView: View, RestartActionView: Vie
6064

6165
public init(
6266
title: String? = nil,
67+
mandatoryIndicator: String? = "*",
6368
@ViewBuilder startAction: () -> StartActionView,
6469
@ViewBuilder restartAction: () -> RestartActionView,
6570
@ViewBuilder cancelAction: () -> CancelActionView,
@@ -70,6 +75,7 @@ public struct SignatureCaptureView<StartActionView: View, RestartActionView: Vie
7075
onDelete: (() -> Void)? = nil
7176
) {
7277
self._title = title
78+
self._mandatoryIndicator = mandatoryIndicator
7379
self._startAction = startAction()
7480
self._restartAction = restartAction()
7581
self._cancelAction = cancelAction()
@@ -144,11 +150,12 @@ extension SignatureCaptureView where StartActionView == _ConditionalContent<_Act
144150
SaveActionView == _ConditionalContent<_Action, EmptyView> {
145151

146152
public init(model: SignatureCaptureViewModel) {
147-
self.init(title: model.title, startAction: model.startAction != nil ? _Action(model: model.startAction!) : nil, restartAction: model.restartAction != nil ? _Action(model: model.restartAction!) : nil, cancelAction: model.cancelAction != nil ? _Action(model: model.cancelAction!) : nil, clearAction: model.clearAction != nil ? _Action(model: model.clearAction!) : nil, saveAction: model.saveAction != nil ? _Action(model: model.saveAction!) : nil, signatureImage: model.signatureImage, onSave: model.onSave, onDelete: model.onDelete)
153+
self.init(title: model.title, mandatoryIndicator: model.mandatoryIndicator, startAction: model.startAction != nil ? _Action(model: model.startAction!) : nil, restartAction: model.restartAction != nil ? _Action(model: model.restartAction!) : nil, cancelAction: model.cancelAction != nil ? _Action(model: model.cancelAction!) : nil, clearAction: model.clearAction != nil ? _Action(model: model.clearAction!) : nil, saveAction: model.saveAction != nil ? _Action(model: model.saveAction!) : nil, signatureImage: model.signatureImage, onSave: model.onSave, onDelete: model.onDelete)
148154
}
149155

150-
public init(title: String? = nil, startAction: _Action? = _Action(model: _TapToSignActionDefault()), restartAction: _Action? = _Action(model: _ReEnterSignatureActionDefault()), cancelAction: _Action? = _Action(model: _CancelActionDefault()), clearAction: _Action? = _Action(model: _ClearActionDefault()), saveAction: _Action? = _Action(model: _SaveActionDefault()), signatureImage: UIImage? = nil, onSave: ((UIImage) -> Void)? = nil, onDelete: (() -> Void)? = nil) {
156+
public init(title: String? = nil, mandatoryIndicator: String? = "*", startAction: _Action? = _Action(model: _TapToSignActionDefault()), restartAction: _Action? = _Action(model: _ReEnterSignatureActionDefault()), cancelAction: _Action? = _Action(model: _CancelActionDefault()), clearAction: _Action? = _Action(model: _ClearActionDefault()), saveAction: _Action? = _Action(model: _SaveActionDefault()), signatureImage: UIImage? = nil, onSave: ((UIImage) -> Void)? = nil, onDelete: (() -> Void)? = nil) {
151157
self._title = title
158+
self._mandatoryIndicator = mandatoryIndicator
152159
self._startAction = startAction != nil ? ViewBuilder.buildEither(first: startAction!) : ViewBuilder.buildEither(second: EmptyView())
153160
self._restartAction = restartAction != nil ? ViewBuilder.buildEither(first: restartAction!) : ViewBuilder.buildEither(second: EmptyView())
154161
self._cancelAction = cancelAction != nil ? ViewBuilder.buildEither(first: cancelAction!) : ViewBuilder.buildEither(second: EmptyView())
@@ -160,6 +167,7 @@ extension SignatureCaptureView where StartActionView == _ConditionalContent<_Act
160167

161168
isModelInit = true
162169
isTitleNil = title == nil ? true : false
170+
isMandatoryIndicatorNil = mandatoryIndicator == nil ? true : false
163171
isStartActionNil = startAction == nil ? true : false
164172
isRestartActionNil = restartAction == nil ? true : false
165173
isCancelActionNil = cancelAction == nil ? true : false

0 commit comments

Comments
 (0)