Skip to content

Commit

Permalink
feat: 🎸 HCPSDKFIORIUIKIT-2479 SwiftUI FUIStepper migration (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzchao-1999 authored May 16, 2024
1 parent ba834a1 commit fefbb49
Show file tree
Hide file tree
Showing 25 changed files with 1,653 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Apps/Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
691DE21925F2A30B00094D4A /* KPIViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 691DE21825F2A30B00094D4A /* KPIViewExample.swift */; };
692F338B26556A6A009B98DA /* SideBarExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 692F338A26556A6A009B98DA /* SideBarExample.swift */; };
69B2B5D9268A333C009AC6B3 /* KPIProgressViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69B2B5D8268A333C009AC6B3 /* KPIProgressViewExample.swift */; };
878219C42BEE128E002FDFBC /* StepperViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 878219C32BEE128E002FDFBC /* StepperViewExample.swift */; };
8A55795724C1286E0098003A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A55795624C1286E0098003A /* AppDelegate.swift */; };
8A55795924C1286E0098003A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A55795824C1286E0098003A /* SceneDelegate.swift */; };
8A55795B24C1286E0098003A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A55795A24C1286E0098003A /* ContentView.swift */; };
Expand Down Expand Up @@ -197,6 +198,7 @@
691DE21825F2A30B00094D4A /* KPIViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KPIViewExample.swift; sourceTree = "<group>"; };
692F338A26556A6A009B98DA /* SideBarExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarExample.swift; sourceTree = "<group>"; };
69B2B5D8268A333C009AC6B3 /* KPIProgressViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KPIProgressViewExample.swift; sourceTree = "<group>"; };
878219C32BEE128E002FDFBC /* StepperViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StepperViewExample.swift; sourceTree = "<group>"; };
8A1E99AD24D59C8000ED8A39 /* cloud-sdk-ios-fiori */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "cloud-sdk-ios-fiori"; path = ../..; sourceTree = "<group>"; };
8A55795324C1286E0098003A /* Examples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Examples.app; sourceTree = BUILT_PRODUCTS_DIR; };
8A55795624C1286E0098003A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -335,6 +337,7 @@
1F3C92EF25DF12A100A99A07 /* FormCells */ = {
isa = PBXGroup;
children = (
878219C32BEE128E002FDFBC /* StepperViewExample.swift */,
1F3C92F025DF12C100A99A07 /* ListPicker.swift */,
B141D6BA29261F9E008A8BD6 /* SearchableListViewExample.swift */,
99193C842B719B8800F33BAF /* InformationViewExample.swift */,
Expand Down Expand Up @@ -946,6 +949,7 @@
B86F02AA267983870049DDA7 /* ObjectItemListView.swift in Sources */,
B846F94826815DE50085044B /* ContactItemRegularExamples.swift in Sources */,
9D00866A2BA8F6820004BE15 /* TextFieldFormViewExample.swift in Sources */,
878219C42BEE128E002FDFBC /* StepperViewExample.swift in Sources */,
3C180C282B858CF6007CE79A /* IllustratedMessageExample.swift in Sources */,
8AD9DFB425D49967007448EC /* ContactItemInitViewBuilderExample.swift in Sources */,
B8D4376D25F97F140024EE7D /* ObjectItemExample.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions Apps/Examples/Examples/FioriSwiftUICore/CoreContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ struct CoreContentView: View {
Text("Linear Progress Indicator")
}
)

NavigationLink(
destination: StepperViewExample(),
label: {
Text("Stepper")
}
)
}.navigationBarTitle("FioriSwiftUICore")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import FioriSwiftUICore
import SwiftUI

struct StepperViewExample: View {
@State var normalStepValue = "3"
@State var longTitleStepValue = "3"
@State var customStyleStepValue = "3"
@State var noHintStepValue = "79"
@State var negativeValue = "80"
@State var disabledValue = "63"
@State var isInputValueValid: Bool = true

var newStyle: any InformationViewStyle {
if self.isInputValueValid {
return InformationViewFioriStyle.fiori
} else {
return InformationViewErrorStyle.error
}
}

var body: some View {
List {
StepperView(
title: { Text("Value") },
text: self.$normalStepValue,
step: 1,
stepRange: 0 ... 100,
description: { Text("Hint Text") }
)
StepperView(
title: { Text("Value") },
text: self.$negativeValue,
step: 1,
stepRange: 0 ... 100,
description: { Text(self.isInputValueValid ? "Hint Text" : "Validation failed.") }
).onChange(of: self.negativeValue, perform: { value in
if Int(value) ?? 1 > 80 {
self.isInputValueValid = false
} else {
self.isInputValueValid = true
}
})
.informationViewStyle(self.newStyle).typeErased
StepperView(
title: { Text("Value") },
text: self.$disabledValue,
step: 1,
stepRange: 0 ... 100,
description: { Text("Disabled Stepper") }
)
.disabled(true)
StepperView(
title: { Text("loooooooooooooooooooooongTitle") },
text: self.$longTitleStepValue,
step: 3,
stepRange: 0 ... 100,
description: { Text("Increment/decrement 3 each step") }
)
StepperView(
title: { Text("Value") },
text: self.$noHintStepValue,
step: 1,
stepRange: 0 ... 100
)
StepperView(
title: { Text("Value") },
text: self.$customStyleStepValue,
step: 1,
stepRange: 0 ... 100,
description: { Text("Custom style") }
)
.titleStyle(content: { titleConfiguration in
titleConfiguration.title
.foregroundColor(.purple)
})
.descriptionStyle(content: { config in
config.description
.foregroundColor(.purple)
})
.stepperFieldStyle(content: { config in
StepperField(config)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(lineWidth: 1)
.foregroundColor(.purple)
)
})
.textInputFieldStyle(content: { config in
TextInputField(config).foregroundColor(.purple)
})
.incrementActionStyle(content: { config in
config.incrementAction.fioriButtonStyle(IncrementBtnStyle())
})
.decrementActionStyle(content: { config in
config.decrementAction.fioriButtonStyle(DecrementBtnStyle())
})
Spacer()
}
}

func getDescription(isValid: Bool) -> any View {
if isValid {
return EmptyView()
} else {
return Text("Validation failed")
}
}
}

struct IncrementBtnStyle: FioriButtonStyle {
func makeBody(configuration: FioriButtonStyle.Configuration) -> some View {
configuration.label.foregroundColor(Color.purple)
}
}

struct DecrementBtnStyle: FioriButtonStyle {
func makeBody(configuration: FioriButtonStyle.Configuration) -> some View {
configuration.label.foregroundColor(Color.purple)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,19 @@ protocol _MessageContentComponent {
@ViewBuilder
var messageContent: (() -> any View)? { get }
}

// sourcery: BaseComponent
protocol _DecrementActionComponent {
// sourcery: @ViewBuilder
// sourcery: defaultValue = "FioriButton { _ in Image(systemName: "minus") }"
// sourcery: resultBuilder.defaultValue = "{ FioriButton { _ in Image(systemName: "minus") } }"
var decrementAction: FioriButton? { get }
}

// sourcery: BaseComponent
protocol _IncrementActionComponent {
// sourcery: @ViewBuilder
// sourcery: defaultValue = "FioriButton { _ in Image(systemName: "plus") }"
// sourcery: resultBuilder.defaultValue = "{ FioriButton { _ in Image(systemName: "plus") } }"
var incrementAction: FioriButton? { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,15 @@ protocol _TextFieldFormViewComponent: _TitleComponent, _TitleFormViewComponent {

// sourcery: CompositeComponent
protocol _JouleWelcomeScreen: _MediaImageComponent, _GreetingTextComponent, _TitleComponent, _FootnoteComponent, _MessageContentComponent {}


// sourcery: CompositeComponent
protocol _StepperFieldComponent: _DecrementActionComponent, _TextInputFieldComponent, _IncrementActionComponent {
/// The step value
var step: Int? { get }

/// a range of values
var stepRange: ClosedRange<Int> { get }
}

// sourcery: CompositeComponent
protocol _StepperViewComponent: _TitleComponent, _StepperFieldComponent, _InformationViewComponent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import FioriThemeManager

// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import Foundation
import SwiftUI

/**
This file provides default fiori style for the component.
1. Uncomment the following code.
2. Implement layout and style in corresponding places.
3. Delete `.generated` from file name.
4. Move this file to `_FioriStyles` folder under `FioriSwiftUICore`.
*/

// Base Layout style
public struct DecrementActionBaseStyle: DecrementActionStyle {
@ViewBuilder
public func makeBody(_ configuration: DecrementActionConfiguration) -> some View {
// Add default layout here
configuration.decrementAction
}
}

// Default fiori styles
public struct DecrementActionFioriStyle: DecrementActionStyle {
@ViewBuilder
public func makeBody(_ configuration: DecrementActionConfiguration) -> some View {
DecrementAction(configuration)
// Add default style here
// .foregroundStyle(Color.preferredColor(<#fiori color#>))
// .font(.fiori(forTextStyle: <#fiori font#>))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import FioriThemeManager

// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
import Foundation
import SwiftUI

/**
This file provides default fiori style for the component.
1. Uncomment the following code.
2. Implement layout and style in corresponding places.
3. Delete `.generated` from file name.
4. Move this file to `_FioriStyles` folder under `FioriSwiftUICore`.
*/

// Base Layout style
public struct IncrementActionBaseStyle: IncrementActionStyle {
@ViewBuilder
public func makeBody(_ configuration: IncrementActionConfiguration) -> some View {
// Add default layout here
configuration.incrementAction
}
}

// Default fiori styles
public struct IncrementActionFioriStyle: IncrementActionStyle {
@ViewBuilder
public func makeBody(_ configuration: IncrementActionConfiguration) -> some View {
IncrementAction(configuration)
// Add default style here
// .foregroundStyle(Color.preferredColor(<#fiori color#>))
// .font(.fiori(forTextStyle: <#fiori font#>))
}
}
Loading

0 comments on commit fefbb49

Please sign in to comment.