Skip to content

Commit 8961d95

Browse files
release - v0.3.0 (#12)
* chore: reorganizing docs (#1) * Feature - Core Hooks + Tests (#2) * feat: creation of core hooks + update docs * feat: tests added * chore: increasing percentage of test coverage * docs: update changelog with testing and hooks implementation * Feature - Setup CI/CD (#3) * feat: creating develop and main flows * feat: adding documentation of CICD and project structure * Feature - Live Location Updates (#6) * feat: adding new native logic and react hooks for live location updates * fix(tests): small fix on lint of setup-minimal.ts * chore(docs): updating docs + increasing project version * chore: updating README.md * feat: adding tests to useLocationUpdates hook * Fix - Fix Live update locations (#7) * fix: fixing tracking of locations, adding interval to get information * chore: just adjusting css of example App * chore(docs): updating docs * chore - Incrementing Workflows (#8) * chore(workflows): updating workflows to allows coverage and badges * chore(docs): updating docs * chore(docs): updating docs (#9) * chore - update workflows (#10) * chore(workflows): updating workflows to allows coverage and badges * chore(docs): updating docs * chore(workflow): updating workflow adding test info * chore - sponsor documentation (#11) * chore(docs): updating docs * chore(docs): updating docs
1 parent b326040 commit 8961d95

28 files changed

+2198
-149
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ jobs:
4646
- name: Run unit tests
4747
run: yarn test --maxWorkers=2 --coverage
4848

49+
- name: Upload coverage reports to Codecov
50+
uses: codecov/codecov-action@v5
51+
with:
52+
token: ${{ secrets.CODECOV_TOKEN }}
53+
file: ./coverage/lcov.info
54+
flags: unittests
55+
fail_ci_if_error: false
56+
4957
build-library:
5058
runs-on: ubuntu-latest
5159

.github/workflows/prerelease.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
permissions:
1717
contents: write
1818
id-token: write
19+
issues: write
20+
pull-requests: write
1921

2022
steps:
2123
- name: Checkout
@@ -57,7 +59,48 @@ jobs:
5759
run: yarn prepare
5860

5961
- name: Run tests
60-
run: yarn test --maxWorkers=2
62+
run: yarn test --coverage --maxWorkers=2
63+
64+
- name: Upload coverage artifact
65+
if: always()
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: coverage-prerelease
69+
path: |
70+
coverage/**
71+
if-no-files-found: warn
72+
73+
- name: Upload coverage reports to Codecov
74+
if: always()
75+
uses: codecov/codecov-action@v5
76+
with:
77+
token: ${{ secrets.CODECOV_TOKEN }}
78+
file: ./coverage/lcov.info
79+
flags: prerelease
80+
fail_ci_if_error: false
81+
82+
- name: Publish coverage summary
83+
if: always()
84+
run: |
85+
if [ -f coverage/coverage-summary.json ]; then
86+
echo "### Test Coverage" >> $GITHUB_STEP_SUMMARY
87+
node -e '
88+
const fs = require("fs");
89+
const s = JSON.parse(fs.readFileSync("coverage/coverage-summary.json", "utf8"));
90+
const t = s.total;
91+
const row = (k,v)=>`| ${k} | ${v.pct}% | ${v.covered}/${v.total} |`;
92+
console.log("| Metric | % | Covered/Total |\n|---|---:|---:|\n" +
93+
[
94+
row("Statements", t.statements),
95+
row("Branches", t.branches),
96+
row("Functions", t.functions),
97+
row("Lines", t.lines)
98+
].join("\n")
99+
);
100+
' >> $GITHUB_STEP_SUMMARY
101+
else
102+
echo "No coverage summary found." >> $GITHUB_STEP_SUMMARY
103+
fi
61104
62105
- name: Publish to NPM (beta tag)
63106
run: |

.github/workflows/publish.yml

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
permissions:
1717
contents: write
1818
id-token: write
19+
issues: write
20+
pull-requests: write
1921

2022
steps:
2123
- name: Checkout
@@ -61,7 +63,48 @@ jobs:
6163

6264
- name: Run tests
6365
if: steps.version-check.outputs.version_changed == 'true'
64-
run: yarn test --maxWorkers=2
66+
run: yarn test --coverage --maxWorkers=2
67+
68+
- name: Upload coverage artifact
69+
if: always()
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: coverage-release
73+
path: |
74+
coverage/**
75+
if-no-files-found: warn
76+
77+
- name: Upload coverage reports to Codecov
78+
if: always()
79+
uses: codecov/codecov-action@v5
80+
with:
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
file: ./coverage/lcov.info
83+
flags: release
84+
fail_ci_if_error: false
85+
86+
- name: Publish coverage summary
87+
if: always()
88+
run: |
89+
if [ -f coverage/coverage-summary.json ]; then
90+
echo "### Test Coverage" >> $GITHUB_STEP_SUMMARY
91+
node -e '
92+
const fs = require("fs");
93+
const s = JSON.parse(fs.readFileSync("coverage/coverage-summary.json", "utf8"));
94+
const t = s.total;
95+
const row = (k,v)=>`| ${k} | ${v.pct}% | ${v.covered}/${v.total} |`;
96+
console.log("| Metric | % | Covered/Total |\n|---|---:|---:|\n" +
97+
[
98+
row("Statements", t.statements),
99+
row("Branches", t.branches),
100+
row("Functions", t.functions),
101+
row("Lines", t.lines)
102+
].join("\n")
103+
);
104+
' >> $GITHUB_STEP_SUMMARY
105+
else
106+
echo "No coverage summary found." >> $GITHUB_STEP_SUMMARY
107+
fi
65108
66109
- name: Publish to NPM
67110
if: steps.version-check.outputs.version_changed == 'true'
@@ -123,3 +166,43 @@ jobs:
123166
prerelease: false
124167
});
125168
169+
- name: Comment on related PRs
170+
if: steps.version-check.outputs.version_changed == 'true'
171+
uses: actions/github-script@v7
172+
with:
173+
github-token: ${{ secrets.GITHUB_TOKEN }}
174+
script: |
175+
const version = require('./package.json').version;
176+
// Find PRs that were just merged into main
177+
const { data: prs } = await github.rest.pulls.list({
178+
owner: context.repo.owner,
179+
repo: context.repo.repo,
180+
state: 'closed',
181+
base: 'main',
182+
sort: 'updated',
183+
direction: 'desc',
184+
per_page: 5
185+
});
186+
187+
const recentlyMergedPRs = prs.filter(pr => {
188+
const mergedAt = new Date(pr.merged_at);
189+
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
190+
return pr.merged_at && mergedAt > fiveMinutesAgo;
191+
});
192+
193+
for (const pr of recentlyMergedPRs) {
194+
await github.rest.issues.createComment({
195+
owner: context.repo.owner,
196+
repo: context.repo.repo,
197+
issue_number: pr.number,
198+
body: `🎉 A release has been published: **v${version}**\n\n` +
199+
`Install with:\n` +
200+
"```bash\n" +
201+
`npm install @gabriel-sisjr/react-native-background-location@${version}\n` +
202+
`# or\n` +
203+
`yarn add @gabriel-sisjr/react-native-background-location@${version}\n` +
204+
"```\n\n" +
205+
`This version includes your changes and is available for installation!`
206+
});
207+
}
208+

CHANGELOG.md

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,126 @@ Starting with 0.2.0, the project follows a two-branch strategy:
142142
- **`main`**: Production-ready releases (stable versions)
143143
- **`develop`**: Latest development code (beta releases available via `npm install @gabriel-sisjr/react-native-background-location@beta`)
144144

145+
## [0.3.0] - 2025-01-26
146+
147+
### Added
148+
149+
- 🎯 **Real-time Location Updates**: New `useLocationUpdates` hook for automatic location watching
150+
- Real-time event-driven location updates via native events
151+
- Automatic subscription to `onLocationUpdate` events from Android background service
152+
- Access to last location received in real-time
153+
- Optional filtering by specific tripId
154+
- Callback support for each new location
155+
- Automatic loading of existing locations on mount
156+
- Complete TypeScript support with full type definitions
157+
- Automatic cleanup of event listeners on unmount
158+
- Graceful handling when native module unavailable
159+
160+
- 📡 **Android Event System**: Native event emission infrastructure
161+
- LocationService emits `onLocationUpdate` events via DeviceEventManagerModule
162+
- Events sent whenever new GPS location is collected
163+
- Non-blocking async event emission
164+
- Context-aware event system with React Native bridge
165+
166+
- 📚 **Enhanced Documentation**:
167+
- Complete real-time updates guide in `docs/getting-started/REAL_TIME_UPDATES.md`
168+
- Usage examples demonstrating manual vs automatic modes
169+
- Best practices for combining hooks
170+
- FAQ section with common questions
171+
- Updated example app with toggle for manual/automatic modes
172+
173+
- 🎨 **Improved Example App**:
174+
- Added toggle switch to demonstrate manual vs automatic update modes
175+
- Real-time visualization of last location
176+
- Visual indicators for active mode
177+
- Conditional UI elements based on update mode
178+
179+
### API Additions
180+
181+
**New Hook**: `useLocationUpdates`
182+
```typescript
183+
const {
184+
locations, // Real-time array of all locations
185+
lastLocation, // Most recent location received
186+
isTracking, // Tracking status
187+
tripId, // Current trip ID
188+
isLoading, // Loading state
189+
error, // Error state
190+
clearError // Clear error function
191+
} = useLocationUpdates({
192+
tripId?: string, // Filter by tripId
193+
onLocationUpdate?: (location) => void, // Callback per location
194+
autoLoad?: boolean // Load existing locations
195+
});
196+
```
197+
198+
### Changed
199+
200+
- 📦 **Version Bump**: Updated to 0.3.0 following semantic versioning (minor release for new features)
201+
- 🔄 **Event System**: Android LocationService now emits native events for real-time updates
202+
- 📱 **Module Integration**: BackgroundLocationModule now provides ReactContext to LocationService
203+
204+
### Technical Details
205+
206+
**File Changes:**
207+
- `android/src/main/java/com/backgroundlocation/LocationService.kt`: Added event emission
208+
- `android/src/main/java/com/backgroundlocation/BackgroundLocationModule.kt`: Added context setup
209+
- `src/hooks/useLocationUpdates.ts`: New hook for real-time updates
210+
- `src/types.ts`: Added `LocationUpdateEvent`, `UseLocationUpdatesOptions`, `UseLocationUpdatesResult`
211+
- `src/hooks/index.ts`: Exported new hook and types
212+
- `src/index.tsx`: Exported new hook and types
213+
- `example/src/App.tsx`: Enhanced with toggle demonstration
214+
215+
**Architecture:**
216+
- Event-driven updates (no polling required)
217+
- Non-blocking event emission
218+
- Automatic subscription/unsubscription
219+
- Memory efficient with minimal overhead
220+
- Compatible with existing imperative API
221+
222+
### Migration Guide
223+
224+
If upgrading from 0.2.0:
225+
226+
**No Breaking Changes** - All existing APIs remain fully supported.
227+
228+
**New Feature - Real-time Updates:**
229+
230+
```typescript
231+
// Option 1: Manual refresh (existing)
232+
import { useBackgroundLocation } from '@gabriel-sisjr/react-native-background-location';
233+
const { locations, refreshLocations } = useBackgroundLocation();
234+
// ... call refreshLocations() periodically
235+
236+
// Option 2: Automatic updates (NEW)
237+
import { useLocationUpdates } from '@gabriel-sisjr/react-native-background-location';
238+
const { locations } = useLocationUpdates();
239+
// ... locations update automatically in real-time
240+
241+
// Option 3: Combine both (recommended)
242+
const control = useBackgroundLocation(); // For start/stop
243+
const updates = useLocationUpdates(); // For real-time data
244+
```
245+
246+
### Requirements
247+
248+
- React Native 0.70 or higher
249+
- Android API 21+ (Android 5.0 Lollipop)
250+
- Google Play Services Location 21.3.0
251+
252+
### Known Limitations
253+
254+
- iOS event emitters not yet implemented (iOS support planned)
255+
- Events only processed when app is in foreground
256+
- Real-time updates currently Android-only
257+
145258
## [Unreleased]
146259

147260
### Planned
148261

149262
- iOS implementation with Swift
263+
- iOS event emitter support
150264
- Customizable location update intervals
151-
- Event emitters for real-time updates
152265
- Geofencing support
153266
- Distance filtering
154267
- SQLite storage option for large datasets

0 commit comments

Comments
 (0)