Skip to content

Commit

Permalink
refactor: 💡 [HCPSDKFIORIUIKIT-2892]SwitchPickerItem Refactor (#953)
Browse files Browse the repository at this point in the history
Co-authored-by: dyongxu <[email protected]>
  • Loading branch information
restaurantt and dyongxu authored Jan 13, 2025
1 parent 1f6bcad commit 0802d8a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ struct SwitchExample: View {
@State var v1: Bool = false
@State var v2: Bool = true
@State var v3: Bool = true

@State var v4: Bool = true

struct CustomTitleStyle: TitleStyle {
@Environment(\.isEnabled) var isEnabled
func makeBody(_ configuration: TitleConfiguration) -> some View {
Expand All @@ -30,6 +31,7 @@ struct SwitchExample: View {
SwitchView(title: "Custom Style", isOn: self.$v3)
.titleStyle(CustomTitleStyle())
.switchStyle(CustomSwitchStyle())
SwitchView(title: "Very long title, layout depend on title width. long long long long long long long long long long long long long long long long long long long long long long long", isOn: self.$v4)
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/FioriSwiftUICore/Models/ModelDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ public protocol SearchListPickerItemModel: OptionListPickerComponent {
// sourcery: add_env_props = "filterFeedbackBarStyle"
// sourcery: generated_component_not_configurable
// sourcery: add_env_props = "fioriToggleStyle"
public protocol SwitchPickerItemModel: SwitchPickerComponent {}
public protocol _SwitchPickerItemModel: SwitchPickerComponent {}

@available(*, unavailable, renamed: "_SwitchPickerItemModel", message: "Will be removed in the future release. Please create SwitchView with other initializers instead.")
public protocol SwitchPickerItemModel {}

// sourcery: add_env_props = "filterFeedbackBarStyle"
// sourcery: generated_component_not_configurable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ extension _SortFilterCFGItemContainer: View {

func switcher(row r: Int, column c: Int) -> some View {
VStack {
SwitchPickerItem(value: Binding<Bool?>(get: { self._items[r][c].switch.workingValue }, set: { self._items[r][c].switch.workingValue = $0 }), name: self._items[r][c].switch.name, hint: nil)
SwitchView(title: AttributedString(self._items[r][c].switch.name), isOn: Binding<Bool>(get: { self._items[r][c].switch.workingValue ?? false }, set: { self._items[r][c].switch.workingValue = $0 }))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FioriThemeManager
import SwiftUI

extension SwitchPickerItem: View {
extension _SwitchPickerItem: View {
public var body: some View {
AnyView(
Toggle(_name ?? "", isOn: .convert(from: _value, ifNilUse: false))
Expand Down Expand Up @@ -122,9 +122,9 @@ private struct TestSwitchPicker: View {

var body: some View {
VStack {
SwitchPickerItem(value: self.$v1, hint: nil)
SwitchPickerItem(value: self.$v2, hint: nil)
SwitchPickerItem(value: self.$v3, hint: nil)
_SwitchPickerItem(value: self.$v1, hint: nil)
_SwitchPickerItem(value: self.$v2, hint: nil)
_SwitchPickerItem(value: self.$v3, hint: nil)
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions Sources/FioriSwiftUICore/_FioriStyles/SwitchViewStyle.fiori.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ import SwiftUI
// Base Layout style
public struct SwitchViewBaseStyle: SwitchViewStyle {
public func makeBody(_ configuration: SwitchViewConfiguration) -> some View {
HStack {
configuration.title
Spacer()
configuration._switch
ViewThatFits {
HStack {
configuration.title
Spacer()
configuration._switch
}
VStack(alignment: .leading, spacing: 0) {
configuration.title
HStack {
Spacer()
configuration._switch
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// DO NOT EDIT
import SwiftUI

public struct SwitchPickerItem {
public struct _SwitchPickerItem {
@Environment(\.fioriToggleStyle) var fioriToggleStyle
@Environment(\.filterFeedbackBarStyle) var filterFeedbackBarStyle

var _value: Binding<Bool?>
var _name: String? = nil
var _hint: String? = nil

public init(model: SwitchPickerItemModel) {
public init(model: _SwitchPickerItemModel) {
self.init(value: Binding<Bool?>(get: { model.value }, set: { model.value = $0 }), name: model.name, hint: model.hint)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
//TODO: Copy commented code to new file: `FioriSwiftUICore/Views/SwitchPickerItem+View.swift`
//TODO: Implement SwitchPickerItem `View` body
//TODO: Copy commented code to new file: `FioriSwiftUICore/Views/_SwitchPickerItem+View.swift`
//TODO: Implement _SwitchPickerItem `View` body

/// - Important: to make `@Environment` properties (e.g. `horizontalSizeClass`), internally accessible
/// to extensions, add as sourcery annotation in `FioriSwiftUICore/Models/ModelDefinitions.swift`
Expand All @@ -13,21 +13,21 @@ import SwiftUI

// FIXME: - Implement Fiori style definitions

// FIXME: - Implement SwitchPickerItem View body
// FIXME: - Implement _SwitchPickerItem View body

extension SwitchPickerItem: View {
extension _SwitchPickerItem: View {
public var body: some View {
<# View body #>
}
}

// FIXME: - Implement SwitchPickerItem specific LibraryContentProvider
// FIXME: - Implement _SwitchPickerItem specific LibraryContentProvider

@available(iOS 14.0, macOS 11.0, *)
struct SwitchPickerItemLibraryContent: LibraryContentProvider {
struct _SwitchPickerItemLibraryContent: LibraryContentProvider {
@LibraryContentBuilder
var views: [LibraryItem] {
LibraryItem(SwitchPickerItem(model: LibraryPreviewData.Person.laurelosborn),
LibraryItem(_SwitchPickerItem(model: LibraryPreviewData.Person.laurelosborn),
category: .control)
}
}
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion sourcery/.lib/Sources/utils/Type+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public extension Type {
"_SingleStepModel",
"_StepProgressIndicatorModel",
"_ObjectHeaderModel",
"_HeaderChartModel"]
"_HeaderChartModel",
"_SwitchPickerItemModel"]

if deprecatedComponents.contains(name) {
return name.replacingOccurrences(of: "Model", with: "")
Expand Down

0 comments on commit 0802d8a

Please sign in to comment.