question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot call map method (showAttribution) - gives this._runNativeCommand is not a function

See original GitHub issue

Describe the bug

Cannot run showAttribution method on the map ref in a functional component. May also apply to other methods.

import React, { useRef } from 'react';
import { TouchableOpacity } from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';

export default function Map(p) {
    const mapRef = useRef()
    
    return (
        <TouchableOpacity onPress={mapRef?.current?.showAttribution}>
            <MapboxGL.MapView 
                ref={mapRef}
                attributionEnabled={false}
            />
        </TouchableOpacity>
    )
}

Expected behavior
Opens attribution menu, as when you click the default ‘i’.

Actual behavior
Gives the following error:

this._runNativeCommand is not a function. (In 'this._runNativeCommand('showAttribution', this._nativeRef)', 'this._runNativeCommand' is undefined)

Versions (please complete the following information):

  • Platform: Android
  • Platform OS: Android 8
  • Device: Pixel 2
  • Emulator/ Simulator: Yes
  • Dev OS: Win10 Professional
  • react-native-mapbox-gl Version: 8.2.0
  • Mapbox GL version: default
  • React Native Version: 0.64.0

Update

I’ve created a fresh React Native project (latest at 0.64.2) using the latest master from this package. I’m still experiencing issues with refs, where the ref is not populated.

react-native init MapTest npm i -S https://github.com/react-native-mapbox-gl/maps

app.js:

import React, {useRef} from 'react';
import type {Node} from 'react';
import Mapbox from '@react-native-mapbox-gl/maps';
import {View} from 'react-native';

Mapbox.setAccessToken(
  'pk.xxx'
);

const App: () => Node = () => {
  const mapRef = useRef();

  console.log('mapRef =', mapRef);
  
  return (
    <View style={{flex: 1}}>
      <Mapbox.MapView ref={mapRef} style={{width: '100%', height: '100%'}} />
    </View>
  );
};

export default App;

The map loads, but mapRef = {"current": undefined} is logged and no methods are accessible.

Interestly, if you hit CTRL+S on App.js, this causes the app to fast refresh and then mapRef.current methods become available. But they aren’t available during normal use of the app.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Kailo-Bcommented, Aug 17, 2022

I am still getting this exact issue, has any solution been found?

0reactions
sweycommented, Nov 6, 2022

@ferdicus There is a difference in the mapbox v10 implementation - the showAttribution method is missing in the View Manager.

https://github.com/rnmapbox/maps/blob/main/ios/RCTMGL-v10/RCTMGLMapViewManager.m vs. https://github.com/rnmapbox/maps/blob/main/ios/RCTMGL/RCTMGLMapViewManager.m#L292

But it looks like that even in the old implementation the referenced view is missing the method as well. So no idea why it worked in the old mapbox version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot call map method (showAttribution) - gives this ... - GitHub
Describe the bug Cannot run showAttribution method on the map ref in a functional component. ... _runNativeCommand is not a function #1409.
Read more >
How To Fix object.map is not a function Error in JavaScript
The Problem. The cause of your error is actually quite simple: the .map() method is only applicable when working with arrays. More specifically, ......
Read more >
Javascript .map() is not a function - Stack Overflow
Since it is sufficiently array-like, you can apply the map method from a real array. var text_content = [].map.call( document.
Read more >
How to map Object in Js, React Native, React ... - YouTube
Object. map is not a function || How to map Object in Js, React Native, React || Map Large arrays. Watch later. Share....
Read more >
Controls | Maps JavaScript API - Google Developers
This property disables any UI control buttons from the Maps JavaScript API. It does not, however, affect mouse gestures or keyboard shortcuts on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found