[ios, macos] Testify MGLMapView gesture recognizer example

This commit is contained in:
Minh Nguyễn
2017-01-24 13:07:34 -08:00
committed by Minh Nguyễn
parent f5bcf186f6
commit 7684bc2125
3 changed files with 24 additions and 2 deletions

View File

@@ -108,10 +108,10 @@ function completeExamples(os) {
}
// Resolve conditional compilation blocks.
example = example.replace(/^(\s*)#if\s+os\((iOS|macOS)\)\n([^]*?)(?:^\1#else\n([^]*?))?^\1#endif\n/gm,
example = example.replace(/^(\s*)#if\s+os\((iOS|macOS)\)\n([^]*?)(?:^\1#else\n([^]*?))?^\1#endif\b\n?/gm,
function (m, indentation, ifOs, ifCase, elseCase) {
return (os === ifOs ? ifCase : elseCase).replace(new RegExp('^ ', 'gm'), '');
});
}).replace(/\n$/, '');
// Insert the test method contents into the documentation comment just
// above the substructure.

View File

@@ -217,4 +217,25 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "contour"))
}
func testMGLMapView() {
//#-example-code
#if os(macOS)
class MapClickGestureRecognizer: NSClickGestureRecognizer {
override func shouldRequireFailure(of otherGestureRecognizer: NSGestureRecognizer) -> Bool {
return otherGestureRecognizer is NSClickGestureRecognizer
}
}
#else
let mapTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(myCustomFunction))
for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
mapTapGestureRecognizer.require(toFail: recognizer)
}
mapView.addGestureRecognizer(mapTapGestureRecognizer)
#endif
//#-end-example-code
}
// For testMGLMapView().
func myCustomFunction() {}
}

View File

@@ -84,6 +84,7 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) {
for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
mapTapGestureRecognizer.require(toFail: recognizer)
}
mapView.addGestureRecognizer(mapTapGestureRecognizer)
```
@note You are responsible for getting permission to use the map data and for