Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5be5e58
updated package name
raisiqueira Apr 2, 2018
7087f00
add peer pedendencies
raisiqueira Apr 2, 2018
ab67407
update index with new methods from BMD Pedometer
raisiqueira Apr 2, 2018
41aaa41
update iOS files
raisiqueira Apr 2, 2018
ede4088
removed SOS Step Detector
raisiqueira Apr 2, 2018
77800fb
changed tab size to 2 spaces
raisiqueira Apr 2, 2018
c3b5b3d
Create LICENSE
raisiqueira Apr 5, 2018
ddb3c17
Merge pull request #1 from AsserData/add-license-1
raisiqueira Apr 5, 2018
43e097d
updated EventEmitter
raisiqueira Apr 5, 2018
edf7f9d
Merge branch 'master' of https://github.com/AsserData/react-native-un…
raisiqueira Apr 5, 2018
12e8ce6
updated readme
raisiqueira Apr 5, 2018
361535d
updated version
raisiqueira Apr 5, 2018
f5dae8d
Update README.md, Update typescript support, Remove 'bracketSpacing' …
Feb 15, 2019
c94b381
Fix error from BMDPedometer.m
Feb 15, 2019
6ec5a33
Update README.md
Feb 15, 2019
2612dfe
Remove SOStepDetector related codes from project.pbxproj
Feb 15, 2019
b09975d
Fix error from ios/BMDPedometer.m
Feb 15, 2019
238f646
Update index.d.ts, Update README.md, Remove 'react' and fix EventEmit…
Feb 15, 2019
4d07dec
Fix yellow box requiresMainQueueSetup message
Feb 16, 2019
400873c
Match android build.gradle to higher version
Mar 26, 2019
d830c6b
Update android compileSdkVersion 23 -> 27
Apr 3, 2019
32d57ce
Merge branch 'master' into master
Jul 14, 2019
14b713b
Added basic podspec file to allow autolinking
stephenheron Sep 9, 2019
f7427c2
Merge pull request #1 from stephenheron/master
Jan 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local.properties
#
node_modules/
npm-debug.log
package-lock.json

# BUCK
buck-out/
Expand Down
Binary file added .vscode/ipch/c1c9645d421b193a/mmap_address.bin
Binary file not shown.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Asser Data S/A

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 58 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,64 @@

React Native pedometer support for iOS version 8.0 and higher and Android. The module is CMPedometer wrapper. More info about CMPedometer can be found in https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMPedometer_class/

## Basic usage
#### _Note_

- Currently typescript is supported.

### Installation

1. `npm install --save @JWWon/react-native-universal-pedometer`

> or `yarn add JWWon/react-native-universal-pedometer`

2. `react-native link @JWWon/react-native-universal-pedometer`

> It will automatically do all necessary settings

##### iOS Configuration

add **NSMotionUsageDescription** on `ios/<your-project>/info.plist`

```
// info.plist
<dict>
...
<key>NSMotionUsageDescription</key>
<string></string>
</dict>
```

### General Usage

```js
import Pedometer from '@JWWon/react-native-universal-pedometer';
```

or

```js
// Import the react-native-pedometer module
import Pedometer from 'react-native-universal-pedometer';

// determine pedometer availability
Pedometer.isStepCountingAvailable((error, isAvailable) => {
// do something
});

Pedometer.isDistanceAvailable((error, isAvailable) => {
// do something
});

Pedometer.isFloorCountingAvailable((error, isAvailable) => {
// do something
});

Pedometer.isCadenceAvailable((error, isAvailable) => {
// do something
});

// start tracking from current time
const now = new Date();
Pedometer.startPedometerUpdatesFromDate(now.getTime(), (pedometerData) => {
// do something with pedometer data
});

// query pedometer data from selected date to other selected date
const startDate = new Date();
startDate.setHours(0,0,0,0);
const endDate = new Date();
Pedometer.queryPedometerDataBetweenDates(startDate.getTime(), endDate.getTime(), (pedometerData) => {
// do something with pedometer data
});

// stop pedometer updates
Pedometer.stopPedometerUpdates();
var Pedometer = require('@JWWon/react-native-universal-pedometer');
```

### Methods

| Method Name | Arguments | Notes |
| -------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| `isStepCountingAvailable` | callback: `Callback` | |
| `isDistanceAvailable` | callback: `Callback` | |
| `isFloorCountingAvailable` | callback: `Callback` | |
| `isPaceAvailable` | callback: `Callback` | |
| `isCadenceAvailable` | callback: `Callback` | |
| `startPedometerUpdatesFromDate` | date: `Date.getTime()`, listener: `Listener` | start tracking from current time |
| `queryPedometerDataBetweenDates` | startDate: `Date.getTime()`, endDate: `Date.getTime()`, listener: `Listener` | query pedometer data from selected date to other selected date |
| `stopPedometerUpdates` | | stop pedometer updates |

### Types

| Type Name | Interface |
| ------------------------- | ------------------------------------------------------------ |
| `PedometerInterface` | `{ startDate: nubmer; endDate: number; numberOfSteps: number; distance: number; }` |
| `PedometerErrorInterface` | `{ code: number; message: string; }` |
| `Callback` | `(error: string or null, avaliable: boolean) => any` |
| `Listener` | `(data: PedometerInterface or PedometerErrorInterface) => any` |

17 changes: 10 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion safeExtGet('compileSdkVersion', 27)

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 27)
versionCode 2
versionName "1.0.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
Expand All @@ -19,5 +22,5 @@ android {
}

dependencies {
compile 'com.facebook.react:react-native:+'
implementation 'com.facebook.react:react-native:+'
}
28 changes: 28 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export interface PedometerInterface {
startDate: number;
endDate: number;
numberOfSteps: number;
distance: number;
}

export interface PedometerErrorInterface {
code: number;
message: string;
}

type Callback = (error: string | null, available: boolean) => any;

type Listener = (data: PedometerInterface | PedometerErrorInterface) => any;

declare const _default: {
isStepCountingAvailable: (callback: Callback) => void;
isDistanceAvailable: (callback: Callback) => void;
isFloorCountingAvailable: (callback: Callback) => void;
isPaceAvailable: (callback: Callback) => void;
isCadenceAvailable: (callback: Callback) => void;
startPedometerUpdatesFromDate: (date: number, listener: Listener) => void;
queryPedometerDataBetweenDates: (startDate: number, endDate: number, listener: Listener) => void;
stopPedometerUpdates: () => void;
};

export default _default;
85 changes: 35 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,42 @@
'use strict';

import {NativeModules, NativeEventEmitter} from 'react-native';
import { NativeEventEmitter, NativeModules } from 'react-native';

const {BMDPedometer} = NativeModules;
const { BMDPedometer } = NativeModules;

const EventEmitter = new NativeEventEmitter(BMDPedometer);
let subscription;
let stepsSubscription;
const PedometerEmitter = new NativeEventEmitter(BMDPedometer);

export default {
isStepCountingAvailable: callback => {
BMDPedometer.isStepCountingAvailable(callback);
},

isDistanceAvailable: callback => {
BMDPedometer.isDistanceAvailable(callback);
},

isFloorCountingAvailable: callback => {
BMDPedometer.isFloorCountingAvailable(callback);
},

isCadenceAvailable: callback => {
BMDPedometer.isCadenceAvailable(callback);
},

startPedometerUpdatesFromDate: (date, handler) => {
BMDPedometer.startPedometerUpdatesFromDate(date);

subscription = EventEmitter.addListener('pedometerDataDidUpdate', handler);
},

startStepsDetection: (handler) => {
BMDPedometer.startStepsDetection();

stepsSubscription = EventEmitter.addListener('pedometerWasStep', handler);
},



queryPedometerDataBetweenDates: (startDate, endDate, handler) => {
BMDPedometer.queryPedometerDataBetweenDates(startDate, endDate, handler);
},

stopPedometerUpdates: () => {
BMDPedometer.stopPedometerUpdates();

if (subscription) {
subscription.remove();
}

if (stepsSubscription) {
stepsSubscription.remove();
}
}
isStepCountingAvailable: callback => {
BMDPedometer.isStepCountingAvailable(callback);
},

isDistanceAvailable: callback => {
BMDPedometer.isDistanceAvailable(callback);
},

isFloorCountingAvailable: callback => {
BMDPedometer.isFloorCountingAvailable(callback);
},

isPaceAvailable: callback => {
BMDPedometer.isPaceAvailable(callback);
},

isCadenceAvailable: callback => {
BMDPedometer.isCadenceAvailable(callback);
},

startPedometerUpdatesFromDate: (date, listener) => {
BMDPedometer.startPedometerUpdatesFromDate(date);
PedometerEmitter.addListener('pedometerDataDidUpdate', listener);
},

queryPedometerDataBetweenDates: (startDate, endDate, listener) => {
BMDPedometer.queryPedometerDataBetweenDates(startDate, endDate, listener);
},

stopPedometerUpdates: () => {
BMDPedometer.stopPedometerUpdates();
}
};
6 changes: 0 additions & 6 deletions ios/BMDPedometer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
43D42B5F203B089B00EC7462 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43D42B5E203B089B00EC7462 /* CoreMotion.framework */; };
43D42B61203B08AA00EC7462 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43D42B60203B08AA00EC7462 /* CoreLocation.framework */; };
43D42B77203B2CB600EC7462 /* SOStepDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 43D42B75203B2CB600EC7462 /* SOStepDetector.m */; };
844442DC1CB01D4A00E10B29 /* BMDPedometer.h in Copy Files */ = {isa = PBXBuildFile; fileRef = 844442DB1CB01D4A00E10B29 /* BMDPedometer.h */; };
844442DE1CB01D4A00E10B29 /* BMDPedometer.m in Sources */ = {isa = PBXBuildFile; fileRef = 844442DD1CB01D4A00E10B29 /* BMDPedometer.m */; };
/* End PBXBuildFile section */
Expand All @@ -31,8 +30,6 @@
/* Begin PBXFileReference section */
43D42B5E203B089B00EC7462 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; };
43D42B60203B08AA00EC7462 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
43D42B75203B2CB600EC7462 /* SOStepDetector.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SOStepDetector.m; sourceTree = "<group>"; };
43D42B76203B2CB600EC7462 /* SOStepDetector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SOStepDetector.h; sourceTree = "<group>"; };
844442D81CB01D4A00E10B29 /* libBMDPedometer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBMDPedometer.a; sourceTree = BUILT_PRODUCTS_DIR; };
844442DB1CB01D4A00E10B29 /* BMDPedometer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BMDPedometer.h; sourceTree = "<group>"; };
844442DD1CB01D4A00E10B29 /* BMDPedometer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BMDPedometer.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,8 +85,6 @@
844442DA1CB01D4A00E10B29 /* BMDPedometer */ = {
isa = PBXGroup;
children = (
43D42B76203B2CB600EC7462 /* SOStepDetector.h */,
43D42B75203B2CB600EC7462 /* SOStepDetector.m */,
844442DB1CB01D4A00E10B29 /* BMDPedometer.h */,
844442DD1CB01D4A00E10B29 /* BMDPedometer.m */,
);
Expand Down Expand Up @@ -154,7 +149,6 @@
buildActionMask = 2147483647;
files = (
844442DE1CB01D4A00E10B29 /* BMDPedometer.m in Sources */,
43D42B77203B2CB600EC7462 /* SOStepDetector.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions ios/BMDPedometer/BMDPedometer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import <Foundation/Foundation.h>
#import <CoreMotion/CoreMotion.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import "SOStepDetector.h"

@interface BMDPedometer : RCTEventEmitter<RCTBridgeModule>

@property (nonatomic, readonly) CMPedometer *pedometer;
@end
Loading