react-native-nitro-compass 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +381 -163
  2. package/android/src/main/java/com/margelo/nitro/nitrocompass/HybridNitroCompass.kt +654 -133
  3. package/ios/HybridNitroCompass.swift +106 -3
  4. package/lib/commonjs/hook.js +98 -11
  5. package/lib/commonjs/hook.js.map +1 -1
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/multiplex.js +23 -2
  8. package/lib/commonjs/multiplex.js.map +1 -1
  9. package/lib/module/hook.js +99 -12
  10. package/lib/module/hook.js.map +1 -1
  11. package/lib/module/index.js.map +1 -1
  12. package/lib/module/multiplex.js +23 -2
  13. package/lib/module/multiplex.js.map +1 -1
  14. package/lib/typescript/src/hook.d.ts +39 -1
  15. package/lib/typescript/src/hook.d.ts.map +1 -1
  16. package/lib/typescript/src/index.d.ts +2 -2
  17. package/lib/typescript/src/index.d.ts.map +1 -1
  18. package/lib/typescript/src/multiplex.d.ts.map +1 -1
  19. package/lib/typescript/src/specs/NitroCompass.nitro.d.ts +142 -18
  20. package/lib/typescript/src/specs/NitroCompass.nitro.d.ts.map +1 -1
  21. package/nitrogen/generated/android/c++/JCompassSample.hpp +7 -3
  22. package/nitrogen/generated/android/c++/JDebugInfo.hpp +85 -0
  23. package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.cpp +17 -0
  24. package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.hpp +3 -0
  25. package/nitrogen/generated/android/c++/JSensorKind.hpp +6 -3
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/CompassSample.kt +9 -4
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/DebugInfo.kt +86 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/HybridNitroCompassSpec.kt +12 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/SensorKind.kt +4 -3
  30. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Bridge.hpp +12 -0
  31. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Umbrella.hpp +3 -0
  32. package/nitrogen/generated/ios/c++/HybridNitroCompassSpecSwift.hpp +23 -0
  33. package/nitrogen/generated/ios/swift/CompassSample.swift +7 -2
  34. package/nitrogen/generated/ios/swift/DebugInfo.swift +64 -0
  35. package/nitrogen/generated/ios/swift/HybridNitroCompassSpec.swift +3 -0
  36. package/nitrogen/generated/ios/swift/HybridNitroCompassSpec_cxx.swift +34 -0
  37. package/nitrogen/generated/ios/swift/SensorKind.swift +8 -4
  38. package/nitrogen/generated/shared/c++/CompassSample.hpp +6 -2
  39. package/nitrogen/generated/shared/c++/DebugInfo.hpp +111 -0
  40. package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.cpp +3 -0
  41. package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.hpp +6 -0
  42. package/nitrogen/generated/shared/c++/SensorKind.hpp +10 -6
  43. package/package.json +2 -2
  44. package/src/hook.ts +146 -12
  45. package/src/index.ts +2 -0
  46. package/src/multiplex.ts +23 -2
  47. package/src/specs/NitroCompass.nitro.ts +147 -18
package/src/hook.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { useEffect, useRef, useState } from 'react'
1
+ import { useCallback, useEffect, useRef, useState } from 'react'
2
2
  import type {
3
3
  AccuracyQuality,
4
4
  CompassSample,
5
+ PermissionStatus,
5
6
  SensorDiagnostics,
6
7
  } from './specs/NitroCompass.nitro'
7
8
  import { NitroCompass } from './native'
@@ -60,6 +61,44 @@ export interface UseCompassResult {
60
61
  hasCompass: boolean
61
62
  /** Which sensor backs the readings on this device. */
62
63
  diagnostics: SensorDiagnostics | undefined
64
+ /**
65
+ * Latest platform permission status. Always `'granted'` on Android.
66
+ * On iOS may transition from `'unknown'` → `'granted'`/`'denied'`
67
+ * after `requestPermission()` resolves.
68
+ */
69
+ permission: PermissionStatus
70
+ /**
71
+ * Synchronous read of the most recent emitted sample (with declination
72
+ * already applied), or `undefined` if not started yet or no sample
73
+ * has arrived. Useful inside event handlers without re-rendering.
74
+ */
75
+ getCurrentHeading: () => CompassSample | undefined
76
+ /**
77
+ * Force a best-effort sensor recalibration. On Android this re-registers
78
+ * the sensor listeners (often nudges the magnetometer driver to
79
+ * re-evaluate calibration); on iOS it dismisses the heading-calibration
80
+ * overlay and stop/restarts heading updates.
81
+ */
82
+ recalibrate: () => void
83
+ /**
84
+ * Set the user's geographic location for a tighter interference gate.
85
+ * Android uses the WMM2025 model bundled in `GeomagneticField` to
86
+ * derive the expected field strength at the location; iOS is a no-op
87
+ * because `CLLocationManager` already uses GPS-derived location
88
+ * internally for all field-related reasoning. Pass `NaN` or
89
+ * out-of-range values to revert to the generic 20–70 µT band.
90
+ */
91
+ setLocation: (latitude: number, longitude: number) => void
92
+ /**
93
+ * Request the platform permission required to deliver headings.
94
+ * Android resolves immediately with `'granted'`. On iOS this prompts
95
+ * the system "Allow location" dialog if the status is `'unknown'`,
96
+ * resolving once the user makes a choice; subsequent calls resolve
97
+ * immediately with the cached status (iOS does not re-prompt). The
98
+ * hook's `permission` field updates automatically when the promise
99
+ * resolves.
100
+ */
101
+ requestPermission: () => Promise<PermissionStatus>
63
102
  }
64
103
 
65
104
  /**
@@ -84,14 +123,39 @@ export function useCompass(
84
123
  const [quality, setQuality] = useState<AccuracyQuality | null>(null)
85
124
  const [interfering, setInterfering] = useState(false)
86
125
 
87
- const [hasCompass] = useState(() => NitroCompass.hasCompass())
88
- const [diagnostics] = useState(() => NitroCompass.getDiagnostics())
126
+ // Wrap in try/catch so a missing/misconfigured native module doesn't
127
+ // throw during render return safe defaults and let the host UI
128
+ // surface "no compass". Without this, the throw bubbles up and
129
+ // becomes a render error that blanks the screen.
130
+ const [hasCompass] = useState(() => {
131
+ try {
132
+ return NitroCompass.hasCompass()
133
+ } catch {
134
+ return false
135
+ }
136
+ })
137
+ const [diagnostics] = useState(() => {
138
+ try {
139
+ return NitroCompass.getDiagnostics()
140
+ } catch {
141
+ return undefined
142
+ }
143
+ })
144
+ const [permission, setPermission] = useState<PermissionStatus>(() => {
145
+ try {
146
+ return NitroCompass.getPermissionStatus()
147
+ } catch {
148
+ return 'unknown'
149
+ }
150
+ })
89
151
 
90
- // Tracked via ref so the heading-subscription effect can re-apply
91
- // the user's filter after a stop/start cycle without restarting on
92
- // every filterDegrees change.
152
+ // Tracked via refs so the heading-subscription effect can re-apply
153
+ // the user's filter and smoothing after a stop/start cycle without
154
+ // restarting on every option change.
93
155
  const filterRef = useRef(filterDegrees)
94
156
  filterRef.current = filterDegrees
157
+ const smoothingRef = useRef(smoothingAlpha)
158
+ smoothingRef.current = smoothingAlpha
95
159
 
96
160
  useEffect(() => {
97
161
  NitroCompass.setFilter(filterDegrees)
@@ -120,14 +184,84 @@ export function useCompass(
120
184
  }, [hasCompass])
121
185
 
122
186
  useEffect(() => {
123
- if (!hasCompass || !enabled) return
124
- const off = addHeadingListener(setReading)
125
- // Multiplex starts the sensor with a default filter; re-apply the
126
- // current option after subscribing.
127
- NitroCompass.setFilter(filterRef.current)
187
+ if (!hasCompass || !enabled) {
188
+ // When the user disables the hook, clear stale UI state.
189
+ // Without this, `reading` / `interfering` keep their last value
190
+ // forever, so the consumer's UI can't tell "subscription is off"
191
+ // from "compass is currently quiet".
192
+ setReading(null)
193
+ setInterfering(false)
194
+ return
195
+ }
196
+ let off: (() => void) | undefined
197
+ try {
198
+ off = addHeadingListener(setReading)
199
+ // Multiplex starts the sensor with a default filter; re-apply
200
+ // the current options after subscribing. recalibrate() can also
201
+ // reset native smoothing state, so we pin our chosen alpha back
202
+ // here as well.
203
+ NitroCompass.setFilter(filterRef.current)
204
+ NitroCompass.setSmoothing(smoothingRef.current)
205
+ } catch (e) {
206
+ // start() throws on iOS when location authorization is denied.
207
+ // Swallow it here so the hook tree doesn't unmount; consumers
208
+ // should call NitroCompass.requestPermission() explicitly before
209
+ // setting enabled=true if they want to recover.
210
+ // eslint-disable-next-line no-console
211
+ console.warn('[NitroCompass] failed to start heading subscription:', e)
212
+ }
128
213
  return off
129
214
  // eslint-disable-next-line react-hooks/exhaustive-deps
130
215
  }, [hasCompass, enabled])
131
216
 
132
- return { reading, quality, interfering, hasCompass, diagnostics }
217
+ // Stable callbacks so consumers' useEffect deps don't churn on every
218
+ // render. All four are thin wrappers around NitroCompass; the hook's
219
+ // own state isn't reactive to recalibrate/setLocation since neither
220
+ // changes any field returned here.
221
+ const getCurrentHeading = useCallback(() => {
222
+ try {
223
+ return NitroCompass.getCurrentHeading()
224
+ } catch {
225
+ return undefined
226
+ }
227
+ }, [])
228
+
229
+ const recalibrate = useCallback(() => {
230
+ try {
231
+ NitroCompass.recalibrate()
232
+ } catch {
233
+ // Native missing — nothing to do.
234
+ }
235
+ }, [])
236
+
237
+ const setLocation = useCallback((latitude: number, longitude: number) => {
238
+ try {
239
+ NitroCompass.setLocation(latitude, longitude)
240
+ } catch {
241
+ // Native missing — silently ignored.
242
+ }
243
+ }, [])
244
+
245
+ const requestPermission = useCallback(async (): Promise<PermissionStatus> => {
246
+ try {
247
+ const status = await NitroCompass.requestPermission()
248
+ setPermission(status)
249
+ return status
250
+ } catch {
251
+ return 'denied'
252
+ }
253
+ }, [])
254
+
255
+ return {
256
+ reading,
257
+ quality,
258
+ interfering,
259
+ hasCompass,
260
+ diagnostics,
261
+ permission,
262
+ getCurrentHeading,
263
+ recalibrate,
264
+ setLocation,
265
+ requestPermission,
266
+ }
133
267
  }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type {
2
2
  AccuracyQuality,
3
3
  CompassSample,
4
+ DebugInfo,
4
5
  NitroCompass as NitroCompassSpec,
5
6
  PermissionStatus,
6
7
  SensorDiagnostics,
@@ -12,6 +13,7 @@ export { NitroCompass } from './native'
12
13
  export type {
13
14
  AccuracyQuality,
14
15
  CompassSample,
16
+ DebugInfo,
15
17
  PermissionStatus,
16
18
  SensorDiagnostics,
17
19
  SensorKind,
package/src/multiplex.ts CHANGED
@@ -82,6 +82,13 @@ export function addHeadingListener(cb: HeadingListener): () => void {
82
82
  }
83
83
  }
84
84
 
85
+ // Module-level no-op kept stable so we can swap it back into the native
86
+ // callback slot when the last listener leaves — releasing references
87
+ // to old dispatcher closures, which matters when the JS module is
88
+ // re-evaluated (Metro Fast Refresh, jest module reset).
89
+ const NOOP_CALIBRATION = (_: AccuracyQuality) => {}
90
+ const NOOP_INTERFERENCE = (_: boolean) => {}
91
+
85
92
  /**
86
93
  * Subscribe to calibration-bucket transitions. Only fires while a
87
94
  * heading subscription is active. Returns the unsubscribe function.
@@ -95,7 +102,17 @@ export function addCalibrationListener(
95
102
  }
96
103
  calibrationListeners.add(cb)
97
104
  return () => {
98
- calibrationListeners.delete(cb)
105
+ if (!calibrationListeners.delete(cb)) return
106
+ if (calibrationListeners.size === 0) {
107
+ // Detach our dispatcher from the native side. Without this, a
108
+ // module reload (Metro Fast Refresh, jest resetModules) leaves
109
+ // the old dispatcher pinned in native memory while a new module
110
+ // load installs a *second* dispatcher pointing at a fresh
111
+ // listener Set — splitting events between the two and silently
112
+ // dropping the now-orphaned listeners.
113
+ NitroCompass.setOnCalibrationNeeded(NOOP_CALIBRATION)
114
+ calibrationRegistered = false
115
+ }
99
116
  }
100
117
  }
101
118
 
@@ -112,6 +129,10 @@ export function addInterferenceListener(
112
129
  }
113
130
  interferenceListeners.add(cb)
114
131
  return () => {
115
- interferenceListeners.delete(cb)
132
+ if (!interferenceListeners.delete(cb)) return
133
+ if (interferenceListeners.size === 0) {
134
+ NitroCompass.setOnInterferenceDetected(NOOP_INTERFERENCE)
135
+ interferenceRegistered = false
136
+ }
116
137
  }
117
138
  }
@@ -2,7 +2,7 @@ import type { HybridObject } from 'react-native-nitro-modules'
2
2
 
3
3
  /**
4
4
  * One compass heading sample, delivered to the JS callback registered with
5
- * `start()`. Both fields are in degrees.
5
+ * `start()`. Angular fields are in degrees; field strength is in microtesla.
6
6
  *
7
7
  * - `heading`: heading clockwise from north, in `[0, 360)`. Magnetic by
8
8
  * default; if you call `setDeclination(deg)` the offset is applied
@@ -10,48 +10,131 @@ import type { HybridObject } from 'react-native-nitro-modules'
10
10
  * `getCurrentHeading()`).
11
11
  * - `accuracy`: estimated heading uncertainty in degrees, or `-1` when the
12
12
  * platform has not yet reported a usable accuracy. Smaller is better.
13
- * On Android this is read from `event.values[4]` of the rotation-vector
14
- * sensor when available, otherwise mapped from `SensorManager.SENSOR_STATUS_*`.
15
- * On iOS this is `CLHeading.headingAccuracy`.
13
+ * On Android, mapped from the magnetometer's `SENSOR_STATUS_*` accuracy
14
+ * bucket (the figure-8 calibration signal). On iOS this is
15
+ * `CLHeading.headingAccuracy`.
16
+ * - `fieldStrengthMicroTesla`: magnitude of the local magnetic field in
17
+ * microteslas (µT), or `-1` when no reading is available yet. Earth's
18
+ * field is normally 25–65 µT; values well outside this band signal
19
+ * external interference (laptops, monitors, magnets, metal). Useful
20
+ * for rendering a "strength" meter à la consumer compass apps.
16
21
  */
17
22
  export interface CompassSample {
18
23
  heading: number
19
24
  accuracy: number
25
+ fieldStrengthMicroTesla: number
20
26
  }
21
27
 
22
28
  /**
23
- * Coarse calibration bucket reported via `setOnCalibrationNeeded`. Buckets
24
- * are derived from numeric heading accuracy on both platforms (same
25
- * thresholds), so values agree across iOS and Android:
29
+ * Coarse calibration bucket reported via `setOnCalibrationNeeded`. The
30
+ * bucket is derived from a numeric heading-accuracy estimate on both
31
+ * platforms, but the thresholds differ because the underlying scales
32
+ * disagree:
26
33
  *
27
- * `<5°` `high`, `<15°` `medium`, `<30°` `low`, otherwise `unreliable`.
34
+ * - **Android** direct mapping from `SensorManager.SENSOR_STATUS_*`:
35
+ * `HIGH` → `high`, `MEDIUM` → `medium`, `LOW` → `low`,
36
+ * `UNRELIABLE`/`NO_CONTACT` → `unreliable`. The numeric `accuracy`
37
+ * field on `CompassSample` is a synthetic upper bound (`<5°`,
38
+ * `<15°`, `<30°`, `-1`).
39
+ * - **iOS** — bucketed from `CLHeading.headingAccuracy` (degrees) with
40
+ * relaxed thresholds because Apple's stack rarely reports under 5°
41
+ * even on a perfectly-calibrated compass:
42
+ * `<20°` → `high`, `<35°` → `medium`, `<55°` → `low`, otherwise
43
+ * `unreliable`. `unreliable` is also reported when iOS asks to
44
+ * display its built-in calibration UI (we suppress the system UI so
45
+ * you can render your own banner).
28
46
  *
29
- * On iOS `unreliable` is also reported when the system asks to display
30
- * its built-in calibration UI (we suppress it).
47
+ * The buckets are intended for UX ("show calibrate prompt") exact
48
+ * cross-platform parity isn't possible because the platforms emit
49
+ * different underlying signals.
31
50
  */
32
51
  export type AccuracyQuality = 'high' | 'medium' | 'low' | 'unreliable'
33
52
 
34
53
  /**
35
54
  * Identifies which underlying sensor / framework is producing headings.
36
55
  *
37
- * - `rotationVector` — Android `Sensor.TYPE_ROTATION_VECTOR` (gyro + accel
38
- * + magnetometer fused). Best quality.
39
- * - `geomagneticRotationVector` Android
40
- * `Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR` (accel + magnetometer only).
41
- * Used as fallback on gyroless / budget devices; lower update rate and
42
- * more susceptible to magnetic interference.
56
+ * - `magnetometer` — Android raw `TYPE_MAGNETIC_FIELD` + `TYPE_ACCELEROMETER`
57
+ * computed via `SensorManager.getRotationMatrix()` + `getOrientation()`.
58
+ * Stateless: snaps back instantly when external interference (magnets,
59
+ * electronics) is removed, instead of waiting for OS-level fusion to
60
+ * re-converge.
43
61
  * - `coreLocation` — iOS `CLLocationManager` heading. Apple's stack
44
62
  * handles fusion natively.
63
+ * - `rotationVector` / `geomagneticRotationVector` — legacy values kept
64
+ * in the union for source compatibility; no longer returned by current
65
+ * builds.
45
66
  */
46
67
  export type SensorKind =
68
+ | 'magnetometer'
69
+ | 'coreLocation'
47
70
  | 'rotationVector'
48
71
  | 'geomagneticRotationVector'
49
- | 'coreLocation'
50
72
 
51
73
  export interface SensorDiagnostics {
52
74
  sensor: SensorKind
53
75
  }
54
76
 
77
+ /**
78
+ * Live introspection of the native compass pipeline. Use for
79
+ * diagnosing user-reported issues (heading wrong, banner stuck,
80
+ * compass frozen) — none of these fields are needed for normal
81
+ * operation.
82
+ *
83
+ * Numeric fields use `-1` (or `NaN` for `fusedYawDeg`) as a
84
+ * "not-applicable / not-yet-available" sentinel; consumers should
85
+ * treat those as missing rather than literal values. Most fields
86
+ * are Android-only — iOS uses `CLLocationManager` and doesn't expose
87
+ * the underlying state, so the iOS implementation reports a minimal
88
+ * subset (`lastFieldMicroTesla`, `interferenceActive`).
89
+ */
90
+ export interface DebugInfo {
91
+ /**
92
+ * Whether the library currently considers external interference to
93
+ * be active. Driven by field-magnitude band checks AND (Android,
94
+ * uncalibrated mag only) recent OS hard-iron-bias jumps.
95
+ */
96
+ interferenceActive: boolean
97
+ /**
98
+ * Milliseconds since the most recent OS hard-iron bias jump on
99
+ * Android's uncalibrated magnetometer. `-1` if never seen.
100
+ * iOS / fallback path: always `-1`.
101
+ */
102
+ msSinceLastBiasJump: number
103
+ /**
104
+ * The expected magnetic field magnitude (µT) at the user's
105
+ * location, derived from `setLocation()`. Used to tighten the
106
+ * interference band. `-1` if `setLocation()` hasn't been called
107
+ * with valid coordinates.
108
+ */
109
+ expectedFieldMicroTesla: number
110
+ /**
111
+ * Most recent measured field magnitude (µT) — same value surfaced
112
+ * on `CompassSample.fieldStrengthMicroTesla`. `-1` if no reading.
113
+ */
114
+ lastFieldMicroTesla: number
115
+ /**
116
+ * Current value of the gyro-corrected fused yaw (deg, [0, 360)).
117
+ * `NaN` before any sample has been processed, or on iOS where
118
+ * gyro fusion is handled inside CLLocationManager.
119
+ */
120
+ fusedYawDeg: number
121
+ /**
122
+ * Latest yaw rate (deg/s) derived from game-rotation-vector
123
+ * deltas. Used to drive the adaptive input low-pass filter.
124
+ * `0` if game-RV is unavailable / hasn't fired yet.
125
+ */
126
+ lastYawRateDegPerS: number
127
+ /** Whether `TYPE_GAME_ROTATION_VECTOR` is currently producing events. Always `false` on iOS. */
128
+ hasGameRotationVector: boolean
129
+ /**
130
+ * Whether Android is sourcing magnetometer data from
131
+ * `TYPE_MAGNETIC_FIELD_UNCALIBRATED` (preferred — bias-jump
132
+ * detection works) vs. the `TYPE_MAGNETIC_FIELD` fallback. Always
133
+ * `false` on iOS.
134
+ */
135
+ usingUncalibratedMag: boolean
136
+ }
137
+
55
138
  /**
56
139
  * Platform permission state required to deliver headings.
57
140
  *
@@ -129,9 +212,17 @@ export interface NitroCompass extends HybridObject<{ ios: 'swift'; android: 'kot
129
212
  */
130
213
  getDiagnostics(): SensorDiagnostics | undefined
131
214
 
215
+ /**
216
+ * Snapshot of the internal compass pipeline. Only intended for
217
+ * diagnosing user-reported issues — see {@link DebugInfo} for
218
+ * field-by-field semantics. Cheap to call (no allocations beyond
219
+ * the returned object); poll at any rate the host UI prefers.
220
+ */
221
+ getDebugInfo(): DebugInfo
222
+
132
223
  /**
133
224
  * Whether the device has the hardware required for a compass reading.
134
- * Android: a rotation-vector sensor (fused or geomagnetic) is present.
225
+ * Android: both a magnetometer and an accelerometer are present.
135
226
  * iOS: `CLLocationManager.headingAvailable()`.
136
227
  */
137
228
  hasCompass(): boolean
@@ -151,6 +242,25 @@ export interface NitroCompass extends HybridObject<{ ios: 'swift'; android: 'kot
151
242
  */
152
243
  setDeclination(degrees: number): void
153
244
 
245
+ /**
246
+ * Set the user's geographic location for a tighter interference
247
+ * gate. With a valid location, the library replaces the generic
248
+ * 20–70 µT "Earth field band" with `expectedField ± 15 µT`, where
249
+ * `expectedField` comes from the WMM2025 model shipped on Android
250
+ * (`GeomagneticField`). This catches weak interference the generic
251
+ * band misses — especially at high/low latitudes where Earth's
252
+ * field is naturally near or above 60 µT.
253
+ *
254
+ * Pass `NaN` for either coordinate, or values outside the valid
255
+ * range (`|lat| > 90`, `|lon| > 180`), to revert to the generic
256
+ * band. Survives across `start`/`stop`.
257
+ *
258
+ * **No-op on iOS.** `CLLocationManager` uses GPS-derived location
259
+ * internally for all field-related reasoning; layering our own
260
+ * lookup on top would be redundant.
261
+ */
262
+ setLocation(latitude: number, longitude: number): void
263
+
154
264
  /**
155
265
  * Register a callback fired when the calibration bucket transitions.
156
266
  * Replaces any previously registered callback. Pass a no-op to mute.
@@ -191,6 +301,25 @@ export interface NitroCompass extends HybridObject<{ ios: 'swift'; android: 'kot
191
301
  */
192
302
  setPauseOnBackground(enabled: boolean): void
193
303
 
304
+ /**
305
+ * Force a best-effort sensor recalibration. Resets internal smoothing
306
+ * and quality-bucket state, then re-registers the underlying sensor
307
+ * listeners. On many Android OEMs the re-registration nudges the
308
+ * magnetometer driver to re-evaluate soft/hard-iron calibration, which
309
+ * unsticks an `UNRELIABLE` bucket that's lingering after a strong
310
+ * magnetic excursion (e.g. another phone placed on top, then removed).
311
+ *
312
+ * On iOS this dismisses the system heading-calibration overlay and
313
+ * stops/restarts heading updates. Apple's stack handles the
314
+ * underlying calibration internally.
315
+ *
316
+ * Idempotent — safe to call when not started, in which case it's a
317
+ * no-op. Calibration recovery still requires the user to move the
318
+ * device through varying orientations; this method just clears the
319
+ * library's cached state so progress is reflected promptly.
320
+ */
321
+ recalibrate(): void
322
+
194
323
  /**
195
324
  * Read the current platform permission state synchronously.
196
325
  * On Android this is always `'granted'` (sensors require no permission);