@blife/rn-step-counter 1.0.0
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.
- package/LICENSE +21 -0
- package/README.kr.md +159 -0
- package/README.md +158 -0
- package/StepCounter.podspec +22 -0
- package/android/README.md +65 -0
- package/android/build.gradle +66 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/java/com/stepcounter/StepCounterModule.kt +190 -0
- package/android/src/main/java/com/stepcounter/StepCounterPackage.kt +53 -0
- package/android/src/main/java/com/stepcounter/services/AccelerometerService.kt +147 -0
- package/android/src/main/java/com/stepcounter/services/SensorListenService.kt +305 -0
- package/android/src/main/java/com/stepcounter/services/StepCounterService.kt +79 -0
- package/android/src/main/java/com/stepcounter/utils/AndroidVersionHelper.kt +33 -0
- package/android/src/main/java/com/stepcounter/utils/SensorFusionMath.kt +104 -0
- package/ios/SOMotionDetecter.h +44 -0
- package/ios/SOMotionDetecter.m +91 -0
- package/ios/StepCounter.h +7 -0
- package/ios/StepCounter.mm +264 -0
- package/lib/module/NativeStepCounter.js +21 -0
- package/lib/module/NativeStepCounter.js.map +1 -0
- package/lib/module/index.js +194 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/jest.setup.d.ts +2 -0
- package/lib/typescript/jest.setup.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeStepCounter.d.ts +60 -0
- package/lib/typescript/src/NativeStepCounter.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +80 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +138 -0
- package/src/NativeStepCounter.ts +62 -0
- package/src/index.tsx +263 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import StepCounterModule, { eventName, NAME, VERSION } from "./NativeStepCounter.js";
|
|
4
|
+
import { NativeEventEmitter, Platform } from "react-native";
|
|
5
|
+
import pkg from "../package.json";
|
|
6
|
+
function repositoryWebUrl() {
|
|
7
|
+
const url = pkg.repository.url;
|
|
8
|
+
return url.replace(/^git\+/, "").replace(/\.git$/, "");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* A way to check if the module is linked. */
|
|
12
|
+
const LINKING_ERROR = `The package '${pkg.name}' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
|
|
13
|
+
ios: "- You have run `pod install` in the `ios` directory and then clean, rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.\n",
|
|
14
|
+
android: "- You have the Android development environment set up: `https://reactnative.dev/docs/environment-setup.`",
|
|
15
|
+
default: ""
|
|
16
|
+
}) + '- Use the "npx react-native clean" command to clean up the module\'s cache and select the ' + '"watchman", "metro", "android", "npm" (and your package manager) options with comma-separated. ' + "Re-install packages and re-build the app again.\n" + "- You rebuilt the app after installing the package\n" + "- You are not using Expo Go\n" + `If none of these fix the issue, please open an issue on the package repository: ${repositoryWebUrl()}`;
|
|
17
|
+
/**
|
|
18
|
+
* A module that allows you to get the step count data.
|
|
19
|
+
* `CMStepCounter` is deprecated in iOS 8.0. Used `CMPedometer` instead.
|
|
20
|
+
* floorsAscended - The number of floors ascended during the time period. iOS Only.
|
|
21
|
+
* floorsDescended - The number of floors descended during the time period. iOS Only.
|
|
22
|
+
* counterType - The type of counter used to count the steps.
|
|
23
|
+
* @throws {Error} LINKING_ERROR - Throws Error If global variable turboModuleProxy is undefined.
|
|
24
|
+
* @example
|
|
25
|
+
* import { StepCounter } from '@bonnmh/rn-step-counter';
|
|
26
|
+
*/
|
|
27
|
+
const StepCounter = StepCounterModule ? StepCounterModule : new Proxy({}, {
|
|
28
|
+
get() {
|
|
29
|
+
throw new Error(LINKING_ERROR);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const StepEventEmitter = new NativeEventEmitter(StepCounter);
|
|
33
|
+
const DEFAULT_MINIMUM_STEP_INTERVAL_MS = 250;
|
|
34
|
+
|
|
35
|
+
// Tracks the subscription created by the most recent startStepCounterUpdate call.
|
|
36
|
+
// Only this subscription is removed in stopStepCounterUpdate, so that external
|
|
37
|
+
// subscribers (e.g. debug log components) are not unintentionally removed.
|
|
38
|
+
let _activeSubscription = null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Transform the step count data into a more readable format.
|
|
42
|
+
* You can use it or directly use the `StepCountData` type.
|
|
43
|
+
* @param {StepCountData} data - Step Counter Sensor Event Data.
|
|
44
|
+
* @returns {ParsedStepCountData} - String Parsed Count Data.
|
|
45
|
+
*/
|
|
46
|
+
export function parseStepData(data) {
|
|
47
|
+
const {
|
|
48
|
+
steps,
|
|
49
|
+
startDate,
|
|
50
|
+
endDate,
|
|
51
|
+
distance
|
|
52
|
+
} = data;
|
|
53
|
+
const dailyGoal = 10000;
|
|
54
|
+
const stepsString = steps + " steps";
|
|
55
|
+
const kCal = (steps * 0.045).toFixed(2) + "kCal";
|
|
56
|
+
const endDateTime = new Date(endDate).toLocaleTimeString("en-gb");
|
|
57
|
+
const startDateTime = new Date(startDate).toLocaleTimeString("en-gb");
|
|
58
|
+
const roundedDistance = distance.toFixed(1) + "m";
|
|
59
|
+
const stepGoalStatus = steps >= dailyGoal ? "Goal Reached" : `${steps}/${dailyGoal} steps`;
|
|
60
|
+
return {
|
|
61
|
+
dailyGoal: stepGoalStatus,
|
|
62
|
+
steps,
|
|
63
|
+
stepsString,
|
|
64
|
+
calories: kCal,
|
|
65
|
+
startDate: startDateTime,
|
|
66
|
+
endDate: endDateTime,
|
|
67
|
+
distance: roundedDistance
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Create a stateful filter for live step-count updates.
|
|
73
|
+
*
|
|
74
|
+
* Native pedometer APIs can already include device/OS false positives, and the
|
|
75
|
+
* Android accelerometer fallback can also react to quick hand rotation. This
|
|
76
|
+
* helper drops updates that imply an impossible cadence and rebases later
|
|
77
|
+
* cumulative values so ignored burst steps do not come back on the next event.
|
|
78
|
+
*/
|
|
79
|
+
export function createStepCountFilter(options = {}) {
|
|
80
|
+
const minimumStepIntervalMs = options.minimumStepIntervalMs && options.minimumStepIntervalMs > 0 ? options.minimumStepIntervalMs : DEFAULT_MINIMUM_STEP_INTERVAL_MS;
|
|
81
|
+
let previousRawData = null;
|
|
82
|
+
let ignoredSteps = 0;
|
|
83
|
+
let ignoredDistance = 0;
|
|
84
|
+
return data => {
|
|
85
|
+
if (!Number.isFinite(data.steps) || data.steps < 0) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (previousRawData && data.steps < previousRawData.steps) {
|
|
89
|
+
previousRawData = data;
|
|
90
|
+
ignoredSteps = 0;
|
|
91
|
+
ignoredDistance = 0;
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
const referenceTime = previousRawData ? previousRawData.endDate : data.startDate;
|
|
95
|
+
const stepDelta = previousRawData ? data.steps - previousRawData.steps : data.steps;
|
|
96
|
+
const distanceDelta = previousRawData ? data.distance - previousRawData.distance : data.distance;
|
|
97
|
+
const elapsedMs = Number.isFinite(data.endDate) && Number.isFinite(referenceTime) ? data.endDate - referenceTime : Number.POSITIVE_INFINITY;
|
|
98
|
+
const isSuspiciousBurst = stepDelta > 0 && elapsedMs >= 0 && elapsedMs < stepDelta * minimumStepIntervalMs;
|
|
99
|
+
previousRawData = data;
|
|
100
|
+
if (isSuspiciousBurst) {
|
|
101
|
+
ignoredSteps += stepDelta;
|
|
102
|
+
if (distanceDelta > 0) {
|
|
103
|
+
ignoredDistance += distanceDelta;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
if (ignoredSteps === 0 && ignoredDistance === 0) {
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...data,
|
|
112
|
+
steps: Math.max(0, data.steps - ignoredSteps),
|
|
113
|
+
distance: Math.max(0, data.distance - ignoredDistance)
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* If you're using a method or property that's not available on the current platform, throw this error.
|
|
120
|
+
* @param {string} moduleName The name of the module.
|
|
121
|
+
* @param {string} propertyName The name of the property.
|
|
122
|
+
* @returns {Error} The error.
|
|
123
|
+
* @example
|
|
124
|
+
* if (!StepCounter.startStepCounterUpdate) {
|
|
125
|
+
* throw new UnavailabilityError(NativeModuleName, eventName);
|
|
126
|
+
* }
|
|
127
|
+
*/
|
|
128
|
+
class UnavailabilityError extends Error {
|
|
129
|
+
constructor(moduleName, propertyName) {
|
|
130
|
+
super(`The method or property ${moduleName}.${propertyName} is not available on ${Platform.OS}, ` + "are you sure you've linked all the native dependencies properly?");
|
|
131
|
+
this.code = "ERR_UNAVAILABLE";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Returns whether the stepCounter is enabled on the device.
|
|
137
|
+
* iOS 8.0+ only. Android is available since KitKat (4.4 / API 19).
|
|
138
|
+
* @see https://developer.android.com/about/versions/android-4.4.html
|
|
139
|
+
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613963-isstepcountingavailable
|
|
140
|
+
* @returns {Promise<{ supported: boolean; granted: boolean }>} A promise that resolves with an object containing the stepCounter availability.
|
|
141
|
+
* supported - Whether the stepCounter is supported on device.
|
|
142
|
+
* granted - Whether user granted the permission.
|
|
143
|
+
*/
|
|
144
|
+
export function isStepCountingSupported() {
|
|
145
|
+
return StepCounter.isStepCountingSupported();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Start to subscribe stepCounter updates.
|
|
150
|
+
* Only the past seven days worth of data is stored and available for you to retrieve.
|
|
151
|
+
* Specifying a start date that is more than seven days in the past returns only the available data.
|
|
152
|
+
* ### iOS
|
|
153
|
+
* `CMStepCounter.startStepCountingUpdates` is deprecated since iOS 8.0. so used `CMPedometer.startUpdates` instead.
|
|
154
|
+
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613950-startupdates
|
|
155
|
+
* @see https://developer.apple.com/documentation/coremotion/cmstepcounter/1616151-startstepcountingupdates
|
|
156
|
+
* @param {Date} start A date indicating the start of the range over which to measure steps.
|
|
157
|
+
* @param {StepCountUpdateCallback} callBack - This callback function makes it easy for app developers to receive sensor events.
|
|
158
|
+
* @returns {EventSubscription} - Returns a Subscription that enables you to call.
|
|
159
|
+
* When you would like to unsubscribe the listener, just use a method of subscriptions's `remove()`.
|
|
160
|
+
* @example
|
|
161
|
+
* const startDate = new Date();
|
|
162
|
+
* subscriptionRef.current = startStepCounterUpdate(startDate, (response) => {
|
|
163
|
+
* const data = parseStepCountData(response);
|
|
164
|
+
* })
|
|
165
|
+
*/
|
|
166
|
+
export function startStepCounterUpdate(start, callBack) {
|
|
167
|
+
if (!StepCounter.startStepCounterUpdate) {
|
|
168
|
+
throw new UnavailabilityError(NAME, eventName);
|
|
169
|
+
}
|
|
170
|
+
// Clean up any previous subscription registered by this library before creating a new one.
|
|
171
|
+
_activeSubscription?.remove();
|
|
172
|
+
_activeSubscription = null;
|
|
173
|
+
const from = start.getTime();
|
|
174
|
+
_activeSubscription = StepEventEmitter.addListener(eventName, data => callBack(data));
|
|
175
|
+
StepCounter.startStepCounterUpdate(from);
|
|
176
|
+
return _activeSubscription;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Stop the step counter updates.
|
|
181
|
+
* ### iOS
|
|
182
|
+
* `CMStepCounter.stopStepCountingUpdates` is deprecated since iOS 8.0. so used `CMPedometer.stopUpdates` instead.
|
|
183
|
+
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613973-stopupdates
|
|
184
|
+
* @see https://developer.apple.com/documentation/coremotion/cmstepcounter/1616157-stopstepcountingupdates
|
|
185
|
+
*/
|
|
186
|
+
export function stopStepCounterUpdate() {
|
|
187
|
+
// Remove only the subscription registered by this library, not all listeners.
|
|
188
|
+
// Calling removeAllListeners would break external subscribers such as debug log components.
|
|
189
|
+
_activeSubscription?.remove();
|
|
190
|
+
_activeSubscription = null;
|
|
191
|
+
StepCounter.stopStepCounterUpdate();
|
|
192
|
+
}
|
|
193
|
+
export { NAME, VERSION };
|
|
194
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StepCounterModule","eventName","NAME","VERSION","NativeEventEmitter","Platform","pkg","repositoryWebUrl","url","repository","replace","LINKING_ERROR","name","select","ios","android","default","StepCounter","Proxy","get","Error","StepEventEmitter","DEFAULT_MINIMUM_STEP_INTERVAL_MS","_activeSubscription","parseStepData","data","steps","startDate","endDate","distance","dailyGoal","stepsString","kCal","toFixed","endDateTime","Date","toLocaleTimeString","startDateTime","roundedDistance","stepGoalStatus","calories","createStepCountFilter","options","minimumStepIntervalMs","previousRawData","ignoredSteps","ignoredDistance","Number","isFinite","referenceTime","stepDelta","distanceDelta","elapsedMs","POSITIVE_INFINITY","isSuspiciousBurst","Math","max","UnavailabilityError","constructor","moduleName","propertyName","OS","code","isStepCountingSupported","startStepCounterUpdate","start","callBack","remove","from","getTime","addListener","stopStepCounterUpdate"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AACA,OAAOA,iBAAiB,IACtBC,SAAS,EACTC,IAAI,EACJC,OAAO,QAIF,wBAAqB;AAC5B,SAASC,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAC3D,OAAOC,GAAG,MAAM,iBAAiB;AAEjC,SAASC,gBAAgBA,CAAA,EAAW;EAClC,MAAMC,GAAG,GAAGF,GAAG,CAACG,UAAU,CAACD,GAAG;EAC9B,OAAOA,GAAG,CAACE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAACA,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;AACxD;;AAEA;AACA,MAAMC,aAAa,GACjB,gBAAgBL,GAAG,CAACM,IAAI,8CAA8C,GACtEP,QAAQ,CAACQ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AuB,CAAC,CAAC;AAC9C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CACpCC,KAAW,EACXC,QAAiC,EACd;EACnB,IAAI,CAACjD,WAAW,CAAC+C,sBAAsB,EAAE;IACvC,MAAM,IAAIP,mBAAmB,CAACvD,IAAI,EAAED,SAAS,CAAC;EAChD;EACA;EACAsB,mBAAmB,EAAE4C,MAAM,CAAC,CAAC;EAC7B5C,mBAAmB,GAAG,IAAI;EAC1B,MAAM6C,IAAI,GAAGH,KAAK,CAACI,OAAO,CAAC,CAAC;EAC5B9C,mBAAmB,GAAGF,gBAAgB,CAACiD,WAAW,CAACrE,SAAS,EAAGwB,IAAI,IACjEyC,QAAQ,CAACzC,IAAqB,CAChC,CAAC;EACDR,WAAW,CAAC+C,sBAAsB,CAACI,IAAI,CAAC;EACxC,OAAO7C,mBAAmB;AAC5B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASgD,qBAAqBA,CAAA,EAAS;EAC5C;EACA;EACAhD,mBAAmB,EAAE4C,MAAM,CAAC,CAAC;EAC7B5C,mBAAmB,GAAG,IAAI;EAC1BN,WAAW,CAACsD,qBAAqB,CAAC,CAAC;AACrC;AAEA,SAASrE,IAAI,EAAEC,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.setup.d.ts","sourceRoot":"","sources":["../../jest.setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type TurboModule } from "react-native";
|
|
2
|
+
export type CounterType = "STEP_COUNTER" | "ACCELEROMETER" | "CMPedometer";
|
|
3
|
+
/**
|
|
4
|
+
* `StepCountData` is an object with four properties: `distance`, `steps`, `startDate`, and `endDate`.
|
|
5
|
+
* StepCountData object - The Object that contains the step count data.
|
|
6
|
+
* counterType - The type of counter used to count the steps.
|
|
7
|
+
* steps - The number of steps taken during the time period.
|
|
8
|
+
* startDate - The start date of the data.
|
|
9
|
+
* endDate - The end date of the data.
|
|
10
|
+
* distance - The distance in meters that the user has walked or run.
|
|
11
|
+
* floorsAscended - number of floors ascended (iOS only)
|
|
12
|
+
* floorsDescended - number of floors descended (iOS only)
|
|
13
|
+
*/
|
|
14
|
+
export type StepCountData = {
|
|
15
|
+
counterType: CounterType;
|
|
16
|
+
steps: number;
|
|
17
|
+
startDate: number;
|
|
18
|
+
endDate: number;
|
|
19
|
+
distance: number;
|
|
20
|
+
floorsAscended?: number;
|
|
21
|
+
floorsDescended?: number;
|
|
22
|
+
};
|
|
23
|
+
export declare const NAME = "StepCounter";
|
|
24
|
+
export declare const VERSION = "0.3.1";
|
|
25
|
+
export declare const eventName = "StepCounter.stepCounterUpdate";
|
|
26
|
+
export interface Spec extends TurboModule {
|
|
27
|
+
/**
|
|
28
|
+
* @description Check if the step counter is supported on the device.
|
|
29
|
+
* @async
|
|
30
|
+
* @returns {Promise<{ supported: boolean; granted: boolean }>} Returns the `Promise` object,
|
|
31
|
+
* including information such as whether the user's device has a step counter sensor by default (`supported`)
|
|
32
|
+
* and whether the user has allowed the app to measure the pedometer data. (`granted`)
|
|
33
|
+
* granted - The permission is granted or not.
|
|
34
|
+
* supported - The step counter is supported or not.
|
|
35
|
+
* @example
|
|
36
|
+
* isStepCountingSupported().then((response) => {
|
|
37
|
+
* const { granted, supported } = response;
|
|
38
|
+
* setStepCountingSupported(supported);
|
|
39
|
+
* setStepCountingGranted(granted);
|
|
40
|
+
* });
|
|
41
|
+
*/
|
|
42
|
+
isStepCountingSupported(): Promise<{
|
|
43
|
+
supported: boolean;
|
|
44
|
+
granted: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* @param {number} from the current time obtained by `new Date()` in milliseconds.
|
|
48
|
+
*/
|
|
49
|
+
startStepCounterUpdate(from: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Stop updating the step count data.
|
|
52
|
+
* Removes all the listeners that were registered with `startStepCounterUpdate`.
|
|
53
|
+
*/
|
|
54
|
+
stopStepCounterUpdate(): void;
|
|
55
|
+
addListener(event: string): void;
|
|
56
|
+
removeListeners(count: number): void;
|
|
57
|
+
}
|
|
58
|
+
declare const _default: Spec;
|
|
59
|
+
export default _default;
|
|
60
|
+
//# sourceMappingURL=NativeStepCounter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeStepCounter.d.ts","sourceRoot":"","sources":["../../../src/NativeStepCounter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,eAAe,GAAG,aAAa,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,IAAI,gBAAgB,CAAC;AAClC,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,SAAS,kCAAkC,CAAC;AAEzD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;;;;;;;;;;;;;OAcG;IACH,uBAAuB,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC7E;;OAEG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C;;;OAGG;IACH,qBAAqB,IAAI,IAAI,CAAC;IAG9B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAED,wBAAqE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { EventSubscription } from "react-native";
|
|
2
|
+
import { NAME, VERSION, type CounterType, type StepCountData } from "./NativeStepCounter";
|
|
3
|
+
export interface ParsedStepCountData {
|
|
4
|
+
dailyGoal: string;
|
|
5
|
+
steps: number;
|
|
6
|
+
stepsString: string;
|
|
7
|
+
calories: string;
|
|
8
|
+
startDate: string;
|
|
9
|
+
endDate: string;
|
|
10
|
+
distance: string;
|
|
11
|
+
}
|
|
12
|
+
type StepCountUpdateCallback = (data: StepCountData) => void;
|
|
13
|
+
export type StepCountFilter = (data: StepCountData) => StepCountData | null;
|
|
14
|
+
export interface StepCountFilterOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Minimum elapsed time expected per accepted step.
|
|
17
|
+
*
|
|
18
|
+
* Events that imply a faster cadence are treated as sensor false positives.
|
|
19
|
+
* 250ms allows up to 4 steps/second, which is already faster than typical walking.
|
|
20
|
+
*/
|
|
21
|
+
minimumStepIntervalMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Transform the step count data into a more readable format.
|
|
25
|
+
* You can use it or directly use the `StepCountData` type.
|
|
26
|
+
* @param {StepCountData} data - Step Counter Sensor Event Data.
|
|
27
|
+
* @returns {ParsedStepCountData} - String Parsed Count Data.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseStepData(data: StepCountData): ParsedStepCountData;
|
|
30
|
+
/**
|
|
31
|
+
* Create a stateful filter for live step-count updates.
|
|
32
|
+
*
|
|
33
|
+
* Native pedometer APIs can already include device/OS false positives, and the
|
|
34
|
+
* Android accelerometer fallback can also react to quick hand rotation. This
|
|
35
|
+
* helper drops updates that imply an impossible cadence and rebases later
|
|
36
|
+
* cumulative values so ignored burst steps do not come back on the next event.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createStepCountFilter(options?: StepCountFilterOptions): StepCountFilter;
|
|
39
|
+
/**
|
|
40
|
+
* Returns whether the stepCounter is enabled on the device.
|
|
41
|
+
* iOS 8.0+ only. Android is available since KitKat (4.4 / API 19).
|
|
42
|
+
* @see https://developer.android.com/about/versions/android-4.4.html
|
|
43
|
+
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613963-isstepcountingavailable
|
|
44
|
+
* @returns {Promise<{ supported: boolean; granted: boolean }>} A promise that resolves with an object containing the stepCounter availability.
|
|
45
|
+
* supported - Whether the stepCounter is supported on device.
|
|
46
|
+
* granted - Whether user granted the permission.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isStepCountingSupported(): Promise<{
|
|
49
|
+
supported: boolean;
|
|
50
|
+
granted: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Start to subscribe stepCounter updates.
|
|
54
|
+
* Only the past seven days worth of data is stored and available for you to retrieve.
|
|
55
|
+
* Specifying a start date that is more than seven days in the past returns only the available data.
|
|
56
|
+
* ### iOS
|
|
57
|
+
* `CMStepCounter.startStepCountingUpdates` is deprecated since iOS 8.0. so used `CMPedometer.startUpdates` instead.
|
|
58
|
+
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613950-startupdates
|
|
59
|
+
* @see https://developer.apple.com/documentation/coremotion/cmstepcounter/1616151-startstepcountingupdates
|
|
60
|
+
* @param {Date} start A date indicating the start of the range over which to measure steps.
|
|
61
|
+
* @param {StepCountUpdateCallback} callBack - This callback function makes it easy for app developers to receive sensor events.
|
|
62
|
+
* @returns {EventSubscription} - Returns a Subscription that enables you to call.
|
|
63
|
+
* When you would like to unsubscribe the listener, just use a method of subscriptions's `remove()`.
|
|
64
|
+
* @example
|
|
65
|
+
* const startDate = new Date();
|
|
66
|
+
* subscriptionRef.current = startStepCounterUpdate(startDate, (response) => {
|
|
67
|
+
* const data = parseStepCountData(response);
|
|
68
|
+
* })
|
|
69
|
+
*/
|
|
70
|
+
export declare function startStepCounterUpdate(start: Date, callBack: StepCountUpdateCallback): EventSubscription;
|
|
71
|
+
/**
|
|
72
|
+
* Stop the step counter updates.
|
|
73
|
+
* ### iOS
|
|
74
|
+
* `CMStepCounter.stopStepCountingUpdates` is deprecated since iOS 8.0. so used `CMPedometer.stopUpdates` instead.
|
|
75
|
+
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613973-stopupdates
|
|
76
|
+
* @see https://developer.apple.com/documentation/coremotion/cmstepcounter/1616157-stopstepcountingupdates
|
|
77
|
+
*/
|
|
78
|
+
export declare function stopStepCounterUpdate(): void;
|
|
79
|
+
export { NAME, VERSION, type CounterType, type StepCountData };
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAA0B,EAExB,IAAI,EACJ,OAAO,EACP,KAAK,WAAW,EAEhB,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAC;AAyB7B,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AA0BD,KAAK,uBAAuB,GAAG,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,aAAa,KAAK,aAAa,GAAG,IAAI,CAAC;AAE5E,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AASD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,mBAAmB,CAkBtE;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAsD3F;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAAC;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAE3F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,uBAAuB,GAChC,iBAAiB,CAanB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAM5C;AAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blife/rn-step-counter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "This library provides an interface for tracking the number of steps taken by the user in a React Native app.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "bun --cwd example run",
|
|
36
|
+
"example:start": "bun --cwd example run start",
|
|
37
|
+
"example:android": "bun --cwd example run android",
|
|
38
|
+
"example:ios": "bun --cwd example run ios",
|
|
39
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build example/ios/Pods lib",
|
|
40
|
+
"test": "jest --runInBand --no-watchman",
|
|
41
|
+
"prepare": "bob build",
|
|
42
|
+
"typecheck": "tsc",
|
|
43
|
+
"sync-brand": "node scripts/sync-brand.mjs",
|
|
44
|
+
"watchman-reset": "watchman watch-del $PWD && watchman watch-project $PWD"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"react-native",
|
|
48
|
+
"ios",
|
|
49
|
+
"android"
|
|
50
|
+
],
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/bonnmh/rn-step-counter.git"
|
|
54
|
+
},
|
|
55
|
+
"author": "bonnmh <nmhbonc2thptcd@gmail.com> (https://github.com/bonnmh)",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/bonnmh/rn-step-counter/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://github.com/bonnmh/rn-step-counter#readme",
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"registry": "https://registry.npmjs.org/"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@babel/core": "^7.29.0",
|
|
66
|
+
"@react-native/babel-preset": "0.85.3",
|
|
67
|
+
"@react-native/jest-preset": "0.85.3",
|
|
68
|
+
"@release-it/conventional-changelog": "^11.0.0",
|
|
69
|
+
"@testing-library/react-native": "^13.3.3",
|
|
70
|
+
"@types/babel__core": "^7.20.5",
|
|
71
|
+
"@types/jest": "^29.5.14",
|
|
72
|
+
"@types/react": "^19.2.15",
|
|
73
|
+
"@types/react-test-renderer": "^19.1.0",
|
|
74
|
+
"del-cli": "^7.0.0",
|
|
75
|
+
"jest": "^29.7.0",
|
|
76
|
+
"jest-config": "29.7.0",
|
|
77
|
+
"react": "19.2.3",
|
|
78
|
+
"react-native": "0.85.3",
|
|
79
|
+
"react-native-builder-bob": "^0.41.0",
|
|
80
|
+
"react-test-renderer": "19.2.3",
|
|
81
|
+
"release-it": "^20.0.1",
|
|
82
|
+
"typescript": "^6.0.3"
|
|
83
|
+
},
|
|
84
|
+
"resolutions": {
|
|
85
|
+
"basic-ftp": "5.3.1",
|
|
86
|
+
"brace-expansion@npm:^1.1.7": "npm:1.1.13",
|
|
87
|
+
"brace-expansion@npm:^2.0.1": "npm:2.0.3",
|
|
88
|
+
"brace-expansion@npm:^5.0.2": "npm:5.0.6",
|
|
89
|
+
"defu@npm:^6.1.4": "npm:6.1.7",
|
|
90
|
+
"fast-xml-parser": "5.7.0",
|
|
91
|
+
"handlebars@npm:^4.7.7": "npm:4.7.9",
|
|
92
|
+
"ip-address@npm:^10.0.1": "npm:10.1.1",
|
|
93
|
+
"minimatch@npm:^10.2.1": "npm:10.2.3",
|
|
94
|
+
"minimatch@npm:^3.0.4": "npm:3.1.4",
|
|
95
|
+
"minimatch@npm:^3.1.1": "npm:3.1.4",
|
|
96
|
+
"minimatch@npm:^9.0.4": "npm:9.0.7",
|
|
97
|
+
"picomatch@npm:^2.0.4": "npm:2.3.2",
|
|
98
|
+
"picomatch@npm:^2.2.3": "npm:2.3.2",
|
|
99
|
+
"picomatch@npm:^2.3.1": "npm:2.3.2",
|
|
100
|
+
"picomatch@npm:^4.0.3": "npm:4.0.4",
|
|
101
|
+
"tar": "7.5.13",
|
|
102
|
+
"yaml@npm:^2.2.1": "npm:2.8.3",
|
|
103
|
+
"yaml@npm:^2.6.1": "npm:2.8.3"
|
|
104
|
+
},
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"react": "*",
|
|
107
|
+
"react-native": ">=0.71.0"
|
|
108
|
+
},
|
|
109
|
+
"workspaces": [
|
|
110
|
+
"example"
|
|
111
|
+
],
|
|
112
|
+
"react-native-builder-bob": {
|
|
113
|
+
"source": "src",
|
|
114
|
+
"output": "lib",
|
|
115
|
+
"targets": [
|
|
116
|
+
[
|
|
117
|
+
"module",
|
|
118
|
+
{
|
|
119
|
+
"esm": true
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
"typescript",
|
|
124
|
+
{
|
|
125
|
+
"project": "tsconfig.build.json"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"codegenConfig": {
|
|
131
|
+
"name": "StepCounterSpec",
|
|
132
|
+
"type": "modules",
|
|
133
|
+
"jsSrcsDir": "src",
|
|
134
|
+
"android": {
|
|
135
|
+
"javaPackageName": "com.stepcounter"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from "react-native";
|
|
2
|
+
|
|
3
|
+
export type CounterType = "STEP_COUNTER" | "ACCELEROMETER" | "CMPedometer";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `StepCountData` is an object with four properties: `distance`, `steps`, `startDate`, and `endDate`.
|
|
7
|
+
* StepCountData object - The Object that contains the step count data.
|
|
8
|
+
* counterType - The type of counter used to count the steps.
|
|
9
|
+
* steps - The number of steps taken during the time period.
|
|
10
|
+
* startDate - The start date of the data.
|
|
11
|
+
* endDate - The end date of the data.
|
|
12
|
+
* distance - The distance in meters that the user has walked or run.
|
|
13
|
+
* floorsAscended - number of floors ascended (iOS only)
|
|
14
|
+
* floorsDescended - number of floors descended (iOS only)
|
|
15
|
+
*/
|
|
16
|
+
export type StepCountData = {
|
|
17
|
+
counterType: CounterType;
|
|
18
|
+
steps: number; // number of steps
|
|
19
|
+
startDate: number; // Unix timestamp in milliseconds (long)
|
|
20
|
+
endDate: number; // Unix timestamp in milliseconds (long)
|
|
21
|
+
distance: number; // distance in meters (android: probably not accurate)
|
|
22
|
+
floorsAscended?: number; // number of floors ascended (iOS only)
|
|
23
|
+
floorsDescended?: number; // number of floors descended (iOS only)
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const NAME = "StepCounter";
|
|
27
|
+
export const VERSION = "0.3.1";
|
|
28
|
+
export const eventName = "StepCounter.stepCounterUpdate";
|
|
29
|
+
|
|
30
|
+
export interface Spec extends TurboModule {
|
|
31
|
+
/**
|
|
32
|
+
* @description Check if the step counter is supported on the device.
|
|
33
|
+
* @async
|
|
34
|
+
* @returns {Promise<{ supported: boolean; granted: boolean }>} Returns the `Promise` object,
|
|
35
|
+
* including information such as whether the user's device has a step counter sensor by default (`supported`)
|
|
36
|
+
* and whether the user has allowed the app to measure the pedometer data. (`granted`)
|
|
37
|
+
* granted - The permission is granted or not.
|
|
38
|
+
* supported - The step counter is supported or not.
|
|
39
|
+
* @example
|
|
40
|
+
* isStepCountingSupported().then((response) => {
|
|
41
|
+
* const { granted, supported } = response;
|
|
42
|
+
* setStepCountingSupported(supported);
|
|
43
|
+
* setStepCountingGranted(granted);
|
|
44
|
+
* });
|
|
45
|
+
*/
|
|
46
|
+
isStepCountingSupported(): Promise<{ supported: boolean; granted: boolean }>;
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} from the current time obtained by `new Date()` in milliseconds.
|
|
49
|
+
*/
|
|
50
|
+
startStepCounterUpdate(from: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Stop updating the step count data.
|
|
53
|
+
* Removes all the listeners that were registered with `startStepCounterUpdate`.
|
|
54
|
+
*/
|
|
55
|
+
stopStepCounterUpdate(): void;
|
|
56
|
+
|
|
57
|
+
/* Required Methods for NativeEventEmitter */
|
|
58
|
+
addListener(event: string): void;
|
|
59
|
+
removeListeners(count: number): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default TurboModuleRegistry.getEnforcing<Spec>("StepCounter");
|