Я пытаюсь создать компонент навигации Mapbox с помощью React Native. Итак, мой вопрос, каков наилучший способ реализовать его через собственный компонент React? Вся помощь приветствуется. Спасибо
RN Компонент
var navDemo = NativeModules.NavDemo;
navDemo.renderNaviDemo(
(originLat = this.props.currentLocation.coords.latitude),
(originLon = this.props.currentLocation.coords.longitude),
(originName = "Start"),
(destinationLat = this.state.manoeuvreDetails.geometry
.coordinates[1]),
(destinationLon = this.state.manoeuvreDetails.geometry
.coordinates[0]),
(destinationName = this.state.manoeuvreDetails.name)
);
Swift Class
import Foundation
import UIKit
import MapboxCoreNavigation
import MapboxNavigation
import MapboxDirections
import Mapbox
@objc(NavDemo)
class NavDemo: NSObject {
@objc
func renderNaviDemo(_ originLat: NSNumber, oriLon originLon: NSNumber, oriName originName: NSString, destLat destinationLat: NSNumber, destLon destinationLon: NSNumber, destName destinationName: NSString) {
let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude: CLLocationDegrees(truncating: originLat), longitude: CLLocationDegrees(truncating: originLon)), name: originName as String)
let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: CLLocationDegrees(truncating: destinationLat), longitude: CLLocationDegrees(truncating: destinationLon)), name: destinationName as String)
let options = NavigationRouteOptions(waypoints: [origin, destination])
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else { return }
let navigationService = MapboxNavigationService(route: route, simulating: .never)
let navigationOptions = NavigationOptions(navigationService: navigationService)
let viewController = NavigationViewController(for: route, options: navigationOptions)
let appDelegate = UIApplication.shared.delegate
appDelegate!.window!!.rootViewController!.present(viewController, animated: true, completion: nil)
}
}
}