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

Android custom Markers with children content have sporadic flashing/glitches (see example video) #4988

Open
trooperandz opened this issue Feb 27, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@trooperandz
Copy link

trooperandz commented Feb 27, 2024

Summary

Beginning with react-native-maps version 1.9.0, map Markers composed of children content (described in the documentation as Children Content) are showing sporadic flashes/glitching on Android. This does not occur with versions 1.8.4 and below.

In this particular case, the Markers are being rendered from an iterable list via map, and they are of SVG format. The particular screen in question is only rendering one time (there are not multiple renders taking place).

The newest versions of react-native-maps were tried as well, with the same flashing occurring (1.10.0, 1.10.3).

Reproducible sample code

import * as React from 'react';
import { View } from 'react-native';
import MapView, { Marker } from 'react-native-maps';
import PinIcon from 'assets/icon-pin.svg';

<MapView>
  {markers.map((marker) => {
    return (
      <Marker
        identifier={`id-${marker.id}`}
        key={`key-id-${marker.id}`}
      >
        <View style={styles.pin}>
          <PinIcon
            fill={color}
            height={imageDimensions}
            width={imageDimensions}
          />
        </View>
      </Marker>
    );
  })}
</MapView>

const styles = StyleSheet.create({
  pin: {
    backgroundColor: 'rgba(0,0,0,0.1)',
    borderRadius: 13,
    height: 25,
    width: 25,
  },
})

Steps to reproduce

Create a map, and render a MapView which includes Markers with children content rendered from an iterable list. Observe the flashing/glitching of the markers.

Expected result

Expect no flashing/glitches in the Marker content to occur.

Actual result

See the flashing/glitches below:

marker-glitch.mp4

React Native Maps Version

1.9.0

What platforms are you seeing the problem on?

Android

React Native Version

0.73.4

What version of Expo are you using?

Not using Expo

Device(s)

Samsung Galaxy S21 (Android 13)

Additional information

No response

@trooperandz trooperandz added the bug Something isn't working label Feb 27, 2024
@pauladapptor
Copy link

Ran into a similar issue, if you remove the image as a child and set it as a prop, this should solve the flickering. Below is just some sudo code of your example, you may have to tweak it for your asset.

<MapView>
  {markers.map((marker) => {
    return (
      <Marker
        identifier={`id-${marker.id}`}
        key={`key-id-${marker.id}`} 
        image={PinIcon}/>
    );
  })}
</MapView>

@Jin-seop
Copy link

Jin-seop commented Feb 28, 2024

The problem is that the trackViewChanges function doesn't work properly.

const [tracksView, setTracksView] = useState(true); //add 

useEffect(() => { //add
  if(Platform.OS === 'android'){
    setTimeout(()=>{
      setTracksView(false);
    },100)
  }
},[])

<MapView>
  {markers.map((marker) => {
    return (
      <Marker
        identifier={`id-${marker.id}`}
        key={`key-id-${marker.id}`}
        tracksViewChanges={tracksView} //add
      >
        <View style={styles.pin}>
          <PinIcon
            fill={color}
            height={imageDimensions}
            width={imageDimensions}
          />
        </View>
      </Marker>
    );
  })}
</MapView>

@chanphiromsok
Copy link

try to custom marker and set trackView to false

import React, { ReactNode, useEffect, useState } from 'react';
import { StyleProp, ViewStyle } from 'react-native';
import { Marker, MarkerAnimated, MapMarkerProps } from 'react-native-maps';

interface Props extends MapMarkerProps {
  animate?: boolean;
  children: ReactNode;
  renderChangeTime?: number;
  style?: StyleProp<ViewStyle>;
}
export default function OptimizedMarker({
  animate = false,
  children,
  renderChangeTime = 2000,
  ...props
}: Props) {
  const [tracksViewChanges, setViewChanges] = useState(true);

  useEffect(() => {
    let timerId:NodeJS.Timeout

    if (tracksViewChanges) {
      timerId = setTimeout(() => {
        setViewChanges(false);
      }, renderChangeTime);
    }

    return () => {
      clearTimeout(timerId);
    };
  }, []);

  if (animate) {
    return (
      <MarkerAnimated {...props} tracksViewChanges={tracksViewChanges}>
        {children}
      </MarkerAnimated>
    );
  }

  return (
    <Marker tracksViewChanges={tracksViewChanges} {...props}>
      {children}
    </Marker>
  );
}

and try use png instead of svg

@andresvega-sourcetoad
Copy link

andresvega-sourcetoad commented Mar 12, 2024

The issue ocurss when updated to 1.10.3 and the same behavior on 1.11.3 trackViewChanges on false doesn't solve the problem for me.

@jeffinhk
Copy link

The issue ocurss when updated to 1.10.3 and the same behavior on 1.11.3 trackViewChanges on false doesn't solve the problem for me.

In my case trackViewChanges on false solves the issue temporarily but instead stops the Marker to render when entering the app after closing. So now the custom marker performance is either flickering or not render at all

@salah-ghanim
Copy link
Collaborator

@jeffinhk in our application the usage of onMapReady on android solves the issue ...

@trooperandz have you tried using both onMapReady and tracksViewChanges to be false, it should solve the problem completely

@nahuelprinsich
Copy link

I'm facing the same issue. If I Take the last advice using tracksViewChanges with onMapReady the flickering stops but some markers get stuck with an image from another marker.
Also tried another advices but nothing seems to work, for example use googleRender='LEGACY' or use a timer to set tracksViewChanges to false after a second.

@trooperandz
Copy link
Author

trooperandz commented May 13, 2024

@jeffinhk in our application the usage of onMapReady on android solves the issue ...

@trooperandz have you tried using both onMapReady and tracksViewChanges to be false, it should solve the problem completely

@salah-ghanim yes I tried both of these approaches; I need tracksViewChanges to be true, because my pins react to presses (change to larger pins to show that they have been pressed by the user. Setting this to false breaks the UI updates).

@nahuelprinsich
Copy link

I fixed the problem using googleRenderer={'LEGACY'}

@trooperandz
Copy link
Author

trooperandz commented May 14, 2024

I fixed the problem using googleRenderer={'LEGACY'}

@nahuelprinsich interesting; this does not fix it for me unfortunately. Same results as before.

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

8 participants