diff --git a/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt b/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt index 32399249c..64a9575bd 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt @@ -8,6 +8,7 @@ import com.facebook.react.module.model.ReactModuleInfo import com.facebook.react.module.model.ReactModuleInfoProvider import com.facebook.react.uimanager.ViewManager import com.rnmapbox.rnmbx.components.annotation.RNMBXCalloutManager +import com.rnmapbox.rnmbx.components.annotation.RNMBXMarkerViewContentManager import com.rnmapbox.rnmbx.components.annotation.RNMBXMarkerViewManager import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationManager import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationModule @@ -117,6 +118,7 @@ class RNMBXPackage : TurboReactPackage() { // annotations managers.add(RNMBXMarkerViewManager(reactApplicationContext)) + managers.add(RNMBXMarkerViewContentManager(reactApplicationContext)) managers.add(RNMBXPointAnnotationManager(reactApplicationContext, getViewTagResolver(reactApplicationContext, "RNMBXPointAnnotationManager"))) managers.add(RNMBXCalloutManager()) managers.add(RNMBXNativeUserLocationManager()) diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt index 7fbdb0b06..711cdf4fe 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt @@ -116,11 +116,13 @@ class RNMBXMarkerView(context: Context?, private val mManager: RNMBXMarkerViewMa val options = getOptions() + val annotation = mMapView?.viewAnnotationManager?.addViewAnnotation( view, options ) didAddToMap = true + } fun update() { @@ -176,6 +178,7 @@ class RNMBXMarkerView(context: Context?, private val mManager: RNMBXMarkerViewMa allowOverlap(mAllowOverlap) offsets(offset.dx, offset.dy) selected(mIsSelected) + } return options } diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt new file mode 100644 index 000000000..94b157360 --- /dev/null +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt @@ -0,0 +1,23 @@ +package com.rnmapbox.rnmbx.components.annotation + +import android.content.Context +import com.facebook.react.uimanager.MeasureSpecAssertions +import com.facebook.react.views.view.ReactViewGroup + +class RNMBXMarkerViewContent(context: Context): ReactViewGroup(context) { + // see https://github.com/rnmapbox/maps/pull/3235 + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + try { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + } catch(e: IllegalStateException) { + val w = MeasureSpec.getSize(widthMeasureSpec) + val h = MeasureSpec.getSize(heightMeasureSpec) + setMeasuredDimension( + if (w == 0) measuredWidth else w, + if (h == 0) measuredHeight else h + ) + } + } + +} + diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContentManager.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContentManager.kt new file mode 100644 index 000000000..bbf271fe8 --- /dev/null +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContentManager.kt @@ -0,0 +1,23 @@ +package com.rnmapbox.rnmbx.components.annotation + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.react.uimanager.ViewGroupManager +import com.facebook.react.viewmanagers.RNMBXMarkerViewContentManagerInterface + + +class RNMBXMarkerViewContentManager(reactApplicationContext: ReactApplicationContext) : + ViewGroupManager(), + RNMBXMarkerViewContentManagerInterface { + override fun getName(): String { + return REACT_CLASS + } + + override fun createViewInstance(context: ThemedReactContext): RNMBXMarkerViewContent { + return RNMBXMarkerViewContent(context) + } + + companion object { + const val REACT_CLASS = "RNMBXMarkerViewContent" + } +} \ No newline at end of file diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXVectorSource.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXVectorSource.kt index 4b8ed3bf7..66280ed35 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXVectorSource.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXVectorSource.kt @@ -23,7 +23,7 @@ class RNMBXVectorSource(context: Context?, private val mManager: RNMBXVectorSour } override fun hasNoDataSoRefersToExisting(): Boolean { - return uRL == null; + return uRL == null && tileUrlTemplates == null; } override fun makeSource(): VectorSource { diff --git a/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/Annotation.kt b/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/Annotation.kt index a58a1244e..431e9ab46 100644 --- a/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/Annotation.kt +++ b/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/Annotation.kt @@ -4,6 +4,7 @@ import android.view.View import com.mapbox.geojson.Geometry import com.mapbox.geojson.Point import com.mapbox.maps.ScreenCoordinate +import com.mapbox.maps.ViewAnnotationAnchor import com.mapbox.maps.ViewAnnotationAnchorConfig import com.mapbox.maps.ViewAnnotationOptions import com.mapbox.maps.viewannotation.geometry as _geometry @@ -22,7 +23,7 @@ fun ViewAnnotationOptions.Builder.geometry(point: Geometry): ViewAnnotationOptio fun ViewAnnotationOptions.Builder.offsets(x: Double, y: Double) { this.variableAnchors(listOf( - ViewAnnotationAnchorConfig.Builder().offsetY(x).offsetY(y).build() + ViewAnnotationAnchorConfig.Builder().anchor(ViewAnnotationAnchor.CENTER).offsetY(x).offsetY(y).build() )) } diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMarkerViewContentManagerDelegate.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMarkerViewContentManagerDelegate.java new file mode 100644 index 000000000..9f88fceb1 --- /dev/null +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMarkerViewContentManagerDelegate.java @@ -0,0 +1,25 @@ +/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.BaseViewManagerInterface; + +public class RNMBXMarkerViewContentManagerDelegate & RNMBXMarkerViewContentManagerInterface> extends BaseViewManagerDelegate { + public RNMBXMarkerViewContentManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + super.setProperty(view, propName, value); + } +} diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMarkerViewContentManagerInterface.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMarkerViewContentManagerInterface.java new file mode 100644 index 000000000..1cf255d30 --- /dev/null +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMarkerViewContentManagerInterface.java @@ -0,0 +1,16 @@ +/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; + +public interface RNMBXMarkerViewContentManagerInterface { + // No props +} diff --git a/ios/RNMBX/RNMBXMarkerViewContentComponentView.h b/ios/RNMBX/RNMBXMarkerViewContentComponentView.h new file mode 100644 index 000000000..6cfb4734f --- /dev/null +++ b/ios/RNMBX/RNMBXMarkerViewContentComponentView.h @@ -0,0 +1,15 @@ +#ifdef RCT_NEW_ARCH_ENABLED + +#import + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RNMBXMarkerViewContentComponentView : RCTViewComponentView +@end + +NS_ASSUME_NONNULL_END + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/RNMBX/RNMBXMarkerViewContentComponentView.mm b/ios/RNMBX/RNMBXMarkerViewContentComponentView.mm new file mode 100644 index 000000000..047eb7bbd --- /dev/null +++ b/ios/RNMBX/RNMBXMarkerViewContentComponentView.mm @@ -0,0 +1,41 @@ +#ifdef RCT_NEW_ARCH_ENABLED + +#import "RNMBXMarkerViewContentComponentView.h" +#import "RNMBXFabricHelpers.h" + +#import +#import + +#import +#import +#import +#import + +using namespace facebook::react; + +@interface RNMBXMarkerViewContentComponentView () +@end + +@implementation RNMBXMarkerViewContentComponentView { +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + return [super initWithFrame:frame]; +} + +#pragma mark - RCTComponentViewProtocol + ++ (ComponentDescriptorProvider)componentDescriptorProvider +{ + return concreteComponentDescriptorProvider(); +} + +@end + +Class RNMBXMarkerViewContentCls(void) +{ + return RNMBXMarkerViewContentComponentView.class; +} + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/ios/RNMBX/RNMBXMarkerViewContentManager.m b/ios/RNMBX/RNMBXMarkerViewContentManager.m new file mode 100644 index 000000000..72f992879 --- /dev/null +++ b/ios/RNMBX/RNMBXMarkerViewContentManager.m @@ -0,0 +1,6 @@ +#import "React/RCTBridgeModule.h" +#import +#import + +@interface RCT_EXTERN_REMAP_MODULE(RNMBXMarkerViewContent, RNMBXMarkerViewContentManager, RCTViewManager) +@end diff --git a/ios/RNMBX/RNMBXMarkerViewContentManager.swift b/ios/RNMBX/RNMBXMarkerViewContentManager.swift new file mode 100644 index 000000000..9fb101b76 --- /dev/null +++ b/ios/RNMBX/RNMBXMarkerViewContentManager.swift @@ -0,0 +1,14 @@ +import Foundation +import MapboxMaps + +@objc(RNMBXMarkerViewContentManager) +class RNMBXMarkerViewContentManager : RCTViewManager { + @objc + override static func requiresMainQueueSetup() -> Bool { + return true + } + + override func view() -> UIView! { + return UIView() + } +} diff --git a/src/components/MarkerView.tsx b/src/components/MarkerView.tsx index 56a72bb06..d6c62aa73 100644 --- a/src/components/MarkerView.tsx +++ b/src/components/MarkerView.tsx @@ -1,17 +1,16 @@ import React from 'react'; -import { Platform, NativeModules, type ViewProps, View } from 'react-native'; +import { Platform, NativeModules, type ViewProps } from 'react-native'; import { toJSONString } from '../utils'; import { makePoint } from '../utils/geoUtils'; import { type Position } from '../types/Position'; import NativeMarkerViewComponent from '../specs/RNMBXMarkerViewNativeComponent'; +import RNMBXMakerViewContentCoponent from '../specs/RNMBXMarkerViewContentNativeComponent'; import PointAnnotation from './PointAnnotation'; const Mapbox = NativeModules.RNMBXModule; -export const NATIVE_MODULE_NAME = 'RNMBXMarkerView'; - type Props = ViewProps & { /** * The center point (specified as a map coordinate) of the marker. @@ -118,7 +117,7 @@ class MarkerView extends React.PureComponent { e.stopPropagation(); }} > - { return true; @@ -128,7 +127,7 @@ class MarkerView extends React.PureComponent { }} > {this.props.children} - + ); } diff --git a/src/specs/RNMBXMarkerViewContentNativeComponent.ts b/src/specs/RNMBXMarkerViewContentNativeComponent.ts new file mode 100644 index 000000000..f640d903a --- /dev/null +++ b/src/specs/RNMBXMarkerViewContentNativeComponent.ts @@ -0,0 +1,9 @@ +import type { HostComponent, ViewProps } from 'react-native'; +import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface NativeProps extends ViewProps {} + +export default codegenNativeComponent( + 'RNMBXMarkerViewContent', +) as HostComponent;