Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
implement isInitialized and isMounted
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozone authored and bnjm committed Feb 21, 2018
1 parent cb3b6e2 commit 652e5b4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
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
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 @@ -139,6 +139,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
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();
ARKitManager.isInitialized().then(isInitialized => {
console.log('was already initialized on startup', isInitialized);
if (isInitialized) {
ARKitManager.clearScene();
}
});
};

0 comments on commit 652e5b4

Please sign in to comment.