Skip to content

feat: add location distance filtering to useLocation hook and impleme… - #69

Merged
cybermax4200 merged 21 commits into
ecotask-network:mainfrom
ABEEGOLD:hook—permission-handling
Aug 24, 2026

Hidden character warning

The head ref may contain hidden characters: "hook\u2014permission-handling"
Merged

feat: add location distance filtering to useLocation hook and impleme…#69
cybermax4200 merged 21 commits into
ecotask-network:mainfrom
ABEEGOLD:hook—permission-handling

Conversation

@ABEEGOLD

Copy link
Copy Markdown
Contributor

Closes #67

Implement useLocation hook and comprehensive test suite

Description

This PR implements the full functionality for the useLocation hook and adds a comprehensive test suite to ensure its reliability.

Specifically, the following changes were made:

  • Continuous Location Tracking: Updated the hook to use Geolocation.watchPosition instead of getCurrentPosition for continuous location updates.
  • Haversine Distance Filter: Added a custom filter using haversineDistance to only update the state when the user has moved 50 meters (0.05 km) or more from their last recorded position.
  • Robust Permission Handling: Implemented robust permission handling on Android (PermissionsAndroid), while gracefully skipping it on iOS where it is not required.
  • Cleanup Logic: Ensured that Geolocation.clearWatch is called properly when the hook unmounts to prevent memory leaks and zombie listeners.
  • Test Suite: Added 13 extensive test cases in src/__tests__/useLocation.test.tsx checking all aspects of permission granting/denial, watch start, distance filtering, and cleanup.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that breaks existing functionality)
  • Documentation update
  • Chore (deps, tooling, refactoring)

How Has This Been Tested?

  • Unit tests added / updated
  • Integration tests added / updated
  • Manual testing on Android
  • Manual testing on iOS

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • I have commented on complex or non-obvious code
  • I have updated the documentation where needed
  • My changes generate no new warnings or lint errors
  • All existing and new tests pass

Screenshots

N/A

Additional Context

The hook previously only implemented a single getCurrentPosition fetch upon mounting and lacked the necessary background watch or filtering. The tests take full advantage of Jest mocks to simulate various OS platforms and location events cleanly without depending on the device environment.

@cybermax4200 cybermax4200 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ci checks are failing, please kindly fix them

@ABEEGOLD
ABEEGOLD force-pushed the hook—permission-handling branch from 495ddc1 to 8bcc4d5 Compare August 19, 2026 13:17
@ABEEGOLD
ABEEGOLD force-pushed the hook—permission-handling branch from 478542d to 2e0f86c Compare August 19, 2026 13:25
@ABEEGOLD

Copy link
Copy Markdown
Contributor Author

@cybermax4200 All checks passed.

@cybermax4200
cybermax4200 merged commit c464736 into ecotask-network:main Aug 24, 2026
4 checks passed
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.

[Testing] Zero test coverage for useLocation hook — permission handling and Haversine filtering

2 participants