Skip to content

Commit

Permalink
Merge pull request #1957 from Skyscanner/ACC-472_nudger-has-wrong-lin…
Browse files Browse the repository at this point in the history
…e-limit

ACC-452 - Set multiline limit to title and subtitle
  • Loading branch information
brunomdac committed May 7, 2024
2 parents 31b00bc + b39ca97 commit 2364edc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Backpack-SwiftUI/Nudger/Classes/BPKNudger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import SwiftUI

public struct BPKNudger: View {

@Environment(\.sizeCategory) var sizeCategory
@State private var canIncrement = true
@State private var canDecrement = true
@Binding private var value: Int
Expand Down Expand Up @@ -88,6 +89,7 @@ public struct BPKNudger: View {
self._value = value
}

// swiftlint:disable closure_body_length
public var body: some View {
HStack(spacing: .md) {
if let title {
Expand All @@ -98,10 +100,12 @@ public struct BPKNudger: View {
}
VStack(alignment: .leading) {
BPKText(title, style: .heading5)
.lineLimit(titleLineLimit())

if let subtitle {
BPKText(subtitle)
.foregroundColor(.textSecondaryColor)
.lineLimit(titleLineLimit())
}
}
}
Expand Down Expand Up @@ -140,6 +144,11 @@ public struct BPKNudger: View {
})
}

private func titleLineLimit() -> Int? {
let isDefaultSizeOrSmaller = sizeCategory <= .large
return isDefaultSizeOrSmaller ? 1 : nil
}

private func updateButtonStates() {
canIncrement = value < maxValue
canDecrement = value > minValue
Expand Down
15 changes: 15 additions & 0 deletions Backpack-SwiftUI/Tests/Nudger/BPKNudgerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,19 @@ class BPKNudgerTests: XCTestCase {
)
)
}

func test_dynamic_type_on_title_and_subtitle() {
assertA11ySnapshot(
BPKNudger(
title: "Travellers Travellers",
subtitle: "Aged 16 and older Aged 16 and older",
icon: .adult,
value: .constant(5),
min: 0,
max: 10,
step: 1
),
customHeight: 600
)
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Backpack-SwiftUI/Tests/SnapshotHelpers/SnapshotHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func assertSnapshot<V: View>(
func assertA11ySnapshot<V: View>(
_ view: V,
sizes: [ContentSizeCategory] = [.large, .extraExtraExtraLarge, .accessibilityExtraLarge],
customHeight: CGFloat? = nil,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
Expand All @@ -77,7 +78,8 @@ func assertA11ySnapshot<V: View>(
}
.padding()
.frame(maxWidth: 375)

.frame(height: customHeight)

assertSnapshot(
a11yView,
modes: [.custom(named: "a11y", trait: UITraitCollection(userInterfaceStyle: .light))],
Expand Down

0 comments on commit 2364edc

Please sign in to comment.