Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ios/.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 0 additions & 24 deletions ios/.swiftlint.yml

This file was deleted.

27 changes: 14 additions & 13 deletions ios/RNGoogleMapsPlusStreetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 }
}
Expand All @@ -56,38 +57,38 @@ 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(),
radius: radius.map { UInt($0) },
source: source?.toGMSPanoramaSource ?? .default
)
}

func setPositionById(panoramaId: String) {
impl.setPositionById(panoramaId)
}

func showLocationDialog() {
locationHandler.showLocationDialog()
}

func openLocationSettings() {
locationHandler.openLocationSettings()
}

func requestLocationPermission() -> NitroModules.Promise<RNLocationPermissionResult> {
return permissionHandler.requestLocationPermission()
}

func isGooglePlayServicesAvailable() -> Bool {
return false
}
Expand Down
62 changes: 31 additions & 31 deletions ios/StreetViewPanoramaViewImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,10 +20,10 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate {
self.locationHandler = locationHandler
super.init(frame: frame)
}

private var lifecycleAttached = false
private var lifecycleTasks = [Task<Void, Never>]()

private func attachLifecycleObservers() {
if lifecycleAttached { return }
lifecycleAttached = true
Expand All @@ -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()
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -140,7 +140,7 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate {
}
}
}

func setPosition(_ coordinate: CLLocationCoordinate2D, radius: UInt?, source: GMSPanoramaSource) {
onMain {
if let radius {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 }
Expand All @@ -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?(
Expand All @@ -229,7 +229,7 @@ final class StreetViewPanoramaViewImpl: UIView, GMSPanoramaViewDelegate {
)
}
}

func panoramaView(_ panoramaView: GMSPanoramaView, didTap point: CGPoint) {
onMain {
let orientation = panoramaView.orientation(for: point)
Expand Down
1 change: 0 additions & 1 deletion ios/extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand Down
Loading