Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-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
  • Loading branch information
Patrick-Kladek committed Mar 12, 2024
2 parents 9c78e13 + 6b59504 commit 004ce94
Show file tree
Hide file tree
Showing 53 changed files with 642 additions and 565 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Maplibre-SwiftUI
name: Release

on:
push:
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test maplibre-swiftui-dsl-playground
name: Test

on:
push:
Expand All @@ -7,6 +7,19 @@ on:
branches: [ main ]

jobs:
format-lint:
runs-on: macos-14

steps:
- name: Install tools
run: brew install swiftformat

- name: Checkout maplibre-swiftui-dsl-playground
uses: actions/checkout@v3

- name: Check format
run: swiftformat . --lint

test:
runs-on: macos-14
strategy:
Expand All @@ -20,15 +33,15 @@ jobs:
]

steps:
- name: Install xcbeautify
- name: Install tools
run: brew install xcbeautify

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.0'

- name: Checkout maplibre-swiftui-dsl-playground
uses: actions/checkout@v3

- name: Test ${{ matrix.scheme }} on ${{ matrix.destination }}
run: xcodebuild -scheme ${{ matrix.scheme }} test -skipMacroValidation -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]}
5 changes: 5 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
builder:
configs:
- documentation_targets: [MapLibreSwiftUI]
platform: ios
15 changes: 15 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# file options

--exclude .build

# format options

--header ""
--indent 4
--importgrouping testable-bottom
--maxwidth 120
--swiftversion 5.9

# rules

--enable isEmpty
22 changes: 11 additions & 11 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/maplibre/maplibre-gl-native-distribution.git",
"state" : {
"revision" : "818e1d6b83e4cbe8482eca3e6e57d3f560926157",
"version" : "6.1.1"
"revision" : "92505cfbad5c5ed6a93e0f3cd70872aaa98a12ac",
"version" : "6.2.0"
}
},
{
"identity" : "maplibre-swift-macros",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stadiamaps/maplibre-swift-macros.git",
"state" : {
"branch" : "main",
"revision" : "b8deecb8adc3b911de311ead5a13b98fbf2d7824"
"revision" : "9f15cbb11d2b5248ead47aecae5be8a1d4d5f463",
"version" : "0.0.2"
}
},
{
"identity" : "mockable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Kolos65/Mockable.git",
"state" : {
"revision" : "7af00c08880d375f2742ca55705abd69837fe6c3",
"version" : "0.0.2"
"revision" : "3b79620f2b916941035b5544bbca321fa7b33ed4",
"version" : "0.0.3"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "e7b77228b34057041374ebef00c0fd7739d71a2b",
"version" : "1.15.3"
"revision" : "5b0c434778f2c1a4c9b5ebdb8682b28e84dd69bd",
"version" : "1.15.4"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
}
],
Expand Down
27 changes: 15 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "MapLibreSwiftUI",
Expand All @@ -13,14 +13,16 @@ let package = Package(
products: [
.library(
name: "MapLibreSwiftUI",
targets: ["MapLibreSwiftUI"]),
targets: ["MapLibreSwiftUI"]
),
.library(
name: "MapLibreSwiftDSL",
targets: ["MapLibreSwiftDSL"]),
targets: ["MapLibreSwiftDSL"]
),
],
dependencies: [
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.1.0"),
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", branch: "main"),
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", from: "0.0.2"),
// 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"),
Expand All @@ -32,37 +34,38 @@ let package = Package(
.target(name: "InternalUtils"),
.target(name: "MapLibreSwiftDSL"),
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
.product(name: "Mockable", package: "Mockable")
.product(name: "Mockable", package: "Mockable"),
],
swiftSettings: [
.define("MOCKING", .when(configuration: .debug))
]),
.define("MOCKING", .when(configuration: .debug)),
]
),
.target(
name: "MapLibreSwiftDSL",
dependencies: [
.target(name: "InternalUtils"),
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros")
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros"),
]
),
.target(
name: "InternalUtils"
),

// MARK: Tests

.testTarget(
name: "MapLibreSwiftUITests",
dependencies: [
"MapLibreSwiftUI",
.product(name: "MockableTest", package: "Mockable"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
.testTarget(
name: "MapLibreSwiftDSLTests",
dependencies: [
"MapLibreSwiftDSL"
"MapLibreSwiftDSL",
]
),
]
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ Then, for each target add either the DSL (for just the DSL) or both (for the Swi
Check out the (super basic) [previews at the bottom of MapView.swift](Sources/MapLibreSwiftUI/MapView.swift)
or more detailed [Examples](Sources/MapLibreSwiftUI/Examples) to see how it works in practice.

## Developer Quick Start

This project uses [`swiftformat`](https://github.com/nicklockwood/SwiftFormat) to automatically handle basic swift formatting
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)
to add swiftformat to your machine.

Once installed, you can autoformat code using the command:

```sh
swiftformat .
```

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.

## Structure

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

TODO: Look at PointFree's Snapshot testing that generates images of SwiftUI views. Also look at inline snapshotting.
https://github.com/pointfreeco/swift-snapshot-testing
https://github.com/pointfreeco/swift-snapshot-testing
4 changes: 2 additions & 2 deletions Sources/InternalUtils/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public func addSourceIfNecessary(_ source: MLNSource, to mlnStyle: MLNStyle) ->
}
}

extension UIImage{
public extension UIImage {
/// Computes a SHA256 hash of the image data.
///
/// This is used internally to generate identifiers for images that can be used in the MapLibre GL
/// style which uniquely identify `UIImage`s to the renderer.
public func sha256() -> String{
func sha256() -> String {
if let imageData = cgImage?.dataProvider?.data as? Data {
return imageData.digest.hexString
}
Expand Down
29 changes: 14 additions & 15 deletions Sources/MapLibreSwiftDSL/Enums.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MapLibre
import InternalUtils
import MapLibre

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


extension LineCap: MLNRawRepresentable {
public var mlnRawValue: MLNLineCap {
switch self {
case .butt: return .butt
case .round: return .round
case .square: return .square
case .butt: .butt
case .round: .round
case .square: .square
}
}
}
Expand All @@ -31,9 +30,9 @@ public enum LineJoin {
extension LineJoin: MLNRawRepresentable {
public var mlnRawValue: MLNLineJoin {
switch self {
case .bevel: return .bevel
case .miter: return .miter
case .round: return .round
case .bevel: .bevel
case .miter: .miter
case .round: .round
}
}
}
Expand All @@ -52,19 +51,19 @@ extension MLNVariableExpression {
var nsExpression: NSExpression {
switch self {
case .featureAccumulated:
return .featureAccumulatedVariable
.featureAccumulatedVariable
case .featureAttributes:
return .featureAttributesVariable
.featureAttributesVariable
case .featureIdentifier:
return .featureIdentifierVariable
.featureIdentifierVariable
case .geometryType:
return .geometryTypeVariable
.geometryTypeVariable
case .heatmapDensity:
return .heatmapDensityVariable
.heatmapDensityVariable
case .lineProgress:
return .lineProgressVariable
.lineProgressVariable
case .zoomLevel:
return .zoomLevelVariable
.zoomLevelVariable
}
}
}
16 changes: 10 additions & 6 deletions Sources/MapLibreSwiftDSL/Expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import Foundation
import MapLibre


// TODO: Parameters and stops need nicer interfaces
// TODO: Expression should be able to accept other expressions like variable getters. Probably should be a protocol?
public func interpolatingExpression(expression: MLNVariableExpression, curveType: MLNExpressionInterpolationMode, parameters: NSExpression?, stops: NSExpression) -> NSExpression {
return NSExpression(forMLNInterpolating: expression.nsExpression,
curveType: curveType,
parameters: parameters,
stops: stops)
public func interpolatingExpression(
expression: MLNVariableExpression,
curveType: MLNExpressionInterpolationMode,
parameters: NSExpression?,
stops: NSExpression
) -> NSExpression {
NSExpression(forMLNInterpolating: expression.nsExpression,
curveType: curveType,
parameters: parameters,
stops: stops)
}
10 changes: 5 additions & 5 deletions Sources/MapLibreSwiftDSL/MapLibre Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Various quality-of-life extensions to MapLibre APIs.

// Various quality-of-life extensions to MapLibre APIs.
import MapLibre

// TODO: Upstream this?
extension MLNPolyline {
public extension MLNPolyline {
/// Constructs a polyline (aka LineString) from a list of coordinates.
public convenience init(coordinates: [CLLocationCoordinate2D]) {
convenience init(coordinates: [CLLocationCoordinate2D]) {
self.init(coordinates: coordinates, count: UInt(coordinates.count))
}
}

extension MLNPointFeature {
public convenience init(coordinate: CLLocationCoordinate2D, configure: ((MLNPointFeature) -> Void)? = nil) {
public extension MLNPointFeature {
convenience init(coordinate: CLLocationCoordinate2D, configure: ((MLNPointFeature) -> Void)? = nil) {
self.init()
self.coordinate = coordinate

Expand Down
Loading

0 comments on commit 004ce94

Please sign in to comment.