Search code examples
react-nativeexporeact-native-maps

React Native Maps what is the tracksViewChanges prop in the <Marker> component exactly for?


I am in expo 50 using react-native-maps version 1.13.0, so i am facing the same flickering issue explained here 4997 when rendering custom markers. When i set trackViewChanges={false} in the Marker it solves the issue and the map is also drastically more performant. For more information about my custom markers they render a jpg or png image inside of them and have like a custom badge that changes its label dynamically on top of them.

my concrete questions:

  • What does trackViewChanges exactly affect/do for a given Marker component?

  • When should it be definitely turned on and when off?

  • Would it not be better to just turn it off by default and and use the redraw() method each marker provides when the marker really needs to move/change or be re rendered? this is also stated in the docs for trackViewsChanges.

I hope anyone with more deeper understanding of how this all works can answer


Solution

  • To address each of your inquiries regarding flickering, let's take them one at a time and discuss them individually.

    Question 1: What does trackViewChanges exactly affect/do for a given Marker component?

    tracksViewChanges controls whether the Marker's view is continuously refreshed. When it's set to true, the Marker's content is always updated, which can be useful for dynamic changes like animations. Setting it to false stops the Marker from continuously refreshing, which can boost performance, especially for static content.

    Question 2: When should it be definitely turned on and when off?

    Turn it on: When you need the Marker to show dynamic changes like animations or label updates. Turn it off: When the Marker's content doesn't change often or after an initial update, to improve performance and prevent flickering.

    Question 3: Would it not be better to just turn it off by default and and use the redraw() method each marker provides when the marker really needs to move/change or be re rendered? this is also stated in the docs for trackViewsChanges.

    Yes, it's often better to turn tracksViewChanges off by default and manually trigger updates using redraw() when needed. This helps optimize performance by reducing unnecessary updates and improving map responsiveness.