Skip to content

Commit 3b268f9

Browse files
authored
chore: update gen swift headers script (#392)
- split `Helpers` class in its own file - regenerate headers - add `SafeArea` to events example page
1 parent 6cb793d commit 3b268f9

File tree

9 files changed

+107
-82
lines changed

9 files changed

+107
-82
lines changed

example/lib/events_page.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ class _EventsPageState extends State<EventsPage> {
2626
),
2727
onEvent: _onEvent,
2828
),
29-
IgnorePointer(
30-
child: Container(
31-
padding: const EdgeInsets.all(8),
32-
alignment: Alignment.bottomLeft,
33-
child: Text(
34-
_events.map(eventToString).join('\n'),
35-
style: const TextStyle(color: Colors.black),
29+
SafeArea(
30+
child: IgnorePointer(
31+
child: Container(
32+
padding: const EdgeInsets.all(8),
33+
alignment: Alignment.bottomLeft,
34+
child: Text(
35+
_events.map(eventToString).join('\n'),
36+
style: const TextStyle(color: Colors.black),
37+
),
3638
),
3739
),
3840
),

maplibre_ios/ios/maplibre_ios/Sources/maplibre_ios/Extensions.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import Foundation
12
import MapLibre
3+
import UIKit
4+
5+
// Update the header file for this class like this:
6+
// cd maplibre_ios/ios/maplibre_ios/Sources/maplibre_ios/
7+
// ./gen_swift_headers.sh
28

39
public extension UIColor {
410
convenience init?(hexString: String) {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import Foundation
2+
import MapLibre
3+
import UIKit
4+
5+
// Update the header file for this class like this:
6+
// cd maplibre_ios/ios/maplibre_ios/Sources/maplibre_ios/
7+
// ./gen_swift_headers.sh
8+
9+
@objc public class Helpers: NSObject {
10+
@objc public static func addImageToStyle(
11+
target: NSObject, field: String, expression: NSExpression
12+
) {
13+
do {
14+
target.setValue(expression, forKey: field)
15+
} catch {
16+
print("Couldn't set expression in Helpers.addImageToStyle()")
17+
}
18+
}
19+
20+
@objc public static func setExpression(
21+
target: NSObject, field: String, expression: NSExpression
22+
) {
23+
do {
24+
// https://developer.apple.com/documentation/objectivec/nsobject/1418139-setvalue
25+
try target.setValue(expression, forKey: field)
26+
} catch {
27+
print("Couldn't set expression in Helpers.setExpression()")
28+
}
29+
}
30+
31+
@objc public static func parseExpression(
32+
propertyName: String, expression: String
33+
) -> NSExpression? {
34+
print("\(propertyName): \(expression)")
35+
do {
36+
// can't create an Expression using the default method if the data is a hex string
37+
if propertyName.contains("color"), expression.first == "#" {
38+
let color = UIColor(hexString: expression)
39+
return NSExpression(forConstantValue: color)
40+
}
41+
if expression.starts(with: "[") {
42+
// can't create an Expression if the data of a literal is an array
43+
let json = try JSONSerialization.jsonObject(
44+
with: expression.data(using: .utf8)!,
45+
options: .fragmentsAllowed
46+
)
47+
// print("json: \(json)")
48+
if let offset = json as? [Any] {
49+
if offset.count == 2, offset.first is String,
50+
offset.first as? String == "literal"
51+
{
52+
if let vector = offset.last as? [Any] {
53+
if vector.count == 2 {
54+
if let x = vector.first as? Double,
55+
let y = vector.last as? Double
56+
{
57+
return NSExpression(
58+
forConstantValue: NSValue(
59+
cgVector: CGVector(dx: x, dy: y)))
60+
}
61+
}
62+
}
63+
}
64+
}
65+
return NSExpression(mglJSONObject: json)
66+
}
67+
// parse as a constant value
68+
return NSExpression(forConstantValue: expression)
69+
70+
} catch {
71+
print("Couldn't parse Expression: " + expression)
72+
}
73+
return nil
74+
}
75+
}

maplibre_ios/ios/maplibre_ios/Sources/maplibre_ios/MapLibreRegistry.swift

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import UIKit
44

55
// Update the header file for this class like this:
66
// cd maplibre_ios/ios/maplibre_ios/Sources/maplibre_ios/
7-
// swiftc -c MapLibreRegistry.swift -module-name maplibre_ios -emit-objc-header-path MapLibreRegistry.h -emit-library -o libmaplibreios.dylib -target arm64-apple-ios18.1-simulator -sdk $(xcrun --sdk iphonesimulator --show-sdk-path) -F /Users/joscha/Library/Caches/CocoaPods/Pods/Release/MapLibre/6.8.1-46c5f/MapLibre.xcframework/ios-arm64_x86_64-simulator
7+
// ./gen_swift_headers.sh
88

99
@objc public class MapLibreRegistry: NSObject {
1010
private static var mapRegistry: [Int64: AnyObject] = [:]
@@ -30,71 +30,3 @@ import UIKit
3030
// Warning: Storing Context in a static field may lead to memory leaks.
3131
@objc public static var context: AnyObject?
3232
}
33-
34-
@objc public class Helpers: NSObject {
35-
@objc public static func addImageToStyle(
36-
target: NSObject, field: String, expression: NSExpression
37-
) {
38-
do {
39-
target.setValue(expression, forKey: field)
40-
} catch {
41-
print("Couldn't set expression in Helpers.setExpression()")
42-
}
43-
}
44-
45-
@objc public static func setExpression(
46-
target: NSObject, field: String, expression: NSExpression
47-
) {
48-
do {
49-
// https://developer.apple.com/documentation/objectivec/nsobject/1418139-setvalue
50-
try target.setValue(expression, forKey: field)
51-
} catch {
52-
print("Couldn't set expression in Helpers.setExpression()")
53-
}
54-
}
55-
56-
@objc public static func parseExpression(
57-
propertyName: String, expression: String
58-
) -> NSExpression? {
59-
print("\(propertyName): \(expression)")
60-
do {
61-
// can't create an Expression using the default method if the data is a hex string
62-
if propertyName.contains("color"), expression.first == "#" {
63-
var color = UIColor(hexString: expression)
64-
return NSExpression(forConstantValue: color)
65-
}
66-
if expression.starts(with: "[") {
67-
// can't create an Expression if the data of a literal is an array
68-
let json = try JSONSerialization.jsonObject(
69-
with: expression.data(using: .utf8)!,
70-
options: .fragmentsAllowed
71-
)
72-
// print("json: \(json)")
73-
if let offset = json as? [Any] {
74-
if offset.count == 2, offset.first is String,
75-
offset.first as? String == "literal"
76-
{
77-
if let vector = offset.last as? [Any] {
78-
if vector.count == 2 {
79-
if let x = vector.first as? Double,
80-
let y = vector.last as? Double
81-
{
82-
return NSExpression(
83-
forConstantValue: NSValue(
84-
cgVector: CGVector(dx: x, dy: y)))
85-
}
86-
}
87-
}
88-
}
89-
}
90-
return NSExpression(mglJSONObject: json)
91-
}
92-
// parse as a constant value
93-
return NSExpression(forConstantValue: expression)
94-
95-
} catch {
96-
print("Couldn't parse Expression: " + expression)
97-
}
98-
return nil
99-
}
100-
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
#!/usr/bin/env bash
22

3+
# Use for -target the same ios version that is returned by xcrun
4+
# Build the MapLibre iOS SDK before running this script
5+
6+
xcrun --sdk iphonesimulator --show-sdk-path
7+
38
swiftc \
49
-c MapLibreRegistry.swift \
10+
-c Extensions.swift \
11+
-c Helpers.swift \
512
-module-name maplibre_ios \
6-
-emit-objc-header-path MapLibreRegistry.h \
13+
-emit-objc-header-path MapLibreIos.h \
714
-emit-library -o libmaplibreios.dylib \
8-
-target arm64-apple-ios18.1-simulator \
15+
-target arm64-apple-ios18.5-simulator \
916
-sdk $(xcrun --sdk iphonesimulator --show-sdk-path) \
10-
-F ../../../.build/MapLibre.xcframework/ios-arm64_x86_64-simulator/
17+
-F ../../../.build/MapLibre.xcframework/ios-arm64_x86_64-simulator/ \
18+
-framework MapLibre
Binary file not shown.

maplibre_ios/lib/maplibre_ffi.dart.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdint.h>
22
#import <Foundation/Foundation.h>
33
#import <objc/message.h>
4-
#import "../ios/maplibre_ios/Sources/maplibre_ios/MapLibreRegistry.h"
4+
#import "../ios/maplibre_ios/Sources/maplibre_ios/MapLibreIos.h"
55
#import "../MapLibre.h"
66

77
#if !__has_feature(objc_arc)

maplibre_ios/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ ffigen:
4040
objc-interfaces:
4141
include:
4242
- 'NSString'
43-
- 'MapLibreRegistry'
4443
- 'CLLocationCoordinate2D'
4544
- 'NSAttributedString'
4645
- 'NSImage'
@@ -55,10 +54,13 @@ ffigen:
5554
- 'UIViewConfigurationState'
5655
- 'NSExpression'
5756
- 'Helpers'
57+
- 'MapLibreRegistry'
58+
- 'Extensions'
5859
- 'MLN.*'
5960
module:
6061
'MapLibreRegistry': 'maplibre_ios'
6162
'Helpers': 'maplibre_ios'
63+
'Extensions': 'maplibre_ios'
6264
'MLNMapView': 'MapLibre'
6365
'MLNMapCamera': 'MapLibre'
6466
'MLNVectorTileSource': 'MapLibre'
@@ -86,7 +88,7 @@ ffigen:
8688
- '-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk'
8789
headers:
8890
entry-points:
89-
- 'ios/maplibre_ios/Sources/maplibre_ios/MapLibreRegistry.h'
91+
- 'ios/maplibre_ios/Sources/maplibre_ios/MapLibreIos.h'
9092
- 'MapLibre.h'
9193
preamble: |
9294
// ignore_for_file: type=lint, unused_element, unused_field |

0 commit comments

Comments
 (0)