Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: NewArch Exception in HostFunction: no non-static method updateCameraStop #3537

Closed
IASV opened this issue Jun 19, 2024 · 1 comment
Closed
Labels
bug 🪲 Something isn't working

Comments

@IASV
Copy link

IASV commented Jun 19, 2024

Mapbox Implementation

Mapbox

Mapbox Version

10.1.27

React Native Version

0.74.2

Platform

Android

@rnmapbox/maps version

10.1.27

Standalone component to reproduce

import React, { useRef, useEffect } from 'react';
import { Camera } from '@rnmapbox/maps';

const CENTER_COORDINATE = [-70.60133170151073, -33.48883453771556]
const ZOOM_LEVEL = 18.149781801261174

const BugReportExample = () => {
  const camera = useRef<Camera>(null);

  useEffect(() => {
    if (camera.current) {
      camera.current.setCamera({
        centerCoordinate: CENTER_COORDINATE,
        zoomLevel: ZOOM_LEVEL
      });
    }
  }, []);

  return <Camera ref={camera} />;
};

export default BugReportExample;

Observed behavior and steps to reproduce

Error

Error: Exception in HostFunction: no non-static method "Lcom/rnmapbox/rnmbx/components/camera/RNMBXCameraModule;.updateCameraStop(Ljava/lang/Double;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V"

When the new architecture is activated, it starts giving the error, once it is deactivated, the error disappears.

camera.current.setCamera(...) //error
camera.current.flyTo(...) //error
camera.current.zoomTo(...) //error

node_moduels -> CameraModule.kt

import com.rnmapbox.rnmbx.utils.ViewRefTag
//more imports...

class RNMBXCameraModule(context: ReactApplicationContext, val viewTagResolver: ViewTagResolver) : NativeRNMBXCameraModuleSpec(context) {
    private fun withViewportOnUIThread(
        viewRef: ViewRefTag?,
        reject: Promise,
        fn: (RNMBXCamera) -> Unit
    ) {
        if (viewRef == null) {
            reject.reject(Exception("viewRef is null"))
        } else {
            viewTagResolver.withViewResolved(viewRef.toInt(), reject, fn)
        }
    }

    private fun createCommandResponse(promise: Promise): CommandResponse = object : CommandResponse {
        override fun success(builder: (WritableMap) -> Unit) {
            val payload: WritableMap = WritableNativeMap()
            builder(payload)

            promise.resolve(payload)
        }

        override fun error(message: String) {
            promise.reject(Exception(message))
        }
    }

    companion object {
      const val NAME = "RNMBXCameraModule"
    }

    override fun updateCameraStop(viewRef: ViewRefTag?, stop: ReadableMap, promise: Promise) {
        withViewportOnUIThread(viewRef, promise) {
            it.updateCameraStop(stop)
            promise.resolve(null)
        }
    }
}

node_moduels -> NativeRNMBXCameraModule.ts

import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
import { TurboModuleRegistry } from 'react-native';

type ViewRef = Int32 | null;

interface NativeCameraStop {
  centerCoordinate?: string;
  bounds?: string;
  heading?: number;
  pitch?: number;
  zoom?: number;
  paddingLeft?: number;
  paddingRight?: number;
  paddingTop?: number;
  paddingBottom?: number;
  duration?: number;
  mode?: NativeAnimationMode;
}

type Stop =
  | {
      stops: NativeCameraStop[];
    }
  | NativeCameraStop;

type NativeAnimationMode = 'flight' | 'ease' | 'linear' | 'none' | 'move';

// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-unused-vars
type ObjectOr<T> = Object;

export interface Spec extends TurboModule {
  updateCameraStop(viewRef: ViewRef, stop: ObjectOr<Stop>): Promise<void>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNMBXCameraModule');

Expected behavior

No response

Notes / preliminary analysis

No response

Additional links and references

image

@IASV IASV added the bug 🪲 Something isn't working label Jun 19, 2024
@mfazekas
Copy link
Contributor

mfazekas commented Jun 20, 2024

@IASV duplicate of #3522

It's a bug in react-native 0.74.2, see my comment at #3522. As a workaround you can use patch-packages to fix the issue in react-native, see my last comment in #3522

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants