maps icon indicating copy to clipboard operation
maps copied to clipboard

not convert return expression of type '[UIView : ViewAnnotationOptions]' to return type 'Dictionary<String, Optional<JSONValue>>.RawValue' (aka 'Dictionary<String, Optional<Any>>')

Open matiastang opened this issue 11 months ago • 7 comments

Environment

  • Dev OS: [e.g. OSX 15.1.1]
  • Xcode: [Version 16.2 ]
  • @rnmapbox/maps version: [eg. 10.1.33]
  • React Native version: [eg. 0.76.3]
  • Expo version: [eg. 52.0.7]

Steps to reproduce

If the build in Xcode or Expo fails and shows the following error: Cannot convert return expression of type '[UIView : ViewAnnotationOptions]' to return type 'Dictionary<String, Optional<JSONValue>>.RawValue' (aka 'Dictionary<String, Optional<Any>>')

The error originates from lines 76-82 in the Pods->MapboxMaps->ViewAnnotationManager file.

/// The complete list of annotations associated with the receiver.
@available(*, deprecated, message: "Use ViewAnnotation")
public var annotations: [UIView: ViewAnnotationOptions] {
    idsByView.compactMapValues { [mapboxMap] id in
        try? mapboxMap.options(forViewAnnotationWithId: id)
    }
}

It’s just a type error, and I bypassed this error using the following method.

/// The complete list of annotations associated with the receiver.
@available(*, deprecated, message: "Use ViewAnnotation")
public var annotations: [UIView: ViewAnnotationOptions] {
    return [:]
}

The annotations property has been deprecated, which might be an issue with the mapbox-gl version.

matiastang avatar Jan 13 '25 08:01 matiastang

facing the same problem using rn 0.76.6

bypassing by using the code from mapbox-maps-ios

    /// The complete list of annotations associated with the receiver.
    @available(*, deprecated, message: "Use ViewAnnotation")
    public var annotations: [UIView: ViewAnnotationOptions] {
        let values = idsByView.compactMapValues { [mapboxMap] id in
            try? mapboxMap.options(forViewAnnotationWithId: id)
        }
        return values
    }

Roshdy avatar Jan 13 '25 20:01 Roshdy

Would you please add more details how to apply the correction, assuming Expo configs?

estoilkov avatar Jan 29 '25 11:01 estoilkov

you can add a postinstall hook to your podfile @estoilkov

installer.pods_project.targets.each do |target|
     if target.name == 'MapboxMaps'
       file_path = 'Pods/MapboxMaps/Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift'
       
       file_content = File.read(file_path)
       
       if file_content.include?('idsByView.compactMapValues { [mapboxMap] id in')
         new_content = file_content.gsub(
           /public var annotations: \[UIView: ViewAnnotationOptions\] \{\n\s+idsByView\.compactMapValues \{ \[mapboxMap\] id in\n\s+try\? mapboxMap\.options\(forViewAnnotationWithId: id\)\n\s+\}\n\s+\}/,
           "public var annotations: [UIView: ViewAnnotationOptions] {\n let values = idsByView.compactMapValues { [mapboxMap] id in\n try? mapboxMap.options(forViewAnnotationWithId: id)\n }\n return values\n }")
         
         File.write(file_path, new_content)
         puts "Fixed ViewAnnotationManager.swift in MapboxMaps pod"
       end
     end
   end

deepnothing avatar Mar 03 '25 20:03 deepnothing

Encountering the same issue with non-expo react native, with rnmapbox/maps 10.1.37

Regarding the postinstall hook, this resulted in a permissions issue for me:

[!] An error occurred while processing the post-install hook of the Podfile.

Permission denied @ rb_sysopen - Pods/MapboxMaps/Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift

Sounds like I'd have to manually change permissions on this file to get the hook to work properly..

SethArchambault avatar Mar 13 '25 20:03 SethArchambault

I am encountering this issue when building using Expo's eas build.

Image

dev-alto avatar Mar 19 '25 06:03 dev-alto

Environment

  • Dev OS: [e.g. OSX 15.1.1]
  • Xcode: [Version 16.2 ]
  • @rnmapbox/maps version: [eg. 10.1.33]
  • React Native version: [eg. 0.76.3]
  • Expo version: [eg. 52.0.7]

Steps to reproduce

If the build in Xcode or Expo fails and shows the following error: Cannot convert return expression of type '[UIView : ViewAnnotationOptions]' to return type 'Dictionary<String, Optional>.RawValue' (aka 'Dictionary<String, Optional>')

The error originates from lines 76-82 in the Pods->MapboxMaps->ViewAnnotationManager file.

/// The complete list of annotations associated with the receiver. @available(*, deprecated, message: "Use ViewAnnotation") public var annotations: [UIView: ViewAnnotationOptions] { idsByView.compactMapValues { [mapboxMap] id in try? mapboxMap.options(forViewAnnotationWithId: id) } } It’s just a type error, and I bypassed this error using the following method.

/// The complete list of annotations associated with the receiver. @available(*, deprecated, message: "Use ViewAnnotation") public var annotations: [UIView: ViewAnnotationOptions] { return [:] } The annotations property has been deprecated, which might be an issue with the mapbox-gl version.

Could you tell us more about how you implemented this fix? How did you apply it? Did you build locally? How did you get EAS to make these changes? }

gabrielroodriz avatar Apr 27 '25 12:04 gabrielroodriz

Implemented solution

I resolved this through the approach:

  1. Updated the Mapbox SDK version in app.config.js:
// app.config.js
[
  "@rnmapbox/maps",
  {
    RNMapboxMapsImpl: "mapbox",
    RNMapboxMapsVersion: "11.8.0", // Updated from 11.4.0
    RNMapboxMapsDownloadToken: process.env.MAPBOX_DOWNLOAD_TOKEN,
  },
],

gabrielroodriz avatar Apr 29 '25 16:04 gabrielroodriz

Implemented solution

I resolved this through the approach:

  1. Updated the Mapbox SDK version in app.config.js:

// app.config.js [ "@rnmapbox/maps", { RNMapboxMapsImpl: "mapbox", RNMapboxMapsVersion: "11.8.0", // Updated from 11.4.0 RNMapboxMapsDownloadToken: process.env.MAPBOX_DOWNLOAD_TOKEN, }, ],

Where is place of this file app.config.js?

szymonWCa avatar Jul 10 '25 16:07 szymonWCa

Where is place of this file app.config.js?

Yes, In plugin key

batazo avatar Oct 15 '25 11:10 batazo

Should be fixed by recent MapboxMaps version

mfazekas avatar Oct 16 '25 14:10 mfazekas