Skip to content

Commit 0175520

Browse files
authored
Merge pull request #28 from ifielder/master
Compatibility with react-native 0.62
2 parents c1f6751 + 18207b9 commit 0175520

4 files changed

+7554
-25
lines changed

README.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public class MainApplication extends Application implements ReactApplication {
9393
4. Add `NSMotionUsageDescription` key to your `Info.plist` with strings describing why your app needs this permission
9494

9595

96-
## Usage
96+
## Usage
97+
### Class based implementation
9798

9899
```js
99100
import ActivityRecognition from 'react-native-activity-recognition'
@@ -118,6 +119,35 @@ ActivityRecognition.stop()
118119
this.unsubscribe()
119120
```
120121

122+
### Hooks based implementation
123+
124+
```js
125+
import ActivityRecognition from 'react-native-activity-recognition'
126+
127+
...
128+
129+
// Subscribe to updates on mount
130+
131+
useEffect(() => {
132+
ActivityRecognition.subscribe(detectedActivities => {
133+
const mostProbableActivity = detectedActivities.sorted[0];
134+
console.log(mostProbableActivity);
135+
});
136+
137+
// Stop activity detection and remove the listener on unmount
138+
139+
return ActivityRecognition.stop();
140+
});
141+
142+
...
143+
144+
// Start activity detection
145+
146+
const detectionIntervalMillis = 1000
147+
ActivityRecognition.start(detectionIntervalMillis)
148+
149+
```
150+
121151
### Android
122152

123153
`detectedActivities` is an object with keys for each detected activity, each of which have an integer percentage (0-100) indicating the likelihood that the user is performing this activity. For example:

RNActivityRecognition.podspec

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
require 'json'
3+
4+
package = JSON.parse(File.read('./package.json'))
5+
6+
Pod::Spec.new do |s|
7+
s.name = 'RNActivityRecognition'
8+
s.version = package['version']
9+
s.summary = package['description']
10+
s.description = package['description']
11+
s.homepage = package['homepage']
12+
s.license = package['license']
13+
s.author = package['author']
14+
s.source = { :git => "https://github.com/author/RNActivityRecognition.git" }
15+
s.platform = :ios, "7.0"
16+
s.source_files = "ios/*.{h,m}"
17+
s.preserve_paths = "*.js"
18+
s.dependency 'React'
19+
end
20+
21+

ios/RNActivityRecognition.podspec

-24
This file was deleted.

0 commit comments

Comments
 (0)