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

Revisions for camera behavior, added basic gesture methods, separated… #19

Merged
merged 15 commits into from
Feb 8, 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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:

jobs:
test:
runs-on: macos-13
runs-on: macos-14
strategy:
matrix:
scheme: [
MapLibreSwiftUI-Package
]
destination: [
# TODO: Add more destinations
'platform=iOS Simulator,name=iPhone 15,OS=17.0.1'
'platform=iOS Simulator,name=iPhone 15,OS=17.2'
]

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MapLibreSwiftUITests"
BuildableName = "MapLibreSwiftUITests"
BlueprintName = "MapLibreSwiftUITests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
22 changes: 20 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/maplibre/maplibre-gl-native-distribution.git",
"state" : {
"revision" : "3b88d990bc39ed5347852a536c0efd942a07fc97",
"version" : "6.0.0-pre9599200f2529de44ba62d4662cddb445dc19397d"
"revision" : "3df876f8f2c6c591b0f66a29b3e216020afc885c",
"version" : "6.0.0"
}
},
{
Expand All @@ -18,6 +18,24 @@
"revision" : "b8deecb8adc3b911de311ead5a13b98fbf2d7824"
}
},
{
"identity" : "mockable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Kolos65/Mockable.git",
"state" : {
"revision" : "7af00c08880d375f2742ca55705abd69837fe6c3",
"version" : "0.0.2"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "e7b77228b34057041374ebef00c0fd7739d71a2b",
"version" : "1.15.3"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
Expand Down
20 changes: 17 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ let package = Package(
targets: ["MapLibreSwiftDSL"]),
],
dependencies: [
// .package(url: "https://github.com/maplibre/maplibre-gl-native-distribution", .upToNextMajor(from: "5.13.0")),
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.0.0-pre9599200f2529de44ba62d4662cddb445dc19397d"),
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", branch: "main")
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.0.0"),
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", branch: "main"),
// Testing
.package(url: "https://github.com/Kolos65/Mockable.git", from: "0.0.2"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.3"),
],
targets: [
.target(
Expand All @@ -30,6 +32,10 @@ let package = Package(
.target(name: "InternalUtils"),
.target(name: "MapLibreSwiftDSL"),
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
.product(name: "Mockable", package: "Mockable")
],
swiftSettings: [
.define("MOCKING", .when(configuration: .debug))
]),
.target(
name: "MapLibreSwiftDSL",
Expand All @@ -45,6 +51,14 @@ let package = Package(

// MARK: Tests

.testTarget(
name: "MapLibreSwiftUITests",
dependencies: [
"MapLibreSwiftUI",
.product(name: "MockableTest", package: "Mockable"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
]
),
.testTarget(
name: "MapLibreSwiftDSLTests",
dependencies: [
Expand Down
44 changes: 28 additions & 16 deletions Sources/MapLibreSwiftDSL/MapViewContentBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
import Foundation

@resultBuilder
public enum MapViewContentBuilder {

public static func buildBlock(_ layers: [StyleLayerDefinition]...) -> [StyleLayerDefinition] {
return layers.flatMap { $0 }
}

public static func buildOptional(_ layers: [StyleLayerDefinition]?) -> [StyleLayerDefinition] {
return layers ?? []
public enum MapViewContentBuilder: DefaultResultBuilder {
public static func buildExpression(_ expression: StyleLayerDefinition) -> [StyleLayerDefinition] {
return [expression]
}

public static func buildExpression(_ layer: StyleLayerDefinition) -> [StyleLayerDefinition] {
return [layer]
public static func buildExpression(_ expression: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return expression
}

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

public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] {
return styleCollection.layers
public static func buildBlock(_ components: [StyleLayerDefinition]...) -> [StyleLayerDefinition] {
return components.flatMap { $0 }
}

public static func buildArray(_ components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return components
}

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

public static func buildEither(first layer: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return layer
public static func buildEither(first components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return components
}

public static func buildEither(second layer: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return layer
public static func buildEither(second components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return components
}

public static func buildOptional(_ components: [StyleLayerDefinition]?) -> [StyleLayerDefinition] {
return components ?? []
}

// MARK: Custom Handler for StyleLayerCollection type.

public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] {
return styleCollection.layers
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public struct ShapeSource: Source {


@resultBuilder
public enum ShapeDataBuilder {
// Handle a single MLNShape element
public enum ShapeDataBuilder: DefaultResultBuilder {
public static func buildExpression(_ expression: MLNShape) -> [MLNShape] {
return [expression]
}
Expand All @@ -55,21 +54,34 @@ public enum ShapeDataBuilder {
return expression
}

// Combine elements into an array
public static func buildExpression(_ expression: Void) -> [MLNShape] {
return []
}

public static func buildBlock(_ components: [MLNShape]...) -> [MLNShape] {
return components.flatMap { $0 }
}

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

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

public static func buildEither(first components: [MLNShape]) -> [MLNShape] {
return components
}

public static func buildEither(second components: [MLNShape]) -> [MLNShape] {
return components
}

public static func buildOptional(_ components: [MLNShape]?) -> [MLNShape] {
return components ?? []
}

// Convert the collected MLNShape array to ShapeData
public static func buildFinalResult(_ components: [MLNShape]) -> ShapeData {
let features = components.compactMap { $0 as? MLNShape & MLNFeature }
Expand Down
39 changes: 39 additions & 0 deletions Sources/MapLibreSwiftDSL/Support/DefaultResultBuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation

/// Enforces a basic set of result builder definiitons.
///
/// This is just a tool to make a result builder easier to build, maintain sorting, etc.
protocol DefaultResultBuilder {

associatedtype Component

static func buildExpression(_ expression: Component) -> [Component]

static func buildExpression(_ expression: [Component]) -> [Component]

// MARK: Handle void

static func buildExpression(_ expression: Void) -> [Component]

// MARK: Combine elements into an array

static func buildBlock(_ components: [Component]...) -> [Component]

// MARK: Handle Arrays

static func buildArray(_ components: [Component]) -> [Component]

// MARK: Handle for in loops

static func buildArray(_ components: [[Component]]) -> [Component]

// MARK: Handle if statements

static func buildEither(first components: [Component]) -> [Component]

static func buildEither(second components: [Component]) -> [Component]

// MARK: Handle Optionals

static func buildOptional(_ components: [Component]?) -> [Component]
}
22 changes: 12 additions & 10 deletions Sources/MapLibreSwiftUI/Examples/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ struct CameraDirectManipulationPreview: View {
@State private var camera = MapViewCamera.center(switzerland, zoom: 4)

let styleURL: URL
var onStyleLoaded: (() -> Void)? = nil

var body: some View {
MapView(styleURL: styleURL, camera: $camera)
.onStyleLoaded { _ in
print("Style is loaded")
onStyleLoaded?()
}
.overlay(alignment: .bottom, content: {
Text("\(camera.coordinate.latitude), \(camera.coordinate.longitude) z \(camera.zoom)")
Text("\(String(describing: camera.state)) z \(camera.zoom)")
.padding()
.foregroundColor(.white)
.background(
Expand All @@ -22,19 +27,16 @@ struct CameraDirectManipulationPreview: View {
.padding(.bottom, 42)
})
.task {
try! await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)
try? await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)

camera = MapViewCamera.center(switzerland, zoom: 6)
}
}
}

struct Camera_Previews: PreviewProvider {
static var previews: some View {
let demoTilesURL = URL(string: "https://demotiles.maplibre.org/style.json")!

CameraDirectManipulationPreview(styleURL: demoTilesURL)
.ignoresSafeArea(.all)
.previewDisplayName("Camera Binding")
}
#Preview("Camera Preview") {
CameraDirectManipulationPreview(
styleURL: URL(string: "https://demotiles.maplibre.org/style.json")!
)
.ignoresSafeArea(.all)
}
Loading
Loading