Skip to content

Commit

Permalink
Merge pull request #173 from susonthapa/feat/add-full-screen-support
Browse files Browse the repository at this point in the history
added full screen support on CarPlay Map template
  • Loading branch information
birkir authored May 21, 2024
2 parents 2af9a39 + 32ad919 commit 4e9ffa3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/react-native-carplay/ios/RNCarPlay.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "RNCarPlay.h"
#import "RNCarPlayViewController.h"
#import <React/RCTConvert.h>
#import <React/RCTRootView.h>

Expand Down Expand Up @@ -44,7 +45,7 @@ + (void) disconnect {
RNCarPlay *cp = [RNCarPlay allocWithZone:nil];
RNCPStore *store = [RNCPStore sharedManager];
[store setConnected:false];
[[store.window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
store.window.rootViewController = nil;

if (cp.bridge) {
[cp sendEventWithName:@"didDisconnect" body:@{}];
Expand Down Expand Up @@ -887,9 +888,8 @@ - (void) applyConfigForMapTemplate:(CPMapTemplate*)mapTemplate templateId:(NSStr

if ([config objectForKey:@"render"]) {
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:templateId initialProperties:@{}];
[rootView setFrame:store.window.frame];
[[store.window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[store.window addSubview:rootView];
RNCarPlayViewController *viewController = [[RNCarPlayViewController alloc] initWithRootView:rootView];
store.window.rootViewController = viewController;
}
}

Expand Down
10 changes: 10 additions & 0 deletions packages/react-native-carplay/ios/RNCarPlayViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// RNCarPlayViewController.h
// Created by Susan Thapa on 27/02/2024.
//
#import <UIKit/UIKit.h>
#import <React/RCTRootView.h>

@interface RNCarPlayViewController : UIViewController
- (instancetype)initWithRootView:(RCTRootView *)rootView;
@end
50 changes: 50 additions & 0 deletions packages/react-native-carplay/ios/RNCarPlayViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// RNCarPlayViewController.m
// react-native-carplay
//
// Created by Susan Thapa on 27/02/2024.
//

#import <Foundation/Foundation.h>
#import "RNCarPlayViewController.h"
#import <React/RCTRootView.h>

@interface RNCarPlayViewController ()

@property (nonatomic, strong) RCTRootView *rootView;

@end

@implementation RNCarPlayViewController

- (instancetype)initWithRootView:(RCTRootView *)rootView {
self = [super init];
if (self) {
_rootView = rootView;
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = false;
if (self.rootView) {
self.rootView.translatesAutoresizingMaskIntoConstraints = false;
self.rootView.frame = self.view.bounds;
[self.view addSubview:self.rootView];

[NSLayoutConstraint activateConstraints:@[
[self.rootView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[self.rootView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
[self.rootView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[self.rootView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
]];
}
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.rootView.frame = self.view.bounds;
}

@end
8 changes: 7 additions & 1 deletion packages/react-native-carplay/src/CarPlay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ImageSourcePropType, NativeEventEmitter, NativeModule, NativeModules, Platform } from 'react-native';
import {
ImageSourcePropType,
NativeEventEmitter,
NativeModule,
NativeModules,
Platform,
} from 'react-native';
import { ActionSheetTemplate } from './templates/ActionSheetTemplate';
import { AlertTemplate } from './templates/AlertTemplate';
import { ContactTemplate } from './templates/ContactTemplate';
Expand Down

0 comments on commit 4e9ffa3

Please sign in to comment.