From 8fc47c683e893fb722322059ce760b02748679e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Wed, 18 Oct 2023 20:09:42 +0200 Subject: [PATCH] refactor: code improvements (#3117) --- .../styles/layers/RNMBXSkyLayerManager.kt | 6 ---- .../RNMBXBackgroundLayerNativeComponent.ts | 15 +++++---- src/specs/RNMBXCameraNativeComponent.ts | 25 +++++++------- src/specs/RNMBXCircleLayerNativeComponent.ts | 19 ++++++----- .../RNMBXFillExtrusionLayerNativeComponent.ts | 21 +++++++----- src/specs/RNMBXFillLayerNativeComponent.ts | 19 ++++++----- src/specs/RNMBXHeatmapLayerNativeComponent.ts | 21 +++++++----- src/specs/RNMBXLineLayerNativeComponent.ts | 19 ++++++----- src/specs/RNMBXMapViewNativeComponent.ts | 33 ++++++++++--------- src/specs/RNMBXRasterLayerNativeComponent.ts | 21 +++++++----- src/specs/RNMBXSkyLayerNativeComponent.ts | 21 +++++++----- src/specs/RNMBXSymbolLayerNativeComponent.ts | 21 +++++++----- src/specs/codegenUtils.ts | 5 +++ 13 files changed, 139 insertions(+), 107 deletions(-) diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/styles/layers/RNMBXSkyLayerManager.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/styles/layers/RNMBXSkyLayerManager.kt index c68c5a17b..838851d55 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/styles/layers/RNMBXSkyLayerManager.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/styles/layers/RNMBXSkyLayerManager.kt @@ -61,12 +61,6 @@ class RNMBXSkyLayerManager : ViewGroupManager(), layer.setReactStyle(style.asMap()) } -// not available -// @ReactProp(name = "sourceLayerID") -// override fun setSourceLayerId(layer: RNMBXSkyLayer, sourceLayerID: Dynamic) { -// layer.setSourceLayerID(sourceLayerID.asString()) -// } - @ReactProp(name = "filter") override fun setFilter(layer: RNMBXSkyLayer, filterList: Dynamic) { layer.setFilter(filterList.asArray()) diff --git a/src/specs/RNMBXBackgroundLayerNativeComponent.ts b/src/specs/RNMBXBackgroundLayerNativeComponent.ts index 5667c3151..d05727309 100644 --- a/src/specs/RNMBXBackgroundLayerNativeComponent.ts +++ b/src/specs/RNMBXBackgroundLayerNativeComponent.ts @@ -4,19 +4,22 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { id: UnsafeMixed; sourceID: UnsafeMixed; - existing: UnsafeMixed; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXCameraNativeComponent.ts b/src/specs/RNMBXCameraNativeComponent.ts index 4b9f0a079..43a17e861 100644 --- a/src/specs/RNMBXCameraNativeComponent.ts +++ b/src/specs/RNMBXCameraNativeComponent.ts @@ -8,6 +8,9 @@ import { import type { NativeCameraStop, UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + type UserTrackingModeChangeEventType = { type: string; payloadRenamed: { @@ -18,21 +21,21 @@ type UserTrackingModeChangeEventType = { export interface NativeProps extends ViewProps { maxBounds?: UnsafeMixed; - animationDuration?: UnsafeMixed; - animationMode?: UnsafeMixed; + animationDuration?: OptionalProp; + animationMode?: OptionalProp; defaultStop?: UnsafeMixed; - userTrackingMode?: UnsafeMixed; + userTrackingMode?: OptionalProp; - followUserLocation?: UnsafeMixed; - followUserMode?: UnsafeMixed; - followZoomLevel?: UnsafeMixed; - followPitch?: UnsafeMixed; - followHeading?: UnsafeMixed; + followUserLocation?: OptionalProp; + followUserMode?: OptionalProp; + followZoomLevel?: OptionalProp; + followPitch?: OptionalProp; + followHeading?: OptionalProp; followPadding?: UnsafeMixed; - zoomLevel?: UnsafeMixed; - maxZoomLevel?: UnsafeMixed; - minZoomLevel?: UnsafeMixed; + zoomLevel?: OptionalProp; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; stop?: UnsafeMixed; onUserTrackingModeChange?: DirectEventHandler; diff --git a/src/specs/RNMBXCircleLayerNativeComponent.ts b/src/specs/RNMBXCircleLayerNativeComponent.ts index bc3a87479..fe4161aaf 100644 --- a/src/specs/RNMBXCircleLayerNativeComponent.ts +++ b/src/specs/RNMBXCircleLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + sourceID: OptionalProp; + existing: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID: OptionalProp; + belowLayerID: OptionalProp; + layerIndex: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel: OptionalProp; + minZoomLevel: OptionalProp; + sourceLayerID: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXFillExtrusionLayerNativeComponent.ts b/src/specs/RNMBXFillExtrusionLayerNativeComponent.ts index 8ed6c12d5..b3801a759 100644 --- a/src/specs/RNMBXFillExtrusionLayerNativeComponent.ts +++ b/src/specs/RNMBXFillExtrusionLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { - id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + id?: UnsafeMixed; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; + sourceLayerID?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXFillLayerNativeComponent.ts b/src/specs/RNMBXFillLayerNativeComponent.ts index 5f1b5c722..72fd5cb3b 100644 --- a/src/specs/RNMBXFillLayerNativeComponent.ts +++ b/src/specs/RNMBXFillLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; + sourceLayerID?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXHeatmapLayerNativeComponent.ts b/src/specs/RNMBXHeatmapLayerNativeComponent.ts index 810737371..b7c784c30 100644 --- a/src/specs/RNMBXHeatmapLayerNativeComponent.ts +++ b/src/specs/RNMBXHeatmapLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { - id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + id: OptionalProp; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; + sourceLayerID?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXLineLayerNativeComponent.ts b/src/specs/RNMBXLineLayerNativeComponent.ts index 6e48c632a..284572770 100644 --- a/src/specs/RNMBXLineLayerNativeComponent.ts +++ b/src/specs/RNMBXLineLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; + sourceLayerID?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXMapViewNativeComponent.ts b/src/specs/RNMBXMapViewNativeComponent.ts index c6467fba8..81872e538 100644 --- a/src/specs/RNMBXMapViewNativeComponent.ts +++ b/src/specs/RNMBXMapViewNativeComponent.ts @@ -7,6 +7,9 @@ import { import type { LocalizeLabels, Point, UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + type OnCameraChangedEventType = { type: string; payload: string }; type OnPressEventType = { type: string; payload: string }; type OnMapChangeEventType = { type: string; payload: string }; @@ -14,32 +17,32 @@ type OnMapChangeEventType = { type: string; payload: string }; export interface NativeProps extends ViewProps { onCameraChanged?: DirectEventHandler; - attributionEnabled?: UnsafeMixed; + attributionEnabled?: OptionalProp; attributionPosition?: UnsafeMixed; - logoEnabled?: UnsafeMixed; + logoEnabled?: OptionalProp; logoPosition?: UnsafeMixed; - compassEnabled?: UnsafeMixed; - compassFadeWhenNorth?: UnsafeMixed; + compassEnabled?: OptionalProp; + compassFadeWhenNorth?: OptionalProp; compassPosition?: UnsafeMixed; - compassViewPosition?: UnsafeMixed; - compassViewMargins?: UnsafeMixed; + compassViewPosition?: OptionalProp; + compassViewMargins?: OptionalProp; - scaleBarEnabled?: UnsafeMixed; + scaleBarEnabled?: OptionalProp; scaleBarPosition?: UnsafeMixed; - zoomEnabled?: UnsafeMixed; - scrollEnabled?: UnsafeMixed; - rotateEnabled?: UnsafeMixed; - pitchEnabled?: UnsafeMixed; + zoomEnabled?: OptionalProp; + scrollEnabled?: OptionalProp; + rotateEnabled?: OptionalProp; + pitchEnabled?: OptionalProp; - requestDisallowInterceptTouchEvent?: UnsafeMixed; + requestDisallowInterceptTouchEvent?: OptionalProp; - projection?: UnsafeMixed; + projection?: OptionalProp; localizeLabels?: UnsafeMixed; - styleURL?: UnsafeMixed; + styleURL?: OptionalProp; // Android only scaleBarViewMargins?: UnsafeMixed; @@ -47,7 +50,7 @@ export interface NativeProps extends ViewProps { attributionViewPosition?: UnsafeMixed; // iOS only - compassImage?: UnsafeMixed; + compassImage?: OptionalProp; onPress?: DirectEventHandler; onLongPress?: DirectEventHandler; diff --git a/src/specs/RNMBXRasterLayerNativeComponent.ts b/src/specs/RNMBXRasterLayerNativeComponent.ts index cff95f895..1d57a3641 100644 --- a/src/specs/RNMBXRasterLayerNativeComponent.ts +++ b/src/specs/RNMBXRasterLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { - id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + id: OptionalProp; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; + sourceLayerID?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXSkyLayerNativeComponent.ts b/src/specs/RNMBXSkyLayerNativeComponent.ts index a67b052e1..094e29b29 100644 --- a/src/specs/RNMBXSkyLayerNativeComponent.ts +++ b/src/specs/RNMBXSkyLayerNativeComponent.ts @@ -4,19 +4,22 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { - id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + id?: OptionalProp; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; - reactStyle: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; + reactStyle?: OptionalProp; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/RNMBXSymbolLayerNativeComponent.ts b/src/specs/RNMBXSymbolLayerNativeComponent.ts index 6571f6cf4..81dd546b7 100644 --- a/src/specs/RNMBXSymbolLayerNativeComponent.ts +++ b/src/specs/RNMBXSymbolLayerNativeComponent.ts @@ -4,20 +4,23 @@ import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; import type { UnsafeMixed } from './codegenUtils'; +// see https://github.com/rnmapbox/maps/wiki/FabricOptionalProp +type OptionalProp = UnsafeMixed; + export interface NativeProps extends ViewProps { - id: UnsafeMixed; - sourceID: UnsafeMixed; - existing: UnsafeMixed; + id?: OptionalProp; + sourceID?: OptionalProp; + existing?: OptionalProp; filter: UnsafeMixed; - aboveLayerID: UnsafeMixed; - belowLayerID: UnsafeMixed; - layerIndex: UnsafeMixed; + aboveLayerID?: OptionalProp; + belowLayerID?: OptionalProp; + layerIndex?: OptionalProp; reactStyle: UnsafeMixed; - maxZoomLevel: UnsafeMixed; - minZoomLevel: UnsafeMixed; - sourceLayerID: UnsafeMixed; + maxZoomLevel?: OptionalProp; + minZoomLevel?: OptionalProp; + sourceLayerID?: OptionalProp; } export default codegenNativeComponent( diff --git a/src/specs/codegenUtils.ts b/src/specs/codegenUtils.ts index b5fea7d4e..54396c9f1 100644 --- a/src/specs/codegenUtils.ts +++ b/src/specs/codegenUtils.ts @@ -2,6 +2,11 @@ // since codegen doesn't really follow imports, this way we can trick it into generating the correct type // while keeping typescript happy export type UnsafeMixed = T; + +// Fabric doesn't support optional props, so we need to use UnsafeMixed +// https://github.com/rnmapbox/maps/pull/3082#discussion_r1339858750 +export type OptionalProp = UnsafeMixed; + import { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes'; export type Point = {