Skip to content

Commit 004ce94

Browse files
Merge branch 'main' of https://github.com/hactar/maplibre-swiftui-dsl-playground into enhancement/camera-bounding-box
# Conflicts: # Package.resolved # Sources/MapLibreSwiftUI/Models/MapCamera/CameraState.swift # Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift # Tests/MapLibreSwiftUITests/Models/MapCamera/CameraStateTests.swift # Tests/MapLibreSwiftUITests/Models/MapCamera/MapViewCameraTests.swift
2 parents 9c78e13 + 6b59504 commit 004ce94

Some content is hidden

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

53 files changed

+642
-565
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Maplibre-SwiftUI
1+
name: Release
22

33
on:
44
push:

.github/workflows/test.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test maplibre-swiftui-dsl-playground
1+
name: Test
22

33
on:
44
push:
@@ -7,6 +7,19 @@ on:
77
branches: [ main ]
88

99
jobs:
10+
format-lint:
11+
runs-on: macos-14
12+
13+
steps:
14+
- name: Install tools
15+
run: brew install swiftformat
16+
17+
- name: Checkout maplibre-swiftui-dsl-playground
18+
uses: actions/checkout@v3
19+
20+
- name: Check format
21+
run: swiftformat . --lint
22+
1023
test:
1124
runs-on: macos-14
1225
strategy:
@@ -20,15 +33,15 @@ jobs:
2033
]
2134

2235
steps:
23-
- name: Install xcbeautify
36+
- name: Install tools
2437
run: brew install xcbeautify
25-
38+
2639
- uses: maxim-lobanov/setup-xcode@v1
2740
with:
2841
xcode-version: '15.0'
2942

3043
- name: Checkout maplibre-swiftui-dsl-playground
3144
uses: actions/checkout@v3
32-
45+
3346
- name: Test ${{ matrix.scheme }} on ${{ matrix.destination }}
3447
run: xcodebuild -scheme ${{ matrix.scheme }} test -skipMacroValidation -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]}

.spi.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [MapLibreSwiftUI]
5+
platform: ios

.swiftformat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# file options
2+
3+
--exclude .build
4+
5+
# format options
6+
7+
--header ""
8+
--indent 4
9+
--importgrouping testable-bottom
10+
--maxwidth 120
11+
--swiftversion 5.9
12+
13+
# rules
14+
15+
--enable isEmpty

Package.resolved

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

Package.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

4-
import PackageDescription
54
import CompilerPluginSupport
5+
import PackageDescription
66

77
let package = Package(
88
name: "MapLibreSwiftUI",
@@ -13,14 +13,16 @@ let package = Package(
1313
products: [
1414
.library(
1515
name: "MapLibreSwiftUI",
16-
targets: ["MapLibreSwiftUI"]),
16+
targets: ["MapLibreSwiftUI"]
17+
),
1718
.library(
1819
name: "MapLibreSwiftDSL",
19-
targets: ["MapLibreSwiftDSL"]),
20+
targets: ["MapLibreSwiftDSL"]
21+
),
2022
],
2123
dependencies: [
2224
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.1.0"),
23-
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", branch: "main"),
25+
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", from: "0.0.2"),
2426
// Testing
2527
.package(url: "https://github.com/Kolos65/Mockable.git", from: "0.0.2"),
2628
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.3"),
@@ -32,37 +34,38 @@ let package = Package(
3234
.target(name: "InternalUtils"),
3335
.target(name: "MapLibreSwiftDSL"),
3436
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
35-
.product(name: "Mockable", package: "Mockable")
37+
.product(name: "Mockable", package: "Mockable"),
3638
],
3739
swiftSettings: [
38-
.define("MOCKING", .when(configuration: .debug))
39-
]),
40+
.define("MOCKING", .when(configuration: .debug)),
41+
]
42+
),
4043
.target(
4144
name: "MapLibreSwiftDSL",
4245
dependencies: [
4346
.target(name: "InternalUtils"),
4447
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
45-
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros")
48+
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros"),
4649
]
4750
),
4851
.target(
4952
name: "InternalUtils"
5053
),
51-
54+
5255
// MARK: Tests
53-
56+
5457
.testTarget(
5558
name: "MapLibreSwiftUITests",
5659
dependencies: [
5760
"MapLibreSwiftUI",
5861
.product(name: "MockableTest", package: "Mockable"),
59-
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
62+
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
6063
]
6164
),
6265
.testTarget(
6366
name: "MapLibreSwiftDSLTests",
6467
dependencies: [
65-
"MapLibreSwiftDSL"
68+
"MapLibreSwiftDSL",
6669
]
6770
),
6871
]

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ Then, for each target add either the DSL (for just the DSL) or both (for the Swi
4646
Check out the (super basic) [previews at the bottom of MapView.swift](Sources/MapLibreSwiftUI/MapView.swift)
4747
or more detailed [Examples](Sources/MapLibreSwiftUI/Examples) to see how it works in practice.
4848

49+
## Developer Quick Start
50+
51+
This project uses [`swiftformat`](https://github.com/nicklockwood/SwiftFormat) to automatically handle basic swift formatting
52+
as well as to lint and ensure conformance in PRs. Check out the swiftformat [Install Guide](https://github.com/nicklockwood/SwiftFormat?tab=readme-ov-file#how-do-i-install-it)
53+
to add swiftformat to your machine.
54+
55+
Once installed, you can autoformat code using the command:
56+
57+
```sh
58+
swiftformat .
59+
```
60+
61+
Swiftformat can occasionally poorly resolve a formatting issue (e.g. when you've already line-broken a large comment). Issues like this are typically easy to manually correct.
62+
4963
## Structure
5064

5165
This package is structured into a few targets. `InternalUtils` is pretty much what it says. `MapLibreSwiftDSL` and
@@ -85,4 +99,4 @@ things like fleshing out the expresison API helpers (which will be highly repeti
8599
check out the issue tracker, as these sholud be noted there.
86100

87101
TODO: Look at PointFree's Snapshot testing that generates images of SwiftUI views. Also look at inline snapshotting.
88-
https://github.com/pointfreeco/swift-snapshot-testing
102+
https://github.com/pointfreeco/swift-snapshot-testing

Sources/InternalUtils/Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public func addSourceIfNecessary(_ source: MLNSource, to mlnStyle: MLNStyle) ->
2525
}
2626
}
2727

28-
extension UIImage{
28+
public extension UIImage {
2929
/// Computes a SHA256 hash of the image data.
3030
///
3131
/// This is used internally to generate identifiers for images that can be used in the MapLibre GL
3232
/// style which uniquely identify `UIImage`s to the renderer.
33-
public func sha256() -> String{
33+
func sha256() -> String {
3434
if let imageData = cgImage?.dataProvider?.data as? Data {
3535
return imageData.digest.hexString
3636
}

Sources/MapLibreSwiftDSL/Enums.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import MapLibre
21
import InternalUtils
2+
import MapLibre
33

44
// This file exists for convenience until / unless
55
// this is merged into the MapLibre Native Swift module OR Swift gains the
@@ -11,13 +11,12 @@ public enum LineCap {
1111
case square
1212
}
1313

14-
1514
extension LineCap: MLNRawRepresentable {
1615
public var mlnRawValue: MLNLineCap {
1716
switch self {
18-
case .butt: return .butt
19-
case .round: return .round
20-
case .square: return .square
17+
case .butt: .butt
18+
case .round: .round
19+
case .square: .square
2120
}
2221
}
2322
}
@@ -31,9 +30,9 @@ public enum LineJoin {
3130
extension LineJoin: MLNRawRepresentable {
3231
public var mlnRawValue: MLNLineJoin {
3332
switch self {
34-
case .bevel: return .bevel
35-
case .miter: return .miter
36-
case .round: return .round
33+
case .bevel: .bevel
34+
case .miter: .miter
35+
case .round: .round
3736
}
3837
}
3938
}
@@ -52,19 +51,19 @@ extension MLNVariableExpression {
5251
var nsExpression: NSExpression {
5352
switch self {
5453
case .featureAccumulated:
55-
return .featureAccumulatedVariable
54+
.featureAccumulatedVariable
5655
case .featureAttributes:
57-
return .featureAttributesVariable
56+
.featureAttributesVariable
5857
case .featureIdentifier:
59-
return .featureIdentifierVariable
58+
.featureIdentifierVariable
6059
case .geometryType:
61-
return .geometryTypeVariable
60+
.geometryTypeVariable
6261
case .heatmapDensity:
63-
return .heatmapDensityVariable
62+
.heatmapDensityVariable
6463
case .lineProgress:
65-
return .lineProgressVariable
64+
.lineProgressVariable
6665
case .zoomLevel:
67-
return .zoomLevelVariable
66+
.zoomLevelVariable
6867
}
6968
}
7069
}

Sources/MapLibreSwiftDSL/Expressions.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
import Foundation
33
import MapLibre
44

5-
65
// TODO: Parameters and stops need nicer interfaces
76
// TODO: Expression should be able to accept other expressions like variable getters. Probably should be a protocol?
8-
public func interpolatingExpression(expression: MLNVariableExpression, curveType: MLNExpressionInterpolationMode, parameters: NSExpression?, stops: NSExpression) -> NSExpression {
9-
return NSExpression(forMLNInterpolating: expression.nsExpression,
10-
curveType: curveType,
11-
parameters: parameters,
12-
stops: stops)
7+
public func interpolatingExpression(
8+
expression: MLNVariableExpression,
9+
curveType: MLNExpressionInterpolationMode,
10+
parameters: NSExpression?,
11+
stops: NSExpression
12+
) -> NSExpression {
13+
NSExpression(forMLNInterpolating: expression.nsExpression,
14+
curveType: curveType,
15+
parameters: parameters,
16+
stops: stops)
1317
}

0 commit comments

Comments
 (0)