Skip to content

Commit

Permalink
fix: 🐛 step progress indicator alignment (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyu0722 authored May 12, 2023
1 parent 71bd6df commit 79658a8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Sources/FioriSwiftUICore/Models/ModelDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public protocol KPIHeaderItemModel {}
// sourcery: virtualPropBottom = "var bottom: CGFloat = 8"
// sourcery: virtualPropLeading = "var leading: CGFloat = 8"
// sourcery: virtualPropTrailing = "var trailing: CGFloat = 8"
// sourcery: virtualPropHorizontalSpacing = "var horizontalSpacing: CGFloat = 14"
// sourcery: virtualPropHorizontalSpacing = "var horizontalSpacing: CGFloat = 8"
// sourcery: virtualPropStepState = "var state: StepIndicatorState?"
// sourcery: virtualPropIsLastStep = "var isLastStep: Bool = false"
// sourcery: generated_component_composite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ struct InnerSingleStep<Title: View, Node: View, Line: View>: View {
.alignmentGuide(.stepsTopAlignment) {
($0.height - ($0[.lastTextBaseline] - $0[.firstTextBaseline])) / 2
}
.alignmentGuide(.stepsLeadingAlignment) { $0[.leading] }
Spacer().frame(width: trailing)
Spacer()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

/// Step items data model for `StepProgressIndicator` with a default style.
public struct StepItem: Identifiable {
/// Step id.
public var id = UUID().uuidString
/// Step title.
public var title: String?
/// Step state.
public var state: StepIndicatorState
/// Sub-steps for this one.
public var substeps: [StepItem]

/// Convenience initialization for step tiem.
/// - Parameters:
/// - id: Step id.
/// - title: Step title.
/// - state: Step state.
/// - children: Sub-steps for this one.
public init(id: String = UUID().uuidString,
title: String? = nil,
state: StepIndicatorState = [],
substeps: [StepItem] = [])
{
self.id = id
self.title = title
self.state = state
self.substeps = substeps
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ extension StepProgressIndicator: View {
title
Spacer()
action
.simultaneousGesture(TapGesture().onEnded { _ in
self.isPresented.toggle()
})
.simultaneousGesture(LongPressGesture().onEnded { _ in
.simultaneousGesture(LongPressGesture(minimumDuration: 0).onEnded { _ in
self.isPresented.toggle()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct StepProgressIndicatorContainer<Steps: IndexedViewContainer>: View {
}
}
case .vertical:
VStack(alignment: .leading, spacing: stepsSpacing) {
VStack(alignment: .stepsLeadingAlignment, spacing: stepsSpacing) {
ForEach(0 ..< steps.count, id: \.self) { index in
steps.view(at: index)
.environment(\.stepAxis, stepAxis)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import FioriThemeManager
import SwiftUI

/// Step items data model for `StepProgressIndicator` with a default style.
public struct StepItem: Identifiable {
/// Step id.
public var id = UUID().uuidString
/// Step title.
public var title: String?
/// Step state.
public var state: StepIndicatorState
/// Sub-steps for this one.
public var substeps: [StepItem]

/// Convenience initialization for step tiem.
/// - Parameters:
/// - id: Step id.
/// - title: Step title.
/// - state: Step state.
/// - children: Sub-steps for this one.
public init(id: String = UUID().uuidString,
title: String? = nil,
state: StepIndicatorState = [],
substeps: [StepItem] = [])
{
self.id = id
self.title = title
self.state = state
self.substeps = substeps
}
}

extension VerticalAlignment {
private enum StepsTopAlignment: AlignmentID {
static func defaultValue(in dimensions: ViewDimensions) -> CGFloat {
Expand All @@ -38,6 +9,24 @@ extension VerticalAlignment {
}

static let stepsTopAlignment = VerticalAlignment(StepsTopAlignment.self)

private enum StepsNodeCenterAlignment: AlignmentID {
static func defaultValue(in dimensions: ViewDimensions) -> CGFloat {
dimensions[VerticalAlignment.center]
}
}

static let stepsNodeCenterAlignment = VerticalAlignment(StepsNodeCenterAlignment.self)
}

extension HorizontalAlignment {
private enum StepsLeadingAlignment: AlignmentID {
static func defaultValue(in dimensions: ViewDimensions) -> CGFloat {
dimensions[HorizontalAlignment.leading]
}
}

static let stepsLeadingAlignment = HorizontalAlignment(StepsLeadingAlignment.self)
}

struct StepButtonStyle: ButtonStyle {
Expand Down Expand Up @@ -85,23 +74,23 @@ struct StepButtonStyle: ButtonStyle {
if let s = stepStyle(id) {
s.makeNode(configuration: stepConfig).typeErased
} else {
stepConfig.node
DefaultStepStyle().makeNode(configuration: stepConfig).typeErased
}
}

@ViewBuilder func generateTitle(_ stepConfig: StepConfiguration) -> some View {
if let s = stepStyle(id) {
s.makeTitle(configuration: stepConfig).typeErased
} else {
stepConfig.title
DefaultStepStyle().makeTitle(configuration: stepConfig).typeErased
}
}

@ViewBuilder func generateLine(_ stepConfig: StepConfiguration) -> some View {
if let s = stepStyle(id) {
s.makeLine(configuration: stepConfig).typeErased
} else {
stepConfig.line
DefaultStepStyle().makeLine(configuration: stepConfig).typeErased
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public struct SingleStep<Title: View, Node: View, Substeps: IndexedViewContainer
var _title: Title
var _node: Node
var _substeps: Substeps
var horizontalSpacing: CGFloat = 14
var horizontalSpacing: CGFloat = 8
var trailing: CGFloat = 8
var bottom: CGFloat = 8
var state: StepIndicatorState?
Expand Down

0 comments on commit 79658a8

Please sign in to comment.