diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bed3ed7..210ec92 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -37,10 +37,10 @@ jobs: - name: Generate nitrogen code run: yarn nitrogen - - name: Install ktlint & swiftlint + - name: Install ktlint & swiftformat run: | brew install ktlint - brew install swiftlint + brew install swiftformat - name: Lint files run: yarn lint diff --git a/ios/.swiftformat b/ios/.swiftformat index a18d528..b05e89f 100644 --- a/ios/.swiftformat +++ b/ios/.swiftformat @@ -16,7 +16,7 @@ --wrap-return-type never --disable wrapMultilineStatementBraces ---rules indent,braces,spaceInsideParens,spaceInsideBraces,spaceAroundOperators +--rules indent,braces,spaceInsideParens,spaceInsideBraces,spaceAroundOperators,consecutiveSpaces,trailingSpace ---trim-whitespace nonblank-lines +--trim-whitespace always --linebreaks lf diff --git a/ios/.swiftlint.yml b/ios/.swiftlint.yml deleted file mode 100644 index a84aed4..0000000 --- a/ios/.swiftlint.yml +++ /dev/null @@ -1,24 +0,0 @@ -disabled_rules: - - file_length - - type_body_length - - cyclomatic_complexity - - function_body_length - - closure_parameter_position - -identifier_name: - min_length: - warning: 1 - error: 1 - max_length: - warning: 40 - error: 100 - -line_length: - warning: 150 - error: 200 - ignores_comments: true - ignores_urls: true - ignores_function_declarations: true - ignores_interpolated_strings: true - -reporter: 'xcode' diff --git a/ios/RNGoogleMapsPlusStreetView.swift b/ios/RNGoogleMapsPlusStreetView.swift index 1eea079..a8330f0 100644 --- a/ios/RNGoogleMapsPlusStreetView.swift +++ b/ios/RNGoogleMapsPlusStreetView.swift @@ -4,16 +4,16 @@ import GoogleMaps import NitroModules final class RNGoogleMapsPlusStreetView: HybridRNGoogleMapsPlusStreetViewSpec { - + private let mapErrorHandler: MapErrorHandler private let permissionHandler: PermissionHandler private let locationHandler: LocationHandler private let impl: StreetViewPanoramaViewImpl - + var view: UIView { return impl } - + override init() { self.permissionHandler = PermissionHandler() self.locationHandler = LocationHandler() @@ -23,18 +23,19 @@ final class RNGoogleMapsPlusStreetView: HybridRNGoogleMapsPlusStreetViewSpec { locationHandler: locationHandler ) } - + func onDropView() { impl.deinitInternal() } - + var initialProps: RNStreetViewInitialProps? { didSet { impl.streetViewInitialProps = initialProps } } - + var uiSettings: RNStreetViewUiSettings? { didSet { impl.uiSettings = uiSettings } } + var onPanoramaReady: ((Bool) -> Void)? { didSet { impl.onPanoramaReady = onPanoramaReady } } @@ -56,14 +57,14 @@ final class RNGoogleMapsPlusStreetView: HybridRNGoogleMapsPlusStreetViewSpec { var onPanoramaError: ((RNMapErrorCode, String) -> Void)? { didSet { mapErrorHandler.callback = onPanoramaError } } - + func setCamera(camera: RNStreetViewCamera, animated: Bool?, durationMs: Double?) { onMain { let cam = camera.toGMSPanoramaCamera(current: self.impl.currentCamera) self.impl.setCamera(cam, animated: animated ?? false, durationMs: durationMs ?? 1000) } } - + func setPosition(position: RNLatLng, radius: Double?, source: RNStreetViewSource?) { impl.setPosition( position.toCLLocationCoordinate2D(), @@ -71,23 +72,23 @@ final class RNGoogleMapsPlusStreetView: HybridRNGoogleMapsPlusStreetViewSpec { source: source?.toGMSPanoramaSource ?? .default ) } - + func setPositionById(panoramaId: String) { impl.setPositionById(panoramaId) } - + func showLocationDialog() { locationHandler.showLocationDialog() } - + func openLocationSettings() { locationHandler.openLocationSettings() } - + func requestLocationPermission() -> NitroModules.Promise { return permissionHandler.requestLocationPermission() } - + func isGooglePlayServicesAvailable() -> Bool { return false } diff --git a/ios/StreetViewPanoramaViewImpl.swift b/ios/StreetViewPanoramaViewImpl.swift index b4b3544..0df5f9b 100644 --- a/ios/StreetViewPanoramaViewImpl.swift +++ b/ios/StreetViewPanoramaViewImpl.swift @@ -4,13 +4,13 @@ import NitroModules import UIKit final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { - + private let mapErrorHandler: MapErrorHandler private let locationHandler: LocationHandler private var panoramaView: GMSPanoramaView? private var panoramaViewInitialized = false private var deInitialized = false - + init( frame: CGRect = .zero, mapErrorHandler: MapErrorHandler, @@ -20,10 +20,10 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { self.locationHandler = locationHandler super.init(frame: frame) } - + private var lifecycleAttached = false private var lifecycleTasks = [Task]() - + private func attachLifecycleObservers() { if lifecycleAttached { return } lifecycleAttached = true @@ -46,23 +46,23 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { } ) } - + private func detachLifecycleObservers() { if !lifecycleAttached { return } lifecycleAttached = false lifecycleTasks.forEach { $0.cancel() } lifecycleTasks.removeAll() } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + func initPanoramaView() { onMain { if self.panoramaViewInitialized { return } self.panoramaViewInitialized = true - + let props = self.streetViewInitialProps if let position = props?.position { let coordinate = position.toCLLocationCoordinate2D() @@ -75,42 +75,42 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { } else { self.panoramaView = GMSPanoramaView(frame: self.bounds) } - + props?.panoramaId.map { self.panoramaView?.move(toPanoramaID: $0) } props?.camera.map { self.panoramaView?.camera = $0.toGMSPanoramaCamera() } - + self.panoramaView?.delegate = self self.panoramaView?.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.panoramaView.map { self.addSubview($0) } - + self.applyProps() self.initLocationCallbacks() self.onPanoramaReady?(true) } } - + private func initLocationCallbacks() { locationHandler.onUpdate = { [weak self] loc in onMain { [weak self] in self?.onLocationUpdate?(loc.toRnLocation()) } } - + locationHandler.onError = { [weak self] error in onMain { [weak self] in self?.onLocationError?(error) } } } - + private func applyProps() { ({ self.uiSettings = self.uiSettings })() } - + var currentCamera: GMSPanoramaCamera? { panoramaView?.camera } - + var streetViewInitialProps: RNStreetViewInitialProps? - + var uiSettings: RNStreetViewUiSettings? { didSet { onMain { @@ -121,14 +121,14 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { } } } - + var onPanoramaReady: ((Bool) -> Void)? var onLocationUpdate: ((RNLocation) -> Void)? var onLocationError: ((RNLocationErrorCode) -> Void)? var onPanoramaChange: ((RNStreetViewPanoramaLocation) -> Void)? var onCameraChange: ((RNStreetViewCamera) -> Void)? var onPanoramaPress: ((RNStreetViewOrientation) -> Void)? - + func setCamera(_ camera: GMSPanoramaCamera, animated: Bool, durationMs: Double) { onMain { if animated { @@ -140,7 +140,7 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { } } } - + func setPosition(_ coordinate: CLLocationCoordinate2D, radius: UInt?, source: GMSPanoramaSource) { onMain { if let radius { @@ -150,13 +150,13 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { } } } - + func setPositionById(_ panoramaId: String) { onMain { self.panoramaView?.move(toPanoramaID: panoramaId) } } - + func deinitInternal() { guard !deInitialized else { return } deInitialized = true @@ -167,17 +167,17 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { self.panoramaView = nil } } - + private func appDidBecomeActive() { if window != nil { locationHandler.start() } } - + private func appDidEnterBackground() { locationHandler.stop() } - + override func didMoveToWindow() { super.didMoveToWindow() if window != nil { @@ -189,11 +189,11 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { detachLifecycleObservers() } } - + deinit { deinitInternal() } - + func panoramaView(_ panoramaView: GMSPanoramaView, didMoveTo panorama: GMSPanorama?) { onMain { guard let panorama else { return } @@ -209,15 +209,15 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { ) } } - + func panoramaView(_ panoramaView: GMSPanoramaView, error: Error, onMoveNearCoordinate coordinate: CLLocationCoordinate2D) { mapErrorHandler.report(.panoramaNotFound, error.localizedDescription, error) } - + func panoramaView(_ panoramaView: GMSPanoramaView, error: Error, onMoveToPanoramaID panoramaID: String) { mapErrorHandler.report(.panoramaNotFound, error.localizedDescription, error) } - + func panoramaView(_ panoramaView: GMSPanoramaView, didMove camera: GMSPanoramaCamera) { onMain { self.onCameraChange?( @@ -229,7 +229,7 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate { ) } } - + func panoramaView(_ panoramaView: GMSPanoramaView, didTap point: CGPoint) { onMain { let orientation = panoramaView.orientation(for: point) diff --git a/ios/extensions/String+Extensions.swift b/ios/extensions/String+Extensions.swift index 3daeaf1..851921e 100644 --- a/ios/extensions/String+Extensions.swift +++ b/ios/extensions/String+Extensions.swift @@ -87,7 +87,6 @@ extension UIColor { let x = c * (1 - Swift.abs((h / 60).truncatingRemainder(dividingBy: 2) - 1)) let m = l - c / 2 - // swiftlint:disable:next large_tuple let (r1, g1, b1): (Double, Double, Double) switch h { case 0 ..< 60: (r1, g1, b1) = (c, x, 0) diff --git a/package.json b/package.json index a4e5ac9..7e5e215 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint": "yarn lint:js && yarn lint:android && yarn lint:ios", "lint:js": "eslint . --max-warnings 0 && yarn prettier --check .", "lint:android": "cd android && ktlint -F ./**/*.kt*", - "lint:ios": "cd ios && swiftlint --quiet && swiftformat . --lint", + "lint:ios": "cd ios && swiftformat . --lint", "format": "yarn format:js && yarn format:ios && yarn format:android", "format:js": "eslint . --fix && prettier --write .", "format:android": "cd android && ktlint --format ./**/*.kt*",