Skip to content

Rebased version of #13. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
@@ -0,0 +1 @@
.DS_Store
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@ 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({
headingIsSupported: didStart,
})
})

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');
}
//...
```
Expand All @@ -45,13 +46,14 @@ const ReactNativeHeading = require('react-native-heading');

## Setup

````
npm install --save react-native-heading
````
```
yarn add https://github.com/joshblour/react-native-heading.git
```

### 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
Expand Down
10 changes: 0 additions & 10 deletions ReactNativeHeading.android.js

This file was deleted.

5 changes: 2 additions & 3 deletions ReactNativeHeading.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
// Copyright © 2016 Yonah Forst. All rights reserved.
//
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

#import <Foundation/Foundation.h>

@interface ReactNativeHeading : NSObject <RCTBridgeModule>
@interface ReactNativeHeading : RCTEventEmitter <RCTBridgeModule>

@end
6 changes: 0 additions & 6 deletions ReactNativeHeading.ios.js

This file was deleted.

12 changes: 12 additions & 0 deletions ReactNativeHeading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* @providesModule ReactNativeHeading
*
*/
'use strict';

import {
NativeModules
} from 'react-native';

export default NativeModules.ReactNativeHeading;
8 changes: 5 additions & 3 deletions ReactNativeHeading.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ - (instancetype)init
[self.locManager stopUpdatingHeading];
}

- (NSArray<NSString *> *)supportedEvents {
return @[@"headingUpdated"];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
if (newHeading.headingAccuracy < 0)
return;
Expand All @@ -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
5 changes: 2 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 18
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
Expand All @@ -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:+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -53,9 +51,6 @@ public String getName() {
return "ReactNativeHeading";
}




@ReactMethod
public void start(int filter, Promise promise) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
modules.add(new ReactNativeHeadingModule(reactContext));
return modules; }

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Arrays.asList();
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions react-native-heading.podspec
Original file line number Diff line number Diff line change
@@ -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/joshblour/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