pol6880
pol6880

Reputation: 151

Adding Google Cardboard SDK to a React Native project

I'm currently working on a React Native application that amongst other things, it needs to show a panorama using the Google Cardboard SDK. I seem to have most of the things set up but given my very limited knowledge on Objective-C, I am not able to connect all ports of the puzzle.

Currently, I have my javascript connecting with objective-c so that's all fine however, looking at the example code in the Cardboard SDK, a PanoramaViewController of type UIViewController is defined and the necessary elements of the page (text, actual panorama viewer, etc) are added to the view using something like:

[_scrollView addSubview:_panoView];

In my case, given that i am defining my ViewController with type NSObject RCTBridgeModule, if I understand correctly, I am not able to do this, unless i'm not missing something else.

I've been looking around to try and find what's the best way of going about this and what I found was something along these lines:

UIViewController *rootController = UIApplication.sharedApplication.delegate.window.rootViewController;
[rootController presentViewController:MyViewController animated:YES completion:nil];

In the above, I don't know what exactly do I have to pass instead of MyViewController given that to my understanding, the Cardboard SDK only creates the view and I am responsible of creating the actual ViewController.

At the moment, this is how my ViewController.h looks like:

#import <Foundation/Foundation.h>
#import "RCTBridge.h"

@interface GCViewController : NSObject <RCTBridgeModule>

@end

and this is how my ViewController.m looks like:

#import "GCViewController.h"
#import "AppDelegate.h"
#import "RCTLog.h"
#import "GCSPanoramaView.h"

@interface GCViewController ()<GCSWidgetViewDelegate>
@end

@implementation GCViewController {
    GCSPanoramaView *_panoView;
}

RCT_EXPORT_MODULE();

-(void)show360Video {

    _panoView = [[GCSPanoramaView alloc] init];
    _panoView.delegate = self;
    _panoView.enableFullscreenButton = YES;
    _panoView.enableCardboardButton = YES;
    [_panoView loadImage:[UIImage imageNamed:@"test.jpg"]
            ofType:kGCSPanoramaImageTypeMono];

    UIViewController *rootController = UIApplication.sharedApplication.delegate.window.rootViewController;
    [rootController presentViewController:XXXXXX animated:YES completion:nil];

}

RCT_EXPORT_METHOD(showVideo) {
    [self show360Video];
}

@end

I would appreciate if anyone can help me on this. Thanks!

PS: in this project i'm using the Google Cardboard v0.7.2 and not the new Google VR library.

Upvotes: 2

Views: 949

Answers (1)

Ankit Singhania
Ankit Singhania

Reputation: 1

You can use rootController Which is defined before that error.Thanks

Upvotes: 0

Related Questions