Skip to content

Commit 364005b

Browse files
authored
Merge pull request #19 from Rallista/feat/gestures-and-better-camera
Revisions for camera behavior, added basic gesture methods, separated…
2 parents b6233a0 + ad561ea commit 364005b

Some content is hidden

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

43 files changed

+1602
-385
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: macos-13
11+
runs-on: macos-14
1212
strategy:
1313
matrix:
1414
scheme: [
1515
MapLibreSwiftUI-Package
1616
]
1717
destination: [
1818
# TODO: Add more destinations
19-
'platform=iOS Simulator,name=iPhone 15,OS=17.0.1'
19+
'platform=iOS Simulator,name=iPhone 15,OS=17.2'
2020
]
2121

2222
steps:

.swiftpm/xcode/xcshareddata/xcschemes/MapLibreSwiftUI-Package.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
ReferencedContainer = "container:">
7878
</BuildableReference>
7979
</TestableReference>
80+
<TestableReference
81+
skipped = "NO">
82+
<BuildableReference
83+
BuildableIdentifier = "primary"
84+
BlueprintIdentifier = "MapLibreSwiftUITests"
85+
BuildableName = "MapLibreSwiftUITests"
86+
BlueprintName = "MapLibreSwiftUITests"
87+
ReferencedContainer = "container:">
88+
</BuildableReference>
89+
</TestableReference>
8090
</Testables>
8191
</TestAction>
8292
<LaunchAction

Package.resolved

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "https://github.com/maplibre/maplibre-gl-native-distribution.git",
77
"state" : {
8-
"revision" : "3b88d990bc39ed5347852a536c0efd942a07fc97",
9-
"version" : "6.0.0-pre9599200f2529de44ba62d4662cddb445dc19397d"
8+
"revision" : "3df876f8f2c6c591b0f66a29b3e216020afc885c",
9+
"version" : "6.0.0"
1010
}
1111
},
1212
{
@@ -18,6 +18,24 @@
1818
"revision" : "b8deecb8adc3b911de311ead5a13b98fbf2d7824"
1919
}
2020
},
21+
{
22+
"identity" : "mockable",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/Kolos65/Mockable.git",
25+
"state" : {
26+
"revision" : "7af00c08880d375f2742ca55705abd69837fe6c3",
27+
"version" : "0.0.2"
28+
}
29+
},
30+
{
31+
"identity" : "swift-snapshot-testing",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
34+
"state" : {
35+
"revision" : "e7b77228b34057041374ebef00c0fd7739d71a2b",
36+
"version" : "1.15.3"
37+
}
38+
},
2139
{
2240
"identity" : "swift-syntax",
2341
"kind" : "remoteSourceControl",

Package.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ let package = Package(
1919
targets: ["MapLibreSwiftDSL"]),
2020
],
2121
dependencies: [
22-
// .package(url: "https://github.com/maplibre/maplibre-gl-native-distribution", .upToNextMajor(from: "5.13.0")),
23-
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.0.0-pre9599200f2529de44ba62d4662cddb445dc19397d"),
24-
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", branch: "main")
22+
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.0.0"),
23+
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", branch: "main"),
24+
// Testing
25+
.package(url: "https://github.com/Kolos65/Mockable.git", from: "0.0.2"),
26+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.3"),
2527
],
2628
targets: [
2729
.target(
@@ -30,6 +32,10 @@ let package = Package(
3032
.target(name: "InternalUtils"),
3133
.target(name: "MapLibreSwiftDSL"),
3234
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
35+
.product(name: "Mockable", package: "Mockable")
36+
],
37+
swiftSettings: [
38+
.define("MOCKING", .when(configuration: .debug))
3339
]),
3440
.target(
3541
name: "MapLibreSwiftDSL",
@@ -45,6 +51,14 @@ let package = Package(
4551

4652
// MARK: Tests
4753

54+
.testTarget(
55+
name: "MapLibreSwiftUITests",
56+
dependencies: [
57+
"MapLibreSwiftUI",
58+
.product(name: "MockableTest", package: "Mockable"),
59+
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
60+
]
61+
),
4862
.testTarget(
4963
name: "MapLibreSwiftDSLTests",
5064
dependencies: [
Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
import Foundation
22

33
@resultBuilder
4-
public enum MapViewContentBuilder {
5-
6-
public static func buildBlock(_ layers: [StyleLayerDefinition]...) -> [StyleLayerDefinition] {
7-
return layers.flatMap { $0 }
8-
}
9-
10-
public static func buildOptional(_ layers: [StyleLayerDefinition]?) -> [StyleLayerDefinition] {
11-
return layers ?? []
4+
public enum MapViewContentBuilder: DefaultResultBuilder {
5+
public static func buildExpression(_ expression: StyleLayerDefinition) -> [StyleLayerDefinition] {
6+
return [expression]
127
}
138

14-
public static func buildExpression(_ layer: StyleLayerDefinition) -> [StyleLayerDefinition] {
15-
return [layer]
9+
public static func buildExpression(_ expression: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
10+
return expression
1611
}
1712

1813
public static func buildExpression(_ expression: Void) -> [StyleLayerDefinition] {
1914
return []
2015
}
2116

22-
public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] {
23-
return styleCollection.layers
17+
public static func buildBlock(_ components: [StyleLayerDefinition]...) -> [StyleLayerDefinition] {
18+
return components.flatMap { $0 }
19+
}
20+
21+
public static func buildArray(_ components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
22+
return components
2423
}
2524

25+
public static func buildArray(_ components: [[StyleLayerDefinition]]) -> [StyleLayerDefinition] {
26+
return components.flatMap { $0 }
27+
}
2628

27-
public static func buildEither(first layer: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
28-
return layer
29+
public static func buildEither(first components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
30+
return components
2931
}
3032

31-
public static func buildEither(second layer: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
32-
return layer
33+
public static func buildEither(second components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
34+
return components
35+
}
36+
37+
public static func buildOptional(_ components: [StyleLayerDefinition]?) -> [StyleLayerDefinition] {
38+
return components ?? []
39+
}
40+
41+
// MARK: Custom Handler for StyleLayerCollection type.
42+
43+
public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] {
44+
return styleCollection.layers
3345
}
3446
}

Sources/MapLibreSwiftDSL/Data Sources.swift renamed to Sources/MapLibreSwiftDSL/ShapeDataBuilder.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public struct ShapeSource: Source {
4545

4646

4747
@resultBuilder
48-
public enum ShapeDataBuilder {
49-
// Handle a single MLNShape element
48+
public enum ShapeDataBuilder: DefaultResultBuilder {
5049
public static func buildExpression(_ expression: MLNShape) -> [MLNShape] {
5150
return [expression]
5251
}
@@ -55,21 +54,34 @@ public enum ShapeDataBuilder {
5554
return expression
5655
}
5756

58-
// Combine elements into an array
57+
public static func buildExpression(_ expression: Void) -> [MLNShape] {
58+
return []
59+
}
60+
5961
public static func buildBlock(_ components: [MLNShape]...) -> [MLNShape] {
6062
return components.flatMap { $0 }
6163
}
6264

63-
// Handle an array of MLNShape (if you want to directly pass arrays)
6465
public static func buildArray(_ components: [MLNShape]) -> [MLNShape] {
6566
return components
6667
}
6768

68-
// Handle for in of MLNShape
6969
public static func buildArray(_ components: [[MLNShape]]) -> [MLNShape] {
7070
return components.flatMap { $0 }
7171
}
7272

73+
public static func buildEither(first components: [MLNShape]) -> [MLNShape] {
74+
return components
75+
}
76+
77+
public static func buildEither(second components: [MLNShape]) -> [MLNShape] {
78+
return components
79+
}
80+
81+
public static func buildOptional(_ components: [MLNShape]?) -> [MLNShape] {
82+
return components ?? []
83+
}
84+
7385
// Convert the collected MLNShape array to ShapeData
7486
public static func buildFinalResult(_ components: [MLNShape]) -> ShapeData {
7587
let features = components.compactMap { $0 as? MLNShape & MLNFeature }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Foundation
2+
3+
/// Enforces a basic set of result builder definiitons.
4+
///
5+
/// This is just a tool to make a result builder easier to build, maintain sorting, etc.
6+
protocol DefaultResultBuilder {
7+
8+
associatedtype Component
9+
10+
static func buildExpression(_ expression: Component) -> [Component]
11+
12+
static func buildExpression(_ expression: [Component]) -> [Component]
13+
14+
// MARK: Handle void
15+
16+
static func buildExpression(_ expression: Void) -> [Component]
17+
18+
// MARK: Combine elements into an array
19+
20+
static func buildBlock(_ components: [Component]...) -> [Component]
21+
22+
// MARK: Handle Arrays
23+
24+
static func buildArray(_ components: [Component]) -> [Component]
25+
26+
// MARK: Handle for in loops
27+
28+
static func buildArray(_ components: [[Component]]) -> [Component]
29+
30+
// MARK: Handle if statements
31+
32+
static func buildEither(first components: [Component]) -> [Component]
33+
34+
static func buildEither(second components: [Component]) -> [Component]
35+
36+
// MARK: Handle Optionals
37+
38+
static func buildOptional(_ components: [Component]?) -> [Component]
39+
}

Sources/MapLibreSwiftUI/Examples/Camera.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ struct CameraDirectManipulationPreview: View {
77
@State private var camera = MapViewCamera.center(switzerland, zoom: 4)
88

99
let styleURL: URL
10+
var onStyleLoaded: (() -> Void)? = nil
1011

1112
var body: some View {
1213
MapView(styleURL: styleURL, camera: $camera)
14+
.onStyleLoaded { _ in
15+
print("Style is loaded")
16+
onStyleLoaded?()
17+
}
1318
.overlay(alignment: .bottom, content: {
14-
Text("\(camera.coordinate.latitude), \(camera.coordinate.longitude) z \(camera.zoom)")
19+
Text("\(String(describing: camera.state)) z \(camera.zoom)")
1520
.padding()
1621
.foregroundColor(.white)
1722
.background(
@@ -22,19 +27,16 @@ struct CameraDirectManipulationPreview: View {
2227
.padding(.bottom, 42)
2328
})
2429
.task {
25-
try! await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)
30+
try? await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)
2631

2732
camera = MapViewCamera.center(switzerland, zoom: 6)
2833
}
2934
}
3035
}
3136

32-
struct Camera_Previews: PreviewProvider {
33-
static var previews: some View {
34-
let demoTilesURL = URL(string: "https://demotiles.maplibre.org/style.json")!
35-
36-
CameraDirectManipulationPreview(styleURL: demoTilesURL)
37-
.ignoresSafeArea(.all)
38-
.previewDisplayName("Camera Binding")
39-
}
37+
#Preview("Camera Preview") {
38+
CameraDirectManipulationPreview(
39+
styleURL: URL(string: "https://demotiles.maplibre.org/style.json")!
40+
)
41+
.ignoresSafeArea(.all)
4042
}

0 commit comments

Comments
 (0)