Skip to content

Commit

Permalink
feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2224] New FioriButtonStyle support (#603
Browse files Browse the repository at this point in the history
)

* fix: 🐛 map unsupported weight and trait combo to existing fonts

* chore: 🤖 Fix a minor compilation issue

* chore: 🤖 fix a compilation issue

* chore: 🤖 fix a compilation issue

* chore: 🤖 fix a compilation issue

* chore: 🤖 fix a compilation issue in Xcode 14.3

* chore: 🤖 fix an error in installGitHooks script

* chore: 🤖 fix a Sourcery api generation issue

API generated for binding property is not correct

* fix: 🐛 simultaneous gesture is not triggered in voice over

* feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2224] New FioriButtonStyle support

Support FioriPrimaryButtonStyle, FioriSecondaryButtonStyle,
FioriTertiaryButtonStyle

* chore: 🤖 minor change

* Update Sources/FioriSwiftUICore/FioriButton/FioriButton.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButton.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButton.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButton.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/StatefulButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Apps/Examples/Examples/FioriSwiftUICore/FioriButton/FioriButtonExample.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/StatefulButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/StatefulButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/StatefulButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update Sources/FioriSwiftUICore/FioriButton/FioriButtonStyle.swift

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>

* Update FioriButtonStyle.swift

* Update StatefulButtonStyle.swift

---------

Co-authored-by: AndyRogersSAP <53194232+AndyRogersSAP@users.noreply.github.com>
  • Loading branch information
billzhou0223 and AndyRogersSAP authored Oct 19, 2023
1 parent 6d09d0f commit 4890872
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 194 deletions.
14 changes: 13 additions & 1 deletion Apps/Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
108E43D5292DAB7C006532F3 /* EmptyStateViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 108E43D4292DAB7C006532F3 /* EmptyStateViewExample.swift */; };
1F26DCFA261A5CD9006C43B1 /* FioriButtonContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F26DCF9261A5CD9006C43B1 /* FioriButtonContentView.swift */; };
1F3C92F125DF12C100A99A07 /* ListPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F3C92F025DF12C100A99A07 /* ListPicker.swift */; };
1F55FEF32AC941FF00D7A1BE /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F55FEF22AC941FF00D7A1BE /* View+Extensions.swift */; };
1F60179729A8439A00DBDCDE /* WatchExamplesApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F60179629A8439A00DBDCDE /* WatchExamplesApp.swift */; };
1F60179929A8439A00DBDCDE /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F60179829A8439A00DBDCDE /* ContentView.swift */; };
1F60179B29A8439C00DBDCDE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1F60179A29A8439C00DBDCDE /* Assets.xcassets */; };
Expand Down Expand Up @@ -151,6 +152,7 @@
108E43D4292DAB7C006532F3 /* EmptyStateViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyStateViewExample.swift; sourceTree = "<group>"; };
1F26DCF9261A5CD9006C43B1 /* FioriButtonContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FioriButtonContentView.swift; sourceTree = "<group>"; };
1F3C92F025DF12C100A99A07 /* ListPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListPicker.swift; sourceTree = "<group>"; };
1F55FEF22AC941FF00D7A1BE /* View+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = "<group>"; };
1F60179429A8439A00DBDCDE /* WatchExamples Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "WatchExamples Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
1F60179629A8439A00DBDCDE /* WatchExamplesApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchExamplesApp.swift; sourceTree = "<group>"; };
1F60179829A8439A00DBDCDE /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -286,6 +288,14 @@
path = FioriButton;
sourceTree = "<group>";
};
1F55FEF12AC941C100D7A1BE /* Utility */ = {
isa = PBXGroup;
children = (
1F55FEF22AC941FF00D7A1BE /* View+Extensions.swift */,
);
path = Utility;
sourceTree = "<group>";
};
1F60179529A8439A00DBDCDE /* WatchExamples Watch App */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -364,6 +374,7 @@
8A55795524C1286E0098003A /* Examples */ = {
isa = PBXGroup;
children = (
1F55FEF12AC941C100D7A1BE /* Utility */,
1FC3040F2705409C004BEE00 /* FioriThemeManager */,
8A55797824C1293C0098003A /* FioriCharts */,
8A5579C824C1293C0098003A /* FioriSwiftUICore */,
Expand Down Expand Up @@ -723,6 +734,7 @@
8A5579CC24C1293C0098003A /* SettingsColorForCategory.swift in Sources */,
8A557A1A24C12C820098003A /* ChartsContentView.swift in Sources */,
8A5579CE24C1293C0098003A /* SettingColor.swift in Sources */,
1F55FEF32AC941FF00D7A1BE /* View+Extensions.swift in Sources */,
8A6DE30B28DD27F9003222E3 /* Colors.swift in Sources */,
8AD9DFB225D49967007448EC /* StylingModifierExample.swift in Sources */,
8A5579D124C1293C0098003A /* Settings.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,54 @@ import SwiftUI
struct FioriButtonExample: View {
@State private var _withCustomStyle = false
@State private var _isSelectionPersistent = false
@State private var _buttonStyle = "Primary"
@State private var _colorStyle = FioriButtonColorStyle.tint
@State private var _isEnabled = true
@State private var _showSettings = false

var fioriButtonStyle: AnyFioriButtonStyle {
switch self._buttonStyle {
case "Primary":
return FioriPrimaryButtonStyle().eraseToAnyFioriButtonStyle()
case "Secondary":
return FioriSecondaryButtonStyle(colorStyle: self._colorStyle).eraseToAnyFioriButtonStyle()
default:
return FioriTertiaryButtonStyle(colorStyle: self._colorStyle).eraseToAnyFioriButtonStyle()
}
}

var body: some View {
Group {
if _withCustomStyle {
makeBody()
.fioriButtonStyle(CustomFioriButtonStyle())
} else {
makeBody()
.fioriButtonStyle(fioriButtonStyle)
}
}
.navigationBarItems(trailing: Button("Config") {
self._showSettings.toggle()
})
.sheet(isPresented: self.$_showSettings) {
Form {
Toggle("isEnabled", isOn: self.$_isEnabled)
Toggle("isSelectionPersistent", isOn: self.$_isSelectionPersistent)
Toggle("custom style", isOn: self.$_withCustomStyle)
.settingsSheet(isPresented: $_showSettings) {
Toggle("isEnabled", isOn: self.$_isEnabled)
Toggle("isSelectionPersistent", isOn: self.$_isSelectionPersistent)
if !_withCustomStyle {
Picker(selection: $_buttonStyle) {
Text("Primary Button").tag("Primary")
Text("Secondary Button").tag("Secondary")
Text("Tertiary Button").tag("Tertiary")
} label: {
Text("button style")
}
if _buttonStyle != "Primary" {
Picker(selection: $_colorStyle) {
Text("tint").tag(FioriButtonColorStyle.tint)
Text("normal").tag(FioriButtonColorStyle.normal)
Text("negative").tag(FioriButtonColorStyle.negative)
} label: {
Text("color style")
}
}
}
Toggle("custom style", isOn: self.$_withCustomStyle)
}
}

Expand Down Expand Up @@ -56,19 +83,6 @@ struct FioriButtonExample: View {
}
}

struct StatefulButtonStyleExample: View {
var body: some View {
Button(action: { print("add tapped") }, label: {
HStack {
Image(systemName: "plus")
Text("Add")
}
})
.buttonStyle(StatefulButtonStyle())
.padding()
}
}

struct CustomFioriButtonStyle: FioriButtonStyle {
func makeBody(configuration: FioriButtonStyle.Configuration) -> some View {
let color: Color
Expand All @@ -88,10 +102,87 @@ struct CustomFioriButtonStyle: FioriButtonStyle {
}
}

struct StatefulButtonStyleExample: View {
@State var _showSettings = false
@State private var _isSelectionPersistent = false
@State private var _buttonStyle = "Primary"
@State private var _colorStyle = FioriButtonColorStyle.tint
@State private var _isEnabled = true

var primitiveButtonStyle: AnyPrimitiveButtonStyle {
switch self._buttonStyle {
case "Primary":
return PrimaryButtonStyle(isSelectionPersistent: _isSelectionPersistent).eraseToAnyPrimitiveButtonStyle()
case "Secondary":
return SecondaryButtonStyle(colorStyle: _colorStyle, isSelectionPersistent: _isSelectionPersistent).eraseToAnyPrimitiveButtonStyle()
default:
return TertiaryButtonStyle(colorStyle: _colorStyle, isSelectionPersistent: _isSelectionPersistent).eraseToAnyPrimitiveButtonStyle()
}
}

var body: some View {
Button(action: { print("add tapped") }, label: {
HStack {
Image(systemName: "plus")
Text("Add")
}
})
.buttonStyle(primitiveButtonStyle)
.disabled(!_isEnabled)
.settingsSheet(isPresented: $_showSettings) {
Toggle("isEnabled", isOn: self.$_isEnabled)
Toggle("isSelectionPersistent", isOn: self.$_isSelectionPersistent)
Picker(selection: $_buttonStyle) {
Text("Primary Button").tag("Primary")
Text("Secondary Button").tag("Secondary")
Text("Tertiary Button").tag("Tertiary")
} label: {
Text("button style")
}
if _buttonStyle != "Primary" {
Picker(selection: $_colorStyle) {
Text("tint").tag(FioriButtonColorStyle.tint)
Text("normal").tag(FioriButtonColorStyle.normal)
Text("negative").tag(FioriButtonColorStyle.negative)
} label: {
Text("color style")
}
}
}
}
}

/// A type-erased button style.
struct AnyPrimitiveButtonStyle: PrimitiveButtonStyle {
let view: (PrimitiveButtonStyleConfiguration) -> AnyView

public init<S: PrimitiveButtonStyle>(_ style: S) {
self.view = {
AnyView(style.makeBody(configuration: $0))
}
}

public func makeBody(configuration: Configuration) -> some View {
self.view(configuration)
}
}

extension PrimitiveButtonStyle {
/// Return a type-erased button style.
/// - Returns: An `AnyPrimitiveButtonStyle` wrapping this button style.
func eraseToAnyPrimitiveButtonStyle() -> AnyPrimitiveButtonStyle {
AnyPrimitiveButtonStyle(self)
}
}

struct PreviewView: PreviewProvider {
static var previews: some View {
FioriButtonExample()
NavigationView{
FioriButtonExample()
}

StatefulButtonStyleExample()
NavigationView {
StatefulButtonStyleExample()
}
}
}
34 changes: 34 additions & 0 deletions Apps/Examples/Examples/Utility/View+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// View+Extensions.swift
// Examples
//
// Created by Zhou, Bill on 9/30/23.
// Copyright © 2023 SAP. All rights reserved.
//

import Foundation
import SwiftUI

extension View {
/// A sheet that can be presented by a settings button in the nav bar for configuring components in a test app.
/// - Parameters:
/// - isPresented: A binding to a Boolean value that determines whether to present the sheet that you create in the modifier’s content closure.
/// - content: A closure that returns the content of the sheet.
func settingsSheet<V: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> V) -> some View {
return self
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button {
isPresented.wrappedValue.toggle()
} label: {
Image(systemName: "gearshape")
}
}
}
.sheet(isPresented: isPresented) {
Form {
content()
}
}
}
}
Loading

0 comments on commit 4890872

Please sign in to comment.