Skip to content

Commit a8641f9

Browse files
authored
Merge pull request #54 from daangn/feature/elon/IOS-1269-add-AddComponentModifier-macro
IOS-1269 feat: add AddComponentModifier Macro
2 parents 817be32 + 7810731 commit a8641f9

58 files changed

Lines changed: 731 additions & 74 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci-sampleapp.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
workflow_dispatch:
1212

1313
concurrency:
14-
group: ${{ github.head_ref || github.run_id }}
14+
group: "${{ github.workflow }}-${{ github.head_ref || github.run_id }}-${{ github.job }}"
1515
cancel-in-progress: true
1616

1717
jobs:
@@ -29,9 +29,13 @@ jobs:
2929
- uses: actions/checkout@v4
3030

3131
- name: Setup Xcode Version
32-
run: sudo xcode-select --switch /Applications/Xcode_16.4.app/Contents/Developer
32+
run: sudo xcode-select --switch /Applications/Xcode_16.4.app
3333
shell: bash
3434

35+
- name: Set Swift Syntax Prebuilts
36+
run: |
37+
defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts YES
38+
3539
- name: Run `build-for-testing`
3640
run: |
3741
set -o pipefail && xcodebuild build-for-testing \

.github/workflows/ci.yml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ on:
1010
workflow_dispatch:
1111

1212
concurrency:
13-
group: ${{ github.head_ref || github.run_id }}
13+
group: "${{ github.workflow }}-${{ github.head_ref || github.run_id }}-${{ github.job }}"
1414
cancel-in-progress: true
1515

1616
jobs:
1717
build_and_test:
18+
name: Build and Test
1819
runs-on: macos-15
20+
strategy:
21+
matrix:
22+
xcode: ['16.4']
23+
config: ['Debug', 'Release']
1924

2025
env:
2126
SCHEME: KarrotListKit
@@ -24,22 +29,38 @@ jobs:
2429
steps:
2530
- uses: actions/checkout@v4
2631

27-
- name: Setup Xcode Version
28-
run: sudo xcode-select --switch /Applications/Xcode_16.4.app/Contents/Developer
32+
- name: Setup Xcode ${{ matrix.xcode }}
33+
run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode }}.app
2934
shell: bash
3035

36+
- name: Set Swift Syntax Prebuilts
37+
run: |
38+
defaults write com.apple.dt.Xcode IDEPackageEnablePrebuilts YES
39+
3140
- name: Run `build-for-testing`
3241
run: |
3342
set -o pipefail && xcodebuild build-for-testing \
3443
-scheme "$SCHEME" \
3544
-destination "$DESTINATION" \
36-
-configuration Debug \
45+
-configuration ${{ matrix.config }} \
46+
ENABLE_TESTABILITY=YES \
3747
| xcbeautify --renderer github-actions
3848
3949
- name: Run `test-without-building`
4050
run: |
4151
set -o pipefail && xcodebuild test-without-building \
4252
-scheme "$SCHEME" \
4353
-destination "$DESTINATION" \
44-
-configuration Debug \
54+
-configuration ${{ matrix.config }} \
55+
ENABLE_TESTABILITY=YES \
4556
| xcbeautify --renderer github-actions
57+
58+
check-macro-compatibility:
59+
name: Check Macro Compatibility
60+
runs-on: macos-latest
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v4
64+
65+
- name: Run Swift Macro Compatibility Check
66+
uses: Matejkob/swift-macro-compatibility-check@v1

Examples/KarrotListKitSampleApp/KarrotListKitSampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 48 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/KarrotListKitSampleApp/KarrotListKitSampleApp/Samples/VerticalLayout/VerticalLayoutItemComponent.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ struct VerticalLayoutItemComponent: Component {
1010

1111
let viewModel: ViewModel
1212

13+
@AddComponentModifier
14+
var onTapButtonHandler: (() -> Void)?
15+
16+
@AddComponentModifier
17+
var onTapButtonWithValueHandler: ((Int) -> Void)?
18+
19+
@AddComponentModifier
20+
var onTapButtonWithValuesHandler: ((Int, String) -> Void)?
21+
22+
@AddComponentModifier
23+
var onTapButtonWithNamedValuesHandler: ((_ intValue: Int, _ stringValue: String) -> Void)?
24+
1325
init(viewModel: ViewModel) {
1426
self.viewModel = viewModel
1527
}

Package.resolved

Lines changed: 20 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
// swift-tools-version: 5.5
1+
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

4+
import CompilerPluginSupport
45
import PackageDescription
56

67
let package = Package(
78
name: "KarrotListKit",
8-
platforms: [.iOS(.v13)],
9+
platforms: [.iOS(.v13), .macOS(.v10_15)],
910
products: [
1011
.library(
1112
name: "KarrotListKit",
1213
targets: ["KarrotListKit"]
1314
),
1415
],
1516
dependencies: [
17+
.package(url: "https://github.com/swiftlang/swift-syntax.git", "509.0.0"..<"602.0.0"),
1618
.package(
1719
url: "https://github.com/ra1028/DifferenceKit.git",
1820
.upToNextMajor(from: "1.0.0")
@@ -23,11 +25,26 @@ let package = Package(
2325
name: "KarrotListKit",
2426
dependencies: [
2527
"DifferenceKit",
28+
"KarrotListKitMacros",
29+
]
30+
),
31+
.macro(
32+
name: "KarrotListKitMacros",
33+
dependencies: [
34+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
35+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
2636
]
2737
),
2838
.testTarget(
2939
name: "KarrotListKitTests",
3040
dependencies: ["KarrotListKit"]
3141
),
42+
.testTarget(
43+
name: "KarrotListKitMacrosTests",
44+
dependencies: [
45+
"KarrotListKitMacros",
46+
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
47+
]
48+
),
3249
]
3350
)

Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
//
44

55
import Combine
6-
import UIKit
7-
86
import DifferenceKit
97

8+
#if canImport(UIKit)
9+
import UIKit
10+
1011
/// An adapter for `UICollectionView`
1112
///
1213
/// The `CollectionViewAdapter` object serves as an adapter between the `UIColletionView` logic and the `KarrotListKit` logic
@@ -772,3 +773,4 @@ extension CollectionViewAdapter: UICollectionViewDataSource {
772773
}
773774
}
774775
}
776+
#endif

Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) 2024 Danggeun Market Inc.
33
//
44

5+
#if canImport(UIKit)
56
import UIKit
67

78
/// The configuration for the CollectionViewAdapter object.
@@ -67,3 +68,4 @@ extension CollectionViewAdapterConfiguration {
6768
}
6869
}
6970
}
71+
#endif

Sources/KarrotListKit/Adapter/CollectionViewLayoutAdaptable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) 2024 Danggeun Market Inc.
33
//
44

5+
#if canImport(UIKit)
56
import UIKit
67

78
/// A protocol that manage data and size information for List
@@ -88,3 +89,4 @@ public class CollectionViewLayoutAdapter: CollectionViewLayoutAdaptable {
8889
)
8990
}
9091
}
92+
#endif

Sources/KarrotListKit/Adapter/ComponentSizeStorage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import Foundation
66

7+
#if canImport(UIKit)
8+
import CoreGraphics
9+
710
/// A protocol that defines the functionality for storing the sizes of components.
811
public protocol ComponentSizeStorage {
912

@@ -79,3 +82,4 @@ final class ComponentSizeStorageImpl: ComponentSizeStorage {
7982
footerSizeStore[hash] = size
8083
}
8184
}
85+
#endif

0 commit comments

Comments
 (0)