ReviewOS

also looking at this

craft-native/craft

fix(native): retain keyed controls and correct map and tab chrome

#368
Merged chris wants to merge codex/native-repeated-selector-identity into main
32 files +449 -100

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.

packages/ios/fixtures/native-screen/NativeRenderUnitTests.swiftmodified+38-0
Changes to packages/ios/fixtures/native-screen/NativeRenderUnitTests.swift
@@ -901,6 +901,44 @@ final class NativeRenderUnitTests: XCTestCase {
901901 XCTAssertEqual(marker.transform.b, 1, accuracy: 0.02)
902902 }
903903
904 func testMapDirectionSignsKeepALightBackdropAndTheAuthoredColor() throws {
905 for appearance in [UIUserInterfaceStyle.light, .dark] {
906 let controller = CraftNativeScreenController(config: CraftConfig())
907 controller.overrideUserInterfaceStyle = appearance
908 controller.loadViewIfNeeded()
909 controller.render([
910 "type": "Map", "props": ["key": "contrast-map"],
911 "style": ["width": 320, "height": 320],
912 "children": [["type": "MapMarker", "props": ["id": "direction", "geometry": [37.7, -119.5], "bearing": 90, "pinColor": "#365b2d"]]],
913 ])
914 let map = try XCTUnwrap(find(MKMapView.self, key: "contrast-map", below: controller.view))
915 let annotation = try XCTUnwrap(map.annotations.first)
916 let marker = try XCTUnwrap(map.delegate?.mapView?(map, viewFor: annotation))
917 let image = try XCTUnwrap(marker.image)
918 let raster = UIGraphicsImageRenderer(size: image.size).image { _ in image.draw(at: .zero) }
919 let cgImage = try XCTUnwrap(raster.cgImage)
920 var pixels = [UInt8](repeating: 0, count: cgImage.width * cgImage.height * 4)
921 try pixels.withUnsafeMutableBytes { bytes in
922 let context = try XCTUnwrap(CGContext(data: bytes.baseAddress, width: cgImage.width, height: cgImage.height,
923 bitsPerComponent: 8, bytesPerRow: cgImage.width * 4, space: CGColorSpaceCreateDeviceRGB(),
924 bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue))
925 context.draw(cgImage, in: CGRect(x: 0, y: 0, width: cgImage.width, height: cgImage.height))
926 }
927 var opaque = 0
928 var light = 0
929 var authored = 0
930 for offset in stride(from: 0, to: pixels.count, by: 4) where pixels[offset + 3] > 240 {
931 opaque += 1
932 let red = Int(pixels[offset]), green = Int(pixels[offset + 1]), blue = Int(pixels[offset + 2])
933 if red > 235 && green > 235 && blue > 235 { light += 1 }
934 if abs(red - 54) < 12 && abs(green - 91) < 12 && abs(blue - 45) < 12 { authored += 1 }
935 }
936 XCTAssertGreaterThan(opaque, 50)
937 XCTAssertGreaterThan(light, opaque / 3, "direction signs need an opaque light backdrop over the basemap")
938 XCTAssertGreaterThan(authored, 10, "the native direction sign ignored its authored pinColor")
939 }
940 }
941
904942 func testMapPreservesAuthoredPolylineOrderAcrossUpdatesAndMoves() throws {
905943 let controller = CraftNativeScreenController(config: CraftConfig())
906944 let window = try hostWindow()