Skip to content

Commit

Permalink
Merge branch 'main' into peng
Browse files Browse the repository at this point in the history
  • Loading branch information
dyongxu authored Nov 12, 2024
2 parents 9c52198 + a5b8b83 commit 90866c4
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import SwiftUI
class InfoViewDataModel: InfoViewModel {
var title: String = "SAP BTP SDK for iOS"
var descriptionText: String? = "SAP BTP SDK for iOS enables you to quickly develop your own native apps, with Swift. The SDK extends the standard Swift Apple iOS frameworks with the reusable UI components from the SAP Fiori for iOS Design Language, and provides APIs which seamlessly integrate apps with SAP BTP services. "
var progressIndicatorText: String? = "Loading..."
var showLoadingIndicator: Bool? = true
var loadingIndicatorText: String? = ""

lazy var action: _ActionModel? = ActionDataModel { [unowned self] in
print("InfoView Primary button clicked")
Expand Down Expand Up @@ -40,9 +41,7 @@ extension InfoViewDataModel {
struct InfoViewSample: View {
private var model = InfoViewDataModel()

public init() {
self.model.progressIndicatorText = ""
}
public init() {}

var body: some View {
VStack {
Expand All @@ -54,7 +53,9 @@ struct InfoViewSample: View {
struct InfoViewWithLoadingLabel: View {
private var model = InfoViewDataModel()

public init() {}
public init() {
self.model.loadingIndicatorText = "Loading..."
}

var body: some View {
VStack {
Expand All @@ -66,40 +67,24 @@ struct InfoViewWithLoadingLabel: View {
struct InfoViewCustomized: View {
private var model = InfoViewDataModel()

public init() {
self.model.progressIndicatorText = ""
}
public init() {}

var body: some View {
if #available(iOS 14.0, *) {
VStack {
InfoView(model: model)
.descriptionTextModifier { $0.font(.fiori(forTextStyle: .subheadline)).foregroundColor(.blue) }
.actionModifier { $0.foregroundColor(.blue) }
.progressIndicatorTextModifier { content in
content
.progressViewStyle(ShadowProgressViewStyle())
}
}
} else {
VStack {
InfoView(model: self.model)
.descriptionTextModifier { $0.font(.fiori(forTextStyle: .subheadline)).foregroundColor(.blue) }
.actionModifier { $0.foregroundColor(.blue) }
.progressIndicatorTextModifier { $0.scaleEffect(x: 2, y: 2, anchor: .center) }
}
VStack {
InfoView(model: self.model)
.descriptionTextModifier { $0.font(.fiori(forTextStyle: .subheadline)).foregroundColor(.blue) }
.actionModifier { $0.foregroundColor(.blue) }
.loadingIndicatorViewStyle(CustomLoadingStyle())
}
}
}

@available(iOS 14.0, *)
struct ShadowProgressViewStyle: ProgressViewStyle {
func makeBody(configuration: Configuration) -> some View {
ProgressView(configuration)
.shadow(color: Color(red: 0, green: 0, blue: 0.4),
radius: 4.0, x: 1.0, y: 2.0)
.accentColor(Color.green)
.scaleEffect(x: 1.5, y: 1.5, anchor: .center)
struct CustomLoadingStyle: LoadingIndicatorViewStyle {
func makeBody(_ configuration: LoadingIndicatorViewConfiguration) -> some View {
LoadingIndicatorView(configuration)
.indicatorTint(Color.pink)
.indicatorControlSize(.large)
.indicatorPosition(.bottom)
}
}

Expand Down
15 changes: 12 additions & 3 deletions Sources/FioriSwiftUICore/Models/ModelDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ public protocol _ListPickerItemModel: KeyComponent, ValueComponent {
@available(*, unavailable, renamed: "_ListPickerItemModel", message: "Will be removed in the future release. Please create ListPickerItem with other initializers instead.")
public protocol ListPickerItemModel {}

/// Deprecated ProgressIndicatorModel
// sourcery: generated_component_not_configurable
public protocol ProgressIndicatorModel: ProgressIndicatorComponent {}
public protocol _ProgressIndicatorModel: ProgressIndicatorComponent {}

@available(*, unavailable, renamed: "_ProgressIndicatorModel", message: "Will be removed in the future release. Please use LoadingIndicator instead.")
public protocol ProgressIndicatorModel {}

/// Deprecated SideBarListItem
// sourcery: add_env_props = "sideBarListItemConfigMode"
// sourcery: add_env_props = "sizeCategory"
Expand Down Expand Up @@ -178,8 +182,13 @@ public protocol ActivationScreenModel: TitleComponent, DescriptionTextComponent,

// sourcery: generated_component_composite
public protocol InfoViewModel: TitleComponent, DescriptionTextComponent {
// sourcery: genericParameter.name = ProgressIndicatorView
var progressIndicator: ProgressIndicatorModel? { get }
// sourcery: default.value = nil
// sourcery: no_view
var showLoadingIndicator: Bool? { get }

// sourcery: default.value = nil
// sourcery: no_view
var loadingIndicatorText: String? { get }

// sourcery: genericParameter.name = ActionView
var action: _ActionModel? { get }
Expand Down
38 changes: 13 additions & 25 deletions Sources/FioriSwiftUICore/Views/InfoView+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ extension Fiori {
}
}

struct ProgressIndicator: ViewModifier {
func body(content: Content) -> some View {
content
.font(.fiori(forTextStyle: .body))
.foregroundColor(.preferredColor(.primaryLabel))
.multilineTextAlignment(.center)
}
}

struct Action: ViewModifier {
func body(content: Content) -> some View {
content
Expand All @@ -48,40 +39,37 @@ extension Fiori {
.foregroundColor(.preferredColor(.tintColor))
}
}

typealias TitleCumulative = EmptyModifier
typealias DescriptionTextCumulative = EmptyModifier
typealias LoadingIndicatorText = EmptyModifier
typealias LoadingIndicatorTextCumulative = EmptyModifier
typealias ActionCumulative = EmptyModifier
typealias SecondaryActionCumulative = EmptyModifier

typealias ProgressIndicatorStyle = EmptyModifier
typealias ProgressIndicatorStyleCumulative = EmptyModifier
static let title = Title()
static let descriptionText = DescriptionText()
static let progressIndicator = ProgressIndicator()
static let loadingIndicatorText = LoadingIndicatorText()
static let action = Action()
static let secondaryAction = SecondaryAction()
static let progressIndicatorStyle = ProgressIndicatorStyle()

typealias TitleCumulative = EmptyModifier
typealias DescriptionTextCumulative = EmptyModifier
typealias ProgressIndicatorCumulative = EmptyModifier
typealias ActionCumulative = EmptyModifier
typealias SecondaryActionCumulative = EmptyModifier

static let titleCumulative = TitleCumulative()
static let descriptionTextCumulative = DescriptionTextCumulative()
static let progressIndicatorCumulative = ProgressIndicatorCumulative()
static let progressIndicatorStyleCumulative = ProgressIndicatorStyleCumulative()
static let loadingIndicatorTextCumulative = LoadingIndicatorTextCumulative()
static let actionCumulative = ActionCumulative()
static let secondaryActionCumulative = SecondaryActionCumulative()
}
}

extension InfoView: View {
public var body: some View {
VStack {
@State var isPresented: Bool = _showLoadingIndicator ?? false
return VStack {
title
.padding(.top, 80)
.padding(.bottom, 40)
descriptionText
Spacer()
progressIndicator
LoadingIndicatorView(title: AttributedString(_loadingIndicatorText ?? ""), isPresented: $isPresented)
Spacer()
action
.padding(.bottom, 20)
Expand All @@ -98,6 +86,6 @@ extension InfoView: View {
struct InfoViewLibraryContent: LibraryContentProvider {
@LibraryContentBuilder
var views: [LibraryItem] {
LibraryItem(InfoView(title: "SAP BTP SDK for iOS", descriptionText: "SAP BTP SDK for iOS enables you to quickly develop your own native apps, with Swift. The SDK extends the standard Swift Apple iOS frameworks with the reusable UI components from the SAP Fiori for iOS Design Language, and provides APIs which seamlessly integrate apps with SAP BTP services.", action: _Action(actionText: "Primary Button"), secondaryAction: _Action(actionText: "Secondary Button")))
LibraryItem(InfoView(title: "SAP BTP SDK for iOS", descriptionText: "SAP BTP SDK for iOS enables you to quickly develop your own native apps, with Swift. The SDK extends the standard Swift Apple iOS frameworks with the reusable UI components from the SAP Fiori for iOS Design Language, and provides APIs which seamlessly integrate apps with SAP BTP services.", showLoadingIndicator: false, loadingIndicatorText: "", action: _Action(actionText: "Primary Button"), secondaryAction: _Action(actionText: "Secondary Button")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ struct ItemsModifierKey: EnvironmentKey {
public static let defaultValue = AnyViewModifier { $0 }
}

struct ProgressIndicatorModifierKey: EnvironmentKey {
public static let defaultValue = AnyViewModifier { $0 }
}

struct DoneActionModifierKey: EnvironmentKey {
public static let defaultValue = AnyViewModifier { $0 }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ extension EnvironmentValues {
set { self[ItemsModifierKey.self] = newValue }
}

public var progressIndicatorModifier: AnyViewModifier {
get { return self[ProgressIndicatorModifierKey.self] }
set { self[ProgressIndicatorModifierKey.self] = newValue }
}

public var doneActionModifier: AnyViewModifier {
get { return self[DoneActionModifierKey.self] }
set { self[DoneActionModifierKey.self] = newValue }
Expand Down Expand Up @@ -543,11 +538,6 @@ public extension View {
self.environment(\.itemsModifier, AnyViewModifier(transform))
}

@ViewBuilder
func progressIndicatorModifier<V: View>(_ transform: @escaping (AnyViewModifier.Content) -> V) -> some View {
self.environment(\.progressIndicatorModifier, AnyViewModifier(transform))
}

@ViewBuilder
func doneActionModifier<V: View>(_ transform: @escaping (AnyViewModifier.Content) -> V) -> some View {
self.environment(\.doneActionModifier, AnyViewModifier(transform))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@
// DO NOT EDIT
import SwiftUI

public struct InfoView<Title: View, DescriptionText: View, ProgressIndicatorView: View, ActionView: View, SecondaryActionView: View> {
public struct InfoView<Title: View, DescriptionText: View, ActionView: View, SecondaryActionView: View> {
@Environment(\.titleModifier) private var titleModifier
@Environment(\.descriptionTextModifier) private var descriptionTextModifier
@Environment(\.progressIndicatorModifier) private var progressIndicatorModifier
@Environment(\.actionModifier) private var actionModifier
@Environment(\.secondaryActionModifier) private var secondaryActionModifier

let _title: Title
let _descriptionText: DescriptionText
let _progressIndicator: ProgressIndicatorView
let _showLoadingIndicator: Bool?
let _loadingIndicatorText: String?
let _action: ActionView
let _secondaryAction: SecondaryActionView


private var isModelInit: Bool = false
private var isDescriptionTextNil: Bool = false
private var isProgressIndicatorNil: Bool = false
private var isShowLoadingIndicatorNil: Bool = false
private var isLoadingIndicatorTextNil: Bool = false
private var isActionNil: Bool = false
private var isSecondaryActionNil: Bool = false

public init(
@ViewBuilder title: () -> Title,
@ViewBuilder descriptionText: () -> DescriptionText,
@ViewBuilder progressIndicator: () -> ProgressIndicatorView,
showLoadingIndicator: Bool? = nil,
loadingIndicatorText: String? = nil,
@ViewBuilder action: () -> ActionView,
@ViewBuilder secondaryAction: () -> SecondaryActionView
) {
self._title = title()
self._descriptionText = descriptionText()
self._progressIndicator = progressIndicator()
self._showLoadingIndicator = showLoadingIndicator
self._loadingIndicatorText = loadingIndicatorText
self._action = action()
self._secondaryAction = secondaryAction()
}
Expand All @@ -49,13 +52,6 @@ public struct InfoView<Title: View, DescriptionText: View, ProgressIndicatorView
} else {
_descriptionText.modifier(descriptionTextModifier.concat(Fiori.InfoView.descriptionText))
}
}
@ViewBuilder var progressIndicator: some View {
if isModelInit {
_progressIndicator.modifier(progressIndicatorModifier.concat(Fiori.InfoView.progressIndicator).concat(Fiori.InfoView.progressIndicatorCumulative))
} else {
_progressIndicator.modifier(progressIndicatorModifier.concat(Fiori.InfoView.progressIndicator))
}
}
@ViewBuilder var action: some View {
if isModelInit {
Expand All @@ -76,10 +72,6 @@ public struct InfoView<Title: View, DescriptionText: View, ProgressIndicatorView
((isModelInit && isDescriptionTextNil) || DescriptionText.self == EmptyView.self) ? true : false
}

var isProgressIndicatorEmptyView: Bool {
((isModelInit && isProgressIndicatorNil) || ProgressIndicatorView.self == EmptyView.self) ? true : false
}

var isActionEmptyView: Bool {
((isModelInit && isActionNil) || ActionView.self == EmptyView.self) ? true : false
}
Expand All @@ -91,24 +83,25 @@ public struct InfoView<Title: View, DescriptionText: View, ProgressIndicatorView

extension InfoView where Title == Text,
DescriptionText == _ConditionalContent<Text, EmptyView>,
ProgressIndicatorView == _ConditionalContent<ProgressIndicator, EmptyView>,
ActionView == _ConditionalContent<_Action, EmptyView>,
SecondaryActionView == _ConditionalContent<_Action, EmptyView> {

public init(model: InfoViewModel) {
self.init(title: model.title, descriptionText: model.descriptionText, progressIndicator: model.progressIndicator != nil ? ProgressIndicator(model: model.progressIndicator!) : nil, action: model.action != nil ? _Action(model: model.action!) : nil, secondaryAction: model.secondaryAction != nil ? _Action(model: model.secondaryAction!) : nil)
self.init(title: model.title, descriptionText: model.descriptionText, showLoadingIndicator: model.showLoadingIndicator, loadingIndicatorText: model.loadingIndicatorText, action: model.action != nil ? _Action(model: model.action!) : nil, secondaryAction: model.secondaryAction != nil ? _Action(model: model.secondaryAction!) : nil)
}

public init(title: String, descriptionText: String? = nil, progressIndicator: ProgressIndicator? = nil, action: _Action? = nil, secondaryAction: _Action? = nil) {
public init(title: String, descriptionText: String? = nil, showLoadingIndicator: Bool? = nil, loadingIndicatorText: String? = nil, action: _Action? = nil, secondaryAction: _Action? = nil) {
self._title = Text(title)
self._descriptionText = descriptionText != nil ? ViewBuilder.buildEither(first: Text(descriptionText!)) : ViewBuilder.buildEither(second: EmptyView())
self._progressIndicator = progressIndicator != nil ? ViewBuilder.buildEither(first: progressIndicator!) : ViewBuilder.buildEither(second: EmptyView())
self._showLoadingIndicator = showLoadingIndicator
self._loadingIndicatorText = loadingIndicatorText
self._action = action != nil ? ViewBuilder.buildEither(first: action!) : ViewBuilder.buildEither(second: EmptyView())
self._secondaryAction = secondaryAction != nil ? ViewBuilder.buildEither(first: secondaryAction!) : ViewBuilder.buildEither(second: EmptyView())

isModelInit = true
isDescriptionTextNil = descriptionText == nil ? true : false
isProgressIndicatorNil = progressIndicator == nil ? true : false
isShowLoadingIndicatorNil = showLoadingIndicator == nil ? true : false
isLoadingIndicatorTextNil = loadingIndicatorText == nil ? true : false
isActionNil = action == nil ? true : false
isSecondaryActionNil = secondaryAction == nil ? true : false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct ProgressIndicator {

var _progressIndicatorText: String? = nil

public init(model: ProgressIndicatorModel) {
public init(model: _ProgressIndicatorModel) {
self.init(progressIndicatorText: model.progressIndicatorText)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ extension Fiori {
typealias TitleCumulative = EmptyModifier
typealias DescriptionText = EmptyModifier
typealias DescriptionTextCumulative = EmptyModifier
typealias ProgressIndicator = EmptyModifier
typealias ProgressIndicatorCumulative = EmptyModifier
typealias Action = EmptyModifier
typealias ActionCumulative = EmptyModifier
typealias SecondaryAction = EmptyModifier
Expand All @@ -42,12 +40,10 @@ extension Fiori {
*/
static let title = Title()
static let descriptionText = DescriptionText()
static let progressIndicator = ProgressIndicator()
static let action = Action()
static let secondaryAction = SecondaryAction()
static let titleCumulative = TitleCumulative()
static let descriptionTextCumulative = DescriptionTextCumulative()
static let progressIndicatorCumulative = ProgressIndicatorCumulative()
static let actionCumulative = ActionCumulative()
static let secondaryActionCumulative = SecondaryActionCumulative()
}
Expand Down
Loading

0 comments on commit 90866c4

Please sign in to comment.