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 map marker has bad performance #476

Closed
RyanTG opened this issue Nov 12, 2022 · 4 comments
Closed

Android custom map marker has bad performance #476

RyanTG opened this issue Nov 12, 2022 · 4 comments

Comments

@RyanTG
Copy link
Collaborator

RyanTG commented Nov 12, 2022

Right now we're using default markers on Android, since the custom ones we've tried really hurt performance. With the latest version 1.x of react-native-maps, this still seems to be the case. There have been various issues over the years about this, but no clear indication that it's been fixed. Recent one react-native-maps/react-native-maps#4161 (not entirely sure if that's our issue)

This person claims they solved it: https://dev.to/ajmal_hasan/react-native-map-optimisation-59na
But I haven't dug deep into that post. Almost seems like their solution is to merely add trackViewChanges={false} for Android, which is certainly something I've already tried.

Official docs: https://github.com/react-native-maps/react-native-maps#rendering-a-marker-with-a-custom-image
say that using <Image ...> is better than . I've tried both. But perhaps I didn't do it perfectly?

Another general note is that Expo Go performance is, overall, worse than using actual builds. That's because Expo Go is doing a bunch of bug monitoring and stuff. So sometimes you need actual builds to see true performance. But I'm sure that usage through Expo Go would give us an idea if some solution is working.

@RyanTG RyanTG added the 5.2.13 label Nov 22, 2022
@RyanTG
Copy link
Collaborator Author

RyanTG commented Nov 24, 2022

Update to this is that adding trackViewChanges={false} to the marker has helped a lot (I was previously adding it to the mapview, which was wrong).

There still seems to be an issue where the hearts don’t always render. Some have noted that you should track changes while the markers are loading then change to false after they’ve loaded. I’ll edit this comment later with the examples of that that I found.

@RyanTG
Copy link
Collaborator Author

RyanTG commented Nov 29, 2022

The recommended use of tracksViewChanges is to enable when the marker
is being rendered or animated, then to disable it.

An example of use of tracksViewChanges would be to set it to false once
onMapReady has fired. This can be accomplished by toggling a state
property (e.g. initialized), and passing it to the child map markers
in their tracksViewChanges prop. Markers would then render correctly
on map load; CPU use falls off once the tracking ceases.

react-native-maps/react-native-maps#1705 (comment)

If you are loading an image inside the marker, you could start with tracksViewChanges={true}, listen to the load even on your image, and then change it to false.

Others use a timeout of like .4 seconds and then set it to false when the pins are first loading. Seems sketchy, though.

react-native-maps/react-native-maps#2082

@RyanTG RyanTG added 5.2.14 and removed 5.2.13 labels Dec 6, 2022
@RyanTG RyanTG added 5.2.15 and removed 5.2.14 labels Jan 4, 2023
@RyanTG RyanTG added 5.2.18 and removed 5.2.16 labels Jan 17, 2023
@chanphiromsok
Copy link

I got a slow marker in android too but here is my solution set trackViewsChange={false} on Marker then call redraw
below are the example you can render with your own coordinate and check condition before rendering those marker in your own

Example for clusterMarker

const markerList = [1, 2, 3, 4, 5, 6];

const Cluster = () => {
    const markersRef = React.useRef({}) as MutableRefObject<{
        [MarkerIdentifier: string]: Marker;
    }>;
    return (
        <>
            {markerList.map(marker => {
                return (
                    <Marker
                        coordinate={{ latitude: 1, longitude: 1 }}
                        ref={ref => {
                            if (ref) markersRef.current[`${marker}`] = ref;
                        }}
                    >
                        <Image
                            source={{ uri: 'image' }}
                            style={{ width: 36, height: 36 }}
                            onLoad={() => {
                                markersRef.current[`${marker}`]?.redraw();
                            }}
                        />
                    </Marker>
                );
            })}
        </>
    );
};

Exmaple Single Marker

const CustomMarker = () => {
    const markersRef = React.useRef({}) as MutableRefObject<Marker>;
    return (
        <Marker
            coordinate={{ latitude: 1, longitude: 1 }}
            ref={ref => {
                if (ref) markersRef.current = ref;
            }}
        >
            <Image
                source={{ uri: 'image' }}
                style={{ width: 36, height: 36 }}
                onLoad={() => {
                    markersRef.current?.redraw();
                }}
            />
        </Marker>
    );
};

@RyanTG RyanTG added 5.2.19 and removed 5.2.18 labels Feb 3, 2023
@RyanTG RyanTG added 5.2.20 and removed 5.2.19 labels Mar 9, 2023
@RyanTG RyanTG removed the 5.2.20 label May 5, 2023
@RyanTG
Copy link
Collaborator Author

RyanTG commented Jul 21, 2023

Resolved via switching to rnmapbox
#498

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