Skip to content
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

Fix: don't ask for permission on startup #152

Merged
merged 5 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions ARKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ Object.keys(ARKitManager).forEach(key => {
ARKit[key] = ARKitManager[key];
});

const addDefaultsToSnapShotFunc = funcName => ({
target = 'cameraRoll',
format = 'png'
} = {}) => ARKitManager[funcName]({ target, format });
const addDefaultsToSnapShotFunc = funcName => (
{ target = 'cameraRoll', format = 'png' } = {},
) => ARKitManager[funcName]({ target, format });

ARKit.snapshot = addDefaultsToSnapShotFunc("snapshot");
ARKit.snapshotCamera = addDefaultsToSnapShotFunc("snapshotCamera");
ARKit.snapshot = addDefaultsToSnapShotFunc('snapshot');
ARKit.snapshotCamera = addDefaultsToSnapShotFunc('snapshotCamera');

ARKit.exportModel = presetId => {
const id = presetId || generateId();
Expand Down Expand Up @@ -197,6 +196,8 @@ ARKit.propTypes = {
onTapOnPlaneUsingExtent: PropTypes.func,
onTapOnPlaneNoExtent: PropTypes.func,
onEvent: PropTypes.func,
isMounted: PropTypes.func,
isInitialized: PropTypes.func,
};

const RCTARKit = requireNativeComponent('RCTARKit', ARKit);
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ These steps are mandatory regardless of doing a manual or automatic installation
2. ARKit only runs on arm64-ready devices so the default build architecture should be set to arm64: go to `Build settings` ➜ `Build Active Architecture Only` and change the value to `Yes`.




## Usage

A simple sample React Native ARKit App
Expand Down Expand Up @@ -83,6 +85,7 @@ export default class ReactNativeARKit extends Component {
onPlaneDetected={console.log} // event listener for plane detection
onPlaneUpdate={console.log} // event listener for plane update
onPlaneRemoved={console.log} // arkit sometimes removes detected planes
onARKitError={console.log} // if arkit could not be initialized (e.g. missing permissions), you will get notified here
>
<ARKit.Box
position={{ x: 0, y: 0, z: 0 }}
Expand Down Expand Up @@ -219,7 +222,7 @@ The `Plane` object has the following properties:

##### Static methods

All methods return a promise with the result.
All methods return a *promise* with the result.

| Method Name | Arguments | Notes
|---|---|---|
Expand All @@ -232,7 +235,8 @@ All methods return a promise with the result.
| `focusScene` | | Sets the scene's position/rotation to where it was when first rendered (but now relative to your device's current position/rotation) |
| `hitTestPlanes` | point, type | check if a plane has ben hit by point (`{x,y}`) with detection type (any of `ARKit.ARHitTestResultType`). See https://developer.apple.com/documentation/arkit/arhittestresulttype?language=objc for further information |
| `hitTestSceneObjects` | point | check if a scene object has ben hit by point (`{x,y}`) |

| `isInitialized` | boolean | check whether arkit has been initialized (e.g. by mounting). See https://github.com/HippoAR/react-native-arkit/pull/152 for details |
| `isMounted` | boolean | check whether arkit has been mounted. See https://github.com/HippoAR/react-native-arkit/pull/152 for details |

#### 3D objects

Expand Down Expand Up @@ -538,6 +542,21 @@ E.gl you have several "walls" with ids "wall_1", "wall_2", etc.
It uses https://developer.apple.com/documentation/scenekit/scnscenerenderer/1522929-hittest with some default options. Please file an issue or send a PR if you need more control over the options here!


## FAQ:

#### Which permissions does this use?

- **camera access** (see section iOS Project configuration above). The user is asked for permission, as soon as you mount an `<ARKit />` component or use any of its API. If user denies access, you will get an error in `onARKitError`
- **location service**: only needed if you use `ARKit.ARWorldAlignment.GravityAndHeading`.

#### Is there an Android / ARCore version?

Not yet, but there has been a proof-of-concept: https://github.com/HippoAR/react-native-arkit/issues/14. We are looking for contributors to help backporting this proof-of-conept to react-native-arkit.

#### I have another question...

[**Join Slack!**](https://join.slack.com/t/react-native-ar/shared_invite/enQtMjUzMzg3MjM0MTQ5LWU3Nzg2YjI4MGRjMTM1ZDBlNmIwYTE4YmM0M2U0NmY2YjBiYzQ4YzlkODExMTA0NDkwMzFhYWY4ZDE2M2Q4NGY)


## Contributing

Expand Down
4 changes: 2 additions & 2 deletions ios/RCTARKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
@interface RCTARKit : UIView

+ (instancetype)sharedInstance;
+ (bool)isInitialized;
- (instancetype)initWithARView:(ARSCNView *)arView;


Expand Down Expand Up @@ -72,8 +73,7 @@ typedef void (^RCTARKitReject)(NSString *code, NSString *message, NSError *error
- (NSDictionary *)readCamera;
- (NSDictionary* )getCurrentLightEstimation;
- (NSArray * )getCurrentDetectedFeaturePoints;


- (bool)isMounted;

#pragma mark - Delegates
- (void)renderer:(id <SCNSceneRenderer>)renderer didRenderScene:(SCNScene *)scene atTime:(NSTimeInterval)time;
Expand Down
15 changes: 14 additions & 1 deletion ios/RCTARKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ void dispatch_once_on_main_thread(dispatch_once_t *predicate,


@implementation RCTARKit
static RCTARKit *instance = nil;

+ (bool)isInitialized {
return instance !=nil;
}

+ (instancetype)sharedInstance {
static RCTARKit *instance = nil;

static dispatch_once_t onceToken;

dispatch_once_on_main_thread(&onceToken, ^{
Expand All @@ -47,9 +52,15 @@ + (instancetype)sharedInstance {
instance = [[self alloc] initWithARView:arView];
}
});

return instance;
}

- (bool)isMounted {

return self.superview != nil;
}

- (instancetype)initWithARView:(ARSCNView *)arView {
if ((self = [super init])) {
self.arView = arView;
Expand Down Expand Up @@ -85,6 +96,8 @@ - (instancetype)initWithARView:(ARSCNView *)arView {
return self;
}



- (void)layoutSubviews {
[super layoutSubviews];
//NSLog(@"setting view bounds %@", NSStringFromCGRect(self.bounds));
Expand Down
13 changes: 13 additions & 0 deletions ios/RCTARKitManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ - (NSDictionary *)constantsToExport
resolve(@{});
}

RCT_EXPORT_METHOD(isInitialized:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
resolve(@([ARKit isInitialized]));
}

RCT_EXPORT_METHOD(isMounted:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
if( [ARKit isInitialized]) {
dispatch_async(dispatch_get_main_queue(), ^{
resolve(@([[ARKit sharedInstance] isMounted]));
});
} else {
resolve(@(NO));
}
}

RCT_EXPORT_METHOD(
hitTestPlanes: (NSDictionary *)pointDict
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/HippoAR/react-native-arkit.git"
},
"version": "0.8.0",
"version": "0.9.0-beta.0",
"description": "React Native binding for iOS ARKit",
"author": "Zehao Li <qft.gtr@gmail.com>",
"license": "MIT",
Expand Down
7 changes: 6 additions & 1 deletion startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ export default () => {
// when reloading the app, the scene should be cleared.
// on prod, this usually does not happen, but you can reload the app in develop mode
// without clearing, this would result in inconsistency
ARKitManager.clearScene();
// do this only when arkit was already initialized
ARKitManager.isInitialized().then(isInitialized => {
if (isInitialized) {
ARKitManager.clearScene();
}
});
};