-
-
Notifications
You must be signed in to change notification settings - Fork 938
Expand file tree
/
Copy pathRNMBXInteractiveElement.swift
More file actions
69 lines (55 loc) · 1.71 KB
/
RNMBXInteractiveElement.swift
File metadata and controls
69 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import MapboxMaps
@objc
public class RNMBXInteractiveElement : UIView, RNMBXMapComponent {
weak var map : RNMBXMapView? = nil
static let hitboxDefault = 44.0
@objc public var draggable: Bool = false
@objc public var hasPressListener: Bool = false
@objc public var hitbox : [String:NSNumber] = [
"width": NSNumber(value: hitboxDefault),
"height": NSNumber(value: hitboxDefault)
]
@objc public var id: String! = nil {
willSet {
if id != nil && newValue != id {
Logger.log(level:.warn, message: "Changing id from: \(optional: id) to \(optional: newValue), changing of id is not supported")
if let map = map { removeFromMap(map, reason: .ComponentChange) }
}
}
didSet {
if oldValue != nil && oldValue != id {
if let map = map {
self.map?.withMapboxMap { [weak self] _mapboxMap in
guard let self = self else { return }
self.addToMap(map, style: _mapboxMap.style)
}
}
}
}
}
@objc public var onDragStart: RCTBubblingEventBlock? = nil
@objc public var onPress: RCTBubblingEventBlock? = nil
func getLayerIDs() -> [String] {
return []
}
func isDraggable() -> Bool {
return draggable
}
func isTouchable() -> Bool {
return hasPressListener
}
// MARK: - RNMBXMapComponent
public func addToMap(_ map: RNMBXMapView, style: Style) {
if (self.id == nil) {
Logger.log(level: .error, message: "id is required on \(self) but not specified")
}
self.map = map
}
public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
self.map = nil
return true
}
public func waitForStyleLoad() -> Bool {
return true
}
}