Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swiftlint step to CI #14

Merged
merged 4 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ on:
branches: [ "main" ]

jobs:
lint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: cirruslabs/swiftlint-action@v1
with:
version: latest

build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: Build for iOS
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ let package = Package(
products: [
.library(
name: "SegmentedPicker",
targets: ["SegmentedPicker"]),
targets: ["SegmentedPicker"])
],
dependencies: [
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.12.0"
)

],
targets: [
.target(
Expand All @@ -30,6 +30,6 @@ let package = Package(
dependencies: [
"SegmentedPicker",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
]),
])
]
)
2 changes: 1 addition & 1 deletion Sources/SegmentedPicker/HorizontalAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension HorizontalAlignment {
return dimension[HorizontalAlignment.center]
}
}

static var horizontalCenterAlignment: HorizontalAlignment {
HorizontalAlignment(CenterAlignmentID.self)
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/SegmentedPicker/SegmentedPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public struct SegmentedPicker<Element, Content, Selection>: View
where
Content: View,
Selection: View {

public typealias Data = [Element]

@State private var segmentSizes: [Data.Index: CGSize] = [:]
@Binding private var selectedIndex: Data.Index?

Expand All @@ -34,7 +34,7 @@ public struct SegmentedPicker<Element, Content, Selection>: View
self._selectedIndex = selectedIndex
self.selectionAlignment = selectionAlignment
}

public var body: some View {
ZStack(alignment: Alignment(horizontal: .horizontalCenterAlignment,
vertical: selectionAlignment)) {
Expand Down Expand Up @@ -74,7 +74,7 @@ public struct SegmentedPicker<Element, Content, Selection>: View
}

private extension SegmentedPicker {

func selectionSize(at index: Data.Index) -> CGSize {
segmentSizes[index] ?? .zero
}
Expand All @@ -85,13 +85,13 @@ private extension SegmentedPicker {
let index: Int
let size: CGSize
}

struct SegmentSizePreferenceKey: PreferenceKey {
static var defaultValue: SegmentSize { SegmentSize(index: .zero, size: .zero) }
static func reduce(value: inout SegmentSize,

static func reduce(value: inout SegmentSize,
nextValue: () -> SegmentSize) {

value = nextValue()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SegmentedPickerTests/CapsuleSelectionViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import UIKit
import XCTest
import SnapshotTesting
@testable import SegmentedPicker

final class CapsuleSelectionViewTests: XCTestCase {
func test_WhenSelectionIsNotProvided_SelectionIsNotVisible_Snapshot() {
let view = CapsuleSelectionView(titles: ["One", "Two", "Three"])
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
}

func test_WhenSelectionIsProvided_SelectionIsVisible_Snapshot() {
let view = CapsuleSelectionView(titles: ["One", "Two", "Three"], selectedIndex: 1)
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct CapsuleSelectionView: View {
.fill(Color.gray)
})
}

Spacer()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct UnderlineSelectionView: View {
let titles: [String]
@State var selectedIndex: Int?

var body: some View {
VStack {
SegmentedPicker(
Expand All @@ -22,7 +22,7 @@ struct UnderlineSelectionView: View {
selectionAlignment: .bottom,
content: { item, isSelected in
Text(item)

.foregroundColor(isSelected ? Color.black : Color.gray )
.padding(.horizontal, 16)
.padding(.vertical, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class UnderlineSelectionViewTest: XCTestCase {
let view = UnderlineSelectionView(titles: ["One", "Two", "Three"])
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
}

func test_WhenSelectionIsProvided_SelectionIsVisible_Snapshot() {
let view = UnderlineSelectionView(titles: ["One", "Two", "Three"], selectedIndex: 1)
assertSnapshots(of: view, as: [.image(layout: .device(config: .iPhone13))])
Expand Down