package expo.modules.gaodemap.navigation import expo.modules.kotlin.modules.Module import expo.modules.kotlin.modules.ModuleDefinition /** * 高德导航视图 Module */ class ExpoGaodeMapNaviViewModule : Module() { override fun definition() = ModuleDefinition { Name("ExpoGaodeMapNaviView") OnActivityEntersForeground { ExpoGaodeMapNaviView.resumeActiveViews() } OnActivityEntersBackground { ExpoGaodeMapNaviView.pauseActiveViews() } OnActivityDestroys { ExpoGaodeMapNaviView.destroyActiveViews() } View(ExpoGaodeMapNaviView::class) { Events( "onNavigationReady", "onNavigationStarted", "onNavigationFailed", "onNavigationEnded", "onLocationUpdate", "onNavigationText", "onArriveDestination", "onRouteCalculated", "onRouteRecalculate", "onWayPointArrived", "onGpsStatusChanged", "onNavigationInfoUpdate", "onGpsSignalWeak", "onNavigationVisualStateUpdate", "onLaneInfoUpdate", "onTrafficStatusesUpdate" ) OnViewDestroys { view: ExpoGaodeMapNaviView -> view.onDestroy() } // Props Prop("naviType") { view, type -> view.applyNaviType(type) } Prop("enableVoice") { view, enabled -> view.applyEnableVoice(enabled) } Prop("carImage") { view, uri -> view.applyCarImage(uri) } Prop?>("carImageSize") { view, value -> val width = value?.get("width") val height = value?.get("height") view.applyCarImageSize(width, height) } Prop("fourCornersImage") { view, uri -> view.applyFourCornersImage(uri) } Prop("startPointImage") { view, uri -> view.applyStartPointImage(uri) } Prop("wayPointImage") { view, uri -> view.applyWayPointImage(uri) } Prop>?>("customWaypointMarkers") { view, markers -> view.applyCustomWaypointMarkers(markers) } Prop("endPointImage") { view, uri -> view.applyEndPointImage(uri) } Prop("autoLockCar") { view, enabled -> view.applyAutoLockCar(enabled) } Prop("autoChangeZoom") { view, enabled -> view.applyAutoChangeZoom(enabled) } Prop("trafficLayerEnabled") { view, enabled -> view.applyTrafficLayerEnabled(enabled) } Prop("realCrossDisplay") { view, enabled -> view.applyRealCrossDisplay(enabled) } Prop("naviMode") { view, mode -> view.applyNaviMode(mode) } Prop("showMode") { view, mode -> view.applyShowMode(mode) } Prop("isNightMode") { view, enabled -> view.applyNightMode(enabled) } Prop("mapViewModeType") { view, mode -> view.applyMapViewModeType(mode) } Prop("carOverlayVisible") { view, visible -> view.applyCarOverlayVisible(visible) } Prop("showTrafficLights") { view, visible -> view.applyTrafficLightsVisible(visible) } Prop("showCompassEnabled") {view, enabled -> view.applyShowCompassEnabled(enabled) } Prop("naviStatusBarEnabled") { view, enabled -> view.applyNaviStatusBarEnabled(enabled) } Prop?>("routeMarkerVisible") { view, config -> config?.let { val showStartEndVia = it["showStartEndVia"] as? Boolean ?: true val showFootFerry = it["showFootFerry"] as? Boolean ?: true val showForbidden = it["showForbidden"] as? Boolean ?: true val showRouteStartIcon = it["showRouteStartIcon"] as? Boolean ?: true val showRouteEndIcon = it["showRouteEndIcon"] as? Boolean ?: true view.applyRouteMarkerVisible(showStartEndVia, showFootFerry, showForbidden, showRouteStartIcon, showRouteEndIcon) } } // 路线转向箭头可见性控制 Prop("naviArrowVisible") { view, visible -> view.applyNaviArrowVisible(visible) } Prop("laneInfoVisible") { view, visible -> view.applyLaneInfoVisible(visible) } Prop("modeCrossDisplay") { view, visible -> view.applyModeCrossDisplay(visible) } Prop("eyrieCrossDisplay") { view, visible -> view.applyEyrieCrossDisplay(visible) } Prop("secondActionVisible") { view, visible -> view.applySecondActionVisible(visible) } Prop("backupOverlayVisible") { view, visible -> view.applyBackupOverlayVisible(visible) } // 是否显示拥堵气泡 Prop("showDriveCongestion") { view, show -> view.applyShowDriveCongestion(show) } // 是否显示红绿灯倒计时气泡 Prop("showTrafficLightView") { view, show -> view.applyShowTrafficLightView(show) } //设置是否为骑步行视图 Prop("isNaviTravelView") { view, isRideStepView -> view.applyIsNaviTravelView(isRideStepView) } Prop("androidStatusBarPaddingTop") { view, topDp -> view.applyAndroidStatusBarPaddingTop(topDp) } Prop("lockZoom") { view, level -> view.applyLockZoom(level) } Prop("lockTilt") { view, tilt -> view.applyLockTilt(tilt) } Prop("eagleMapVisible") { view, visible -> view.applyEagleMapVisible(visible) } Prop?>("pointToCenter") { view, value -> val x = value?.get("x") ?: 0.0 val y = value?.get("y") ?: 0.0 view.applyPointToCenter(x, y) } Prop("hideNativeTopInfoLayout") { view, hidden -> view.applyHideNativeTopInfoLayout(hidden) } Prop("showCamera") { view, enabled -> view.applyShowCamera(enabled) } Prop("showUIElements") { view, visible -> view.applyShowUIElements(visible) } Prop("androidBackgroundNavigationNotificationEnabled") { view, enabled -> view.applyAndroidBackgroundNavigationNotificationEnabled(enabled) } // iOS-only prop, keep a no-op mapping on Android for cross-platform prop compatibility. Prop("iosLiveActivityEnabled") { _: ExpoGaodeMapNaviView, _: Boolean -> } Prop("showTrafficBar") { view, enabled -> view.applyAndroidTrafficBarEnabled(enabled) } Prop("showTrafficButton"){ view, enabled -> view.applyShowTrafficButton(enabled) } Prop("showBrowseRouteButton") { view, enabled -> view.applyShowBrowseRouteButton(enabled) } Prop("showVectorline"){ view, enabled -> view.applyShowVectorline(enabled) } Prop("showGreyAfterPass") { view, enabled -> view.applyShowGreyAfterPass(enabled) } // 方法 AsyncFunction("startNavigation") { view: ExpoGaodeMapNaviView, startLat: Double, startLng: Double, endLat: Double, endLng: Double, promise: expo.modules.kotlin.Promise -> view.startNavigation(startLat, startLng, endLat, endLng, promise) } AsyncFunction("startNavigationWithIndependentPath") { view: ExpoGaodeMapNaviView, token: Int, routeId: Int?, routeIndex: Int?, naviType: Int?, promise: expo.modules.kotlin.Promise -> view.startNavigationWithIndependentPath(token, routeId, routeIndex, naviType, promise) } AsyncFunction("stopNavigation") { view: ExpoGaodeMapNaviView, promise: expo.modules.kotlin.Promise -> view.stopNavigation(promise) } AsyncFunction("playCustomTTS") { view: ExpoGaodeMapNaviView, text: String, forcePlay: Boolean, promise: expo.modules.kotlin.Promise -> val success = view.playCustomTTS(text, forcePlay) if (success) { promise.resolve( mapOf( "success" to true ) ) } else { promise.reject("PLAY_TTS_FAILED", "当前场景暂不支持或正在播报其他导航语音", null) } } } } }