also looking at this
feat(maps): add key-free native Android maps and shared map controls
#363
28 files
+1857
-481
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -901,6 +901,48 @@ final class NativeRenderUnitTests: XCTestCase { | ||
| 901 | 901 | XCTAssertEqual(marker.transform.b, 1, accuracy: 0.02) |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | func testMapPreservesAuthoredPolylineOrderAcrossUpdatesAndMoves() throws { | |
| 905 | let controller = CraftNativeScreenController(config: CraftConfig()) | |
| 906 | let window = try hostWindow() | |
| 907 | window.rootViewController = controller | |
| 908 | window.makeKeyAndVisible() | |
| 909 | defer { window.isHidden = true } | |
| 910 | controller.loadViewIfNeeded() | |
| 911 | func document(_ casingWidth: Double, reversed: Bool = false) -> [String: Any] { | |
| 912 | let casing: [String: Any] = ["type": "MapPolyline", "props": ["id": "casing", "geometry": [37.7, -119.5, 37.71, -119.51], "strokeColor": "#365b2d", "strokeWidth": casingWidth]] | |
| 913 | let route: [String: Any] = ["type": "MapPolyline", "props": ["id": "route", "geometry": [37.7, -119.5, 37.71, -119.51], "strokeColor": "#91e86b", "strokeWidth": 5]] | |
| 914 | return ["type": "Map", "props": ["key": "ordered-map"], | |
| 915 | "style": ["width": 320, "height": 320], | |
| 916 | "children": reversed ? [route, casing] : [casing, route]] | |
| 917 | } | |
| 918 | controller.render(document(9)) | |
| 919 | controller.view.layoutIfNeeded() | |
| 920 | let map = try XCTUnwrap(find(MKMapView.self, key: "ordered-map", below: controller.view)) | |
| 921 | func widths() throws -> [CGFloat] { | |
| 922 | try map.overlays.compactMap { $0 as? MKPolyline }.map { line in | |
| 923 | let renderer = try XCTUnwrap(map.delegate?.mapView?(map, rendererFor: line) as? MKPolylineRenderer) | |
| 924 | return renderer.lineWidth | |
| 925 | } | |
| 926 | } | |
| 927 | XCTAssertEqual(try widths(), [9, 5], "the bright route draws above its wider casing") | |
| 928 | let foreground = try XCTUnwrap(map.overlays.compactMap { $0 as? MKPolyline }.last) | |
| 929 | ||
| 930 | // Replacing a lower overlay must not move it above an unchanged line. | |
| 931 | controller.render(document(11)) | |
| 932 | controller.view.layoutIfNeeded() | |
| 933 | XCTAssertTrue(map === find(MKMapView.self, key: "ordered-map", below: controller.view)) | |
| 934 | XCTAssertEqual(try widths(), [11, 5]) | |
| 935 | XCTAssertTrue(map.overlays.compactMap { $0 as? MKPolyline }.last === foreground) | |
| 936 | ||
| 937 | // Child moves are draw-order changes even when geometry is unchanged. | |
| 938 | controller.render(document(11, reversed: true)) | |
| 939 | controller.view.layoutIfNeeded() | |
| 940 | XCTAssertEqual(try widths(), [5, 11]) | |
| 941 | controller.render(document(11)) | |
| 942 | controller.view.layoutIfNeeded() | |
| 943 | XCTAssertEqual(try widths(), [11, 5]) | |
| 944 | } | |
| 945 | ||
| 904 | 946 | func testMapUpdatesNativePinColorAndTiltGestureWithoutReplacingTheMarker() throws { |
| 905 | 947 | let controller = CraftNativeScreenController(config: CraftConfig()) |
| 906 | 948 | let window = try hostWindow() |