diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e43b0f9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/README.md b/README.md
index 1f6cc73..7901dd9 100644
--- a/README.md
+++ b/README.md
@@ -5,12 +5,13 @@ Get device heading information on iOS or Android
Report back device orientation in degrees, 0-360, with 0 being North.
#### Example
-```java
-const { DeviceEventEmitter } = require('react-native');
-const ReactNativeHeading = require('react-native-heading');
+```javascript
+import { NativeEventEmitter } from 'react-native';
+import ReactNativeHeading from 'react-native-heading';
//....
componentDidMount() {
+ this.listener = new NativeEventEmitter(ReactNativeHeading)
ReactNativeHeading.start(1)
.then(didStart => {
this.setState({
@@ -18,14 +19,14 @@ const ReactNativeHeading = require('react-native-heading');
})
})
- DeviceEventEmitter.addListener('headingUpdated', data => {
- console.log('New heading is:', data.heading);
+ this.listener.addListener('headingUpdated', heading => {
+ console.log('New heading is:', heading);
});
}
componentWillUnmount() {
ReactNativeHeading.stop();
- DeviceEventEmitter.removeAllListeners('headingUpdated');
+ this.listener.removeAllListeners('headingUpdated');
}
//...
```
@@ -45,13 +46,14 @@ const ReactNativeHeading = require('react-native-heading');
## Setup
-````
-npm install --save react-native-heading
-````
+```
+yarn add react-native-heading
+```
### iOS
* Run open node_modules/react-native-heading
-* Drag ReactNativeHeading.xcodeproj into your Libraries group
+* Drag ReactNativeHeading.xcodeproj into your Libraries group of XCode's project navigator
+* In XCode add Libraries/ReactNativeHeading.xcodeproj/Products/libReactNativeHeading.a to the "Link Binary with Libraries" section of the Build Phases
### Android
##### Step 1 - Update Gradle Settings
diff --git a/ReactNativeHeading.android.js b/ReactNativeHeading.android.js
deleted file mode 100644
index 87dac21..0000000
--- a/ReactNativeHeading.android.js
+++ /dev/null
@@ -1,10 +0,0 @@
-/** *
- * @providesModule ReactNativeHeading
- * @flow
- */
-'use strict';
-
-var React = require('react-native');
-var ReactNativeHeading = React.NativeModules.ReactNativeHeading;
-
-module.exports = ReactNativeHeading;
diff --git a/ReactNativeHeading.h b/ReactNativeHeading.h
index 2ae0d8d..f760db6 100644
--- a/ReactNativeHeading.h
+++ b/ReactNativeHeading.h
@@ -6,9 +6,8 @@
// Copyright © 2016 Yonah Forst. All rights reserved.
//
#import
+#import
-#import
-
-@interface ReactNativeHeading : NSObject
+@interface ReactNativeHeading : RCTEventEmitter
@end
diff --git a/ReactNativeHeading.ios.js b/ReactNativeHeading.ios.js
deleted file mode 100644
index b3e92e4..0000000
--- a/ReactNativeHeading.ios.js
+++ /dev/null
@@ -1,6 +0,0 @@
-'use strict';
-
-var React = require('react-native');
-var Heading = React.NativeModules.ReactNativeHeading;
-
-module.exports = Heading;
diff --git a/ReactNativeHeading.js b/ReactNativeHeading.js
new file mode 100644
index 0000000..b79b49b
--- /dev/null
+++ b/ReactNativeHeading.js
@@ -0,0 +1,12 @@
+/**
+ *
+ * @providesModule ReactNativeHeading
+ *
+ */
+'use strict';
+
+import {
+ NativeModules
+} from 'react-native';
+
+export default NativeModules.ReactNativeHeading;
\ No newline at end of file
diff --git a/ReactNativeHeading.m b/ReactNativeHeading.m
index d573b45..bca329e 100644
--- a/ReactNativeHeading.m
+++ b/ReactNativeHeading.m
@@ -54,6 +54,10 @@ - (instancetype)init
[self.locManager stopUpdatingHeading];
}
+- (NSArray *)supportedEvents {
+ return @[@"headingUpdated"];
+}
+
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
if (newHeading.headingAccuracy < 0)
return;
@@ -62,9 +66,7 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading
CLLocationDirection heading = ((newHeading.trueHeading > 0) ?
newHeading.trueHeading : newHeading.magneticHeading);
- NSDictionary *headingEvent = @{@"heading": @(heading)};
-
- [self.bridge.eventDispatcher sendDeviceEventWithName:@"headingUpdated" body:headingEvent];
+ [self sendEventWithName:@"headingUpdated" body:@(heading)];
}
@end
diff --git a/android/build.gradle b/android/build.gradle
index 55dc946..dc4f79d 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -15,7 +15,7 @@ android {
buildToolsVersion "23.0.1"
defaultConfig {
- minSdkVersion 18
+ minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
@@ -30,6 +30,5 @@ repositories {
}
dependencies {
- compile 'com.facebook.react:react-native:0.20.+'
- compile "com.joshblour.discovery:discovery:0.0.3"
+ compile 'com.facebook.react:react-native:+'
}
diff --git a/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingModule.java b/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingModule.java
index 6875d34..c62b481 100755
--- a/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingModule.java
+++ b/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingModule.java
@@ -20,8 +20,6 @@
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
-import com.joshblour.discovery.BLEUser;
-import com.joshblour.discovery.Discovery;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -37,7 +35,7 @@ public class ReactNativeHeadingModule extends ReactContextBaseJavaModule impleme
private static Context mApplicationContext;
private int mAzimuth = 0; // degree
private int newAzimuth = 0; // degree
- private float mFilter = 5;
+ private int mFilter = 5;
private SensorManager mSensorManager;
private Sensor mSensor;
private float[] orientation = new float[3];
@@ -53,9 +51,6 @@ public String getName() {
return "ReactNativeHeading";
}
-
-
-
@ReactMethod
public void start(int filter, Promise promise) {
diff --git a/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingPackage.java b/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingPackage.java
index df0e4be..24e0bf7 100755
--- a/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingPackage.java
+++ b/android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingPackage.java
@@ -24,11 +24,6 @@ public List createNativeModules(ReactApplicationContext reactConte
modules.add(new ReactNativeHeadingModule(reactContext));
return modules; }
- @Override
- public List> createJSModules() {
- return Collections.emptyList();
- }
-
@Override
public List createViewManagers(ReactApplicationContext reactContext) {
return Arrays.asList();
diff --git a/package.json b/package.json
index e24bcb4..ce6b25f 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,8 @@
"type": "git",
"url": "https://github.com/joshblour/react-native-heading.git"
},
+ "homepage": "https://github.com/joshblour/react-native-heading.git",
+ "summary": "RN Package for head sensor detection",
"license": "MIT",
"keywords": ["react-native", "react-component"],
"main": "ReactNativeHeading",
diff --git a/react-native-heading.podspec b/react-native-heading.podspec
new file mode 100644
index 0000000..f4418a8
--- /dev/null
+++ b/react-native-heading.podspec
@@ -0,0 +1,22 @@
+require 'json'
+
+package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
+
+Pod::Spec.new do |s|
+ s.name = 'react-native-heading'
+ s.version = package['version']
+ s.summary = package['summary']
+ s.description = package['description']
+ s.license = package['license']
+ s.author = package['author']
+ s.homepage = package['homepage']
+ s.source = { :git => 'https://github.com/yonahforst/react-native-heading', :tag => s.version }
+
+ s.requires_arc = true
+ s.platform = :ios, '8.0'
+
+ s.preserve_paths = 'LICENSE', 'README.md', 'package.json', 'ReactNativeHeading.ios.js'
+ s.source_files = '*.{h,m}'
+
+ s.dependency 'React'
+end