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

flyTo() with unchanged parameters only works once on iOS with new Architecture #571

Open
KiwiKilian opened this issue Dec 20, 2024 · 3 comments

Comments

@KiwiKilian
Copy link
Collaborator

Initially reported in: #517

import {
  Camera,
  type CameraRef,
  MapView,
} from "@maplibre/maplibre-react-native";
import { createRef } from "react";
import { Pressable, Text } from "react-native";

import { sheet } from "../styles/sheet";

export function BugReport() {
  const cameraRef = createRef<CameraRef>();

  return (
    <>
      <Pressable
        onPress={() => {
          cameraRef.current?.flyTo([10, 10]);
        }}
      >
        <Text>Fly to</Text>
      </Pressable>
      <MapView style={sheet.matchParent}>
        <Camera ref={cameraRef} />
      </MapView>
    </>
  );
}

With this example it's only broken on iOS with the new architecture.

@brentforder
Copy link

In my app, I've been working around issues with flyTo() for a while. Earlier in Alpha, this method wasn't working at all on Android (before New Arch was an option) for some time.
Instead of calling flyTo(), I am updating Camera's centerCoordinate property, with the animationMode property set to 'flyTo'. This seems to work pretty well, but I would love to untie this workaround and use flyTo() if it gets fixed up.
I can confirm that this workaround executes as expected, X number of times per runtime, on both Android & iOS with or without RN New Arch, on beta 13.

@KiwiKilian KiwiKilian changed the title flyTo() only works once on iOS with new Architecture flyTo() with unchanged parameters only works once on iOS with new Architecture Dec 27, 2024
@KiwiKilian
Copy link
Collaborator Author

Please clarify, AFAIK flyTo on Beta 15 works fine, except for this specific case:

Calling repeatedly with the same parameters on iOS with the new architecture enabled.

Can you reproduce for other combinations?

In my testing setNativeProps only triggers the native setters on iOS and new arch, if the parameters changed from the previous call of setNativeProps. A workaround could be to add a timestamp to the makeNativeCameraStop, but I'm not sure which implications this could have to other use cases.

Usage of setNativeProps is discouraged and this bug basically shows, how the Camera is still flawed. Using setNativeProps brings the props from JS and Native out of sync. I guess setNativeProps calls should be replaced by proper, imperative, native methods. But I'm still new to the native side of this library and not yet 100% sure how to solve this.

@brentforder
Copy link

brentforder commented Dec 28, 2024

@KiwiKilian I don't know what's happening under the hood, but I'm not calling setNativeProps directly. My workaround is using the Camera's exposed and documented centerCoordinate, animationMode, and animationDuration properties to do the exact effect that flyTo() is supposed to.

<Camera
    animationMode={'flyTo'}
    animationDuration={250}
    centerCoordinate={mapCenterOverride}
/>

...where mapCenterOverride is a state variable updated by state hooks (my business logic managers) whenever I need a flyTo() effect.

It works repeatedly like this, with either the same or different coordinates. Whatever Camera.flyTo() is doing has led to multiple issues historically, and just isn't as robust as updating the centerCoordinate property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants