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

fix(ios): fix custom location provider add/remove #3416

Merged
merged 1 commit into from
Mar 10, 2024
Merged

Conversation

mfazekas
Copy link
Contributor

@mfazekas mfazekas commented Mar 9, 2024

Closes: #3411

Screen.Recording.2024-03-09.at.17.17.53.mov

Example:

import React, { useRef, useEffect } from 'react';
import { Switch, View, Text } from 'react-native';
import {
  MapView,
  Camera,
  CustomLocationProvider,
  LocationPuck,
  Viewport,
} from '@rnmapbox/maps';

export default function BugReportExample() {
  const [location, setLocation] = React.useState([-74.00597, 40.71427]);
  const [useCustomLocation, setUseCustomLocation] = React.useState(false);
  useEffect(() => {
    const interval = setInterval(() => {
      setLocation((location) => [location[0] + 0.0001, location[1] + 0.0001]);
    }, 500);
    return () => clearInterval(interval);
  }, []);
  const viewportRef = useRef();

  return (
    <>
      <View style={{ flexDirection: 'row', alignItems: 'center' }}>
        <Text>Emulate Location</Text>
        <Switch
          value={useCustomLocation}
          onChange={() => setUseCustomLocation(!useCustomLocation)}
        />
      </View>

      <MapView
        style={{ flex: 1 }}
        onDidFinishLoadingStyle={() => {
          viewportRef.current.transitionTo(
            { kind: 'followPuck', zoom: 16 },
            { kind: 'default' },
          );
        }}
      >
        <Camera
          defaultSettings={{
            centerCoordinate: [-74.00597, 40.71427],
            zoomLevel: 14,
          }}
          followZoomLevel={14}
          followUserLocation={true}
        />
        <Viewport ref={viewportRef} />
        {useCustomLocation && <CustomLocationProvider coordinate={location} />}
        <LocationPuck visible={true} />
      </MapView>
    </>
  );
}

@mfazekas mfazekas mentioned this pull request Mar 9, 2024
8 tasks
@mfazekas mfazekas merged commit 3437362 into main Mar 10, 2024
10 checks passed
@mfazekas mfazekas deleted the fix-custom-location branch March 10, 2024 07:59
@mfazekas mfazekas changed the title fix(ios): fix custome location provider add/remove fix(ios): fix custom location provider add/remove Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant