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

Add static geolocation #317

Merged
merged 17 commits into from
Jun 10, 2024
Merged

Add static geolocation #317

merged 17 commits into from
Jun 10, 2024

Conversation

filip131311
Copy link
Collaborator

@filip131311 filip131311 commented May 28, 2024

This PR adds an ability to set static device location.

added functionality:

  • setting location
  • enable/disable location services
  • coordinates validation
Screen.Recording.2024-06-06.at.16.02.55.mov
Screen.Recording.2024-06-06.at.16.05.48.mov

Fixes: #330

Copy link

vercel bot commented May 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2024 11:52am

Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this over call but posting high level comments such that they don't get lost:

  1. let's accept single line input for coords and allow different formatting (use some js libfor parsing). It is convinient to be able to paste the coords from somewhere instead of interacting with four separate controls
  2. don't put form controls below "save" button, the enable/disable switch should be first actually
  3. we don't need save, let's just save on change assuming the provided coords are valid

Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving some minor comments in code to fix before merging

@@ -27,3 +27,25 @@ export function throttle<T extends (...args: any[]) => any>(
recentArgs = args;
} as T;
}

export function throttleWithTrailing<T extends (...args: any[]) => any>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this different than "throttle"? Maybe add some comment here? Also from reading the code it appears like you can actually use the existing method, no?

Comment on lines +94 to +110
if (settings.location.isDisabled) {
await exec("xcrun", [
"simctl",
"--set",
deviceSetLocation,
"location",
this.deviceUDID,
"clear",
]);
} else {
await exec("xcrun", [
"simctl",
"--set",
deviceSetLocation,
"location",
this.deviceUDID,
"set",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

await exec("xcrun", [
         "simctl",
         "--set",
         deviceSetLocation,
         "location",
         this.deviceUDID,
         settings.location.isDisabled ? "clear" : "set",
       ]);

Comment on lines +68 to +69
latitude: 50.048653,
longitude: 19.965474,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't block on this but I still think we shouldn't default to any location.

text-align: center;
height: 42px;
align-self: right;
/* margin-left: 5px; */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out.

const { project, deviceSettings } = useProject();
const inputRef = useRef<HTMLInputElement>(null);

const updateProjectSettingWithThrottle = throttleWithTrailing(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use blur events instead of throttling change events?

Comment on lines +74 to +78
const convertDDToDMS = (D: number, lng: boolean) => {
return {
dir: D < 0 ? (lng ? "W" : "S") : lng ? "E" : "N",
deg: 0 | (D < 0 ? (D = -D) : D),
min: String(0 | (((D += 1e-9) % 1) * 60)).padStart(2, "0"),
sec: String(Math.floor((0 | (((D * 60) % 1) * 6000)) / 100)).padStart(2, "0"),
};
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you drop a comment what DD and DMS is? Assuming the code is copied from somewhere, would be nice to have a source URL.

<label className="latitude">
<div className="picker">
<input
ref={inputRef}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it isn't easier to make it controlled input.

Comment on lines +53 to +59
try {
position = new CoordinateParser(newCoordinate);
setIsCoordinateValid(true);
} catch (e) {
setIsCoordinateValid(false);
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't particularly like it. What do you think about some small helper function to return lat, long?

If it returns nice error, we can also try to pass it to user.

function parseCoords(raw: string) {
  try {
    const { getLatitude, getLongitude } = new CoordinateParser(newCoordinate);
    return { latitude: getLatitude(), longitude: getLongitude() };
  } catch (_e) {}
  return undefined;
}

@filip131311 filip131311 dismissed stale reviews from kacperkapusciak and jakub-gonet June 10, 2024 10:15

gg

@filip131311 filip131311 merged commit 71ec697 into main Jun 10, 2024
3 checks passed
@filip131311 filip131311 deleted the @Filip131311/AddLocation branch June 10, 2024 12:27
kmagiera added a commit that referenced this pull request Jun 10, 2024
In #317 new fields have been added to device settings. However, since we
persist device settings, the changes are not compatible with the old
data that might've been stored there. To prevent this we are adding a
versioning of device settings key (will increment version with future
changes).

This PR also changes the defaults to use disabled location, especially
that we need to have some coordinates specified, it'd be weird to have
everyone using IDE pointing to the same geo location.
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.

can't use gps sensor in android emulator
4 participants