forked from birkir/react-native-carplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
3,344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#import <CoreLocation/CoreLocation.h> | ||
#import <MapKit/MapKit.h> | ||
#import <CarPlay/CarPlay.h> | ||
#import <React/RCTConvert.h> | ||
|
||
@interface RCTConvert (RNCarPlay) | ||
|
||
+ (CPTripEstimateStyle)CPTripEstimateStyle:(id)json; | ||
+ (CPPanDirection)CPPanDirection:(id)json; | ||
+ (CPAssistantCellPosition)CPAssistantCellPosition:(id)json; | ||
+ (CPAssistantCellVisibility)CPAssistantCellVisibility:(id)json; | ||
+ (CPAssistantCellActionType)CPAssistantCellActionType:(id)json; | ||
+ (CPMapButton*)CPMapButton:(id)json withHandler:(void (^)(CPMapButton * _Nonnull mapButton))handler; | ||
+ (CPRouteChoice*)CPRouteChoice:(id)json; | ||
+ (MKMapItem*)MKMapItem:(id)json; | ||
+ (CPPointOfInterest*)CPPointOfInterest:(id)json; | ||
+ (CPAlertActionStyle)CPAlertActionStyle:(id)json; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#import "RCTConvert+RNCarPlay.h" | ||
#import <React/RCTConvert+CoreLocation.h> | ||
#import <Availability.h> | ||
|
||
@implementation RCTConvert (RNCarPlay) | ||
|
||
RCT_ENUM_CONVERTER(CPTripEstimateStyle, (@{ | ||
@"light": @(CPTripEstimateStyleLight), | ||
@"dark": @(CPTripEstimateStyleDark) | ||
}), | ||
CPTripEstimateStyleDark, | ||
integerValue) | ||
|
||
RCT_ENUM_CONVERTER(CPPanDirection, (@{ | ||
@"up": @(CPPanDirectionUp), | ||
@"right": @(CPPanDirectionRight), | ||
@"bottom": @(CPPanDirectionDown), | ||
@"left": @(CPPanDirectionLeft), | ||
@"none": @(CPPanDirectionNone) | ||
}), CPPanDirectionNone, integerValue) | ||
|
||
RCT_ENUM_CONVERTER(CPAssistantCellPosition, (@{ | ||
@"top": @(CPAssistantCellPositionTop), | ||
@"bottom": @(CPAssistantCellPositionBottom) | ||
}), CPAssistantCellPositionTop, integerValue) | ||
|
||
RCT_ENUM_CONVERTER(CPAssistantCellVisibility, (@{ | ||
@"off": @(CPAssistantCellVisibilityOff), | ||
@"always": @(CPAssistantCellVisibilityAlways), | ||
@"limited": @(CPAssistantCellVisibilityWhileLimitedUIActive) | ||
}), CPAssistantCellVisibilityOff, integerValue) | ||
|
||
RCT_ENUM_CONVERTER(CPAssistantCellActionType, (@{ | ||
@"playMedia": @(CPAssistantCellActionTypePlayMedia), | ||
@"startCall": @(CPAssistantCellActionTypeStartCall) | ||
}), CPAssistantCellActionTypeStartCall, integerValue) | ||
|
||
|
||
+ (CPMapButton*)CPMapButton:(id)json withHandler:(void (^)(CPMapButton * _Nonnull mapButton))handler { | ||
CPMapButton *mapButton = [[CPMapButton alloc] initWithHandler:handler]; | ||
|
||
if ([json objectForKey:@"image"]) { | ||
[mapButton setImage:[RCTConvert UIImage:json[@"image"]]]; | ||
} | ||
|
||
if ([json objectForKey:@"focusedImage"]) { | ||
[mapButton setImage:[RCTConvert UIImage:json[@"focusedImage"]]]; | ||
} | ||
|
||
if ([json objectForKey:@"disabled"]) { | ||
[mapButton setEnabled:![RCTConvert BOOL:json[@"disabled"]]]; | ||
} | ||
|
||
if ([json objectForKey:@"hidden"]) { | ||
[mapButton setHidden:[RCTConvert BOOL:json[@"hidden"]]]; | ||
} | ||
|
||
return mapButton; | ||
} | ||
|
||
+ (MKMapItem*)MKMapItem:(id)json { | ||
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([RCTConvert double:json[@"latitude"]], [RCTConvert double:json[@"longitude"]]); | ||
NSString *name = [RCTConvert NSString:json[@"name"]]; | ||
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate]; | ||
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; | ||
mapItem.name = name; | ||
return mapItem; | ||
} | ||
|
||
+ (CPRouteChoice*)CPRouteChoice:(id)json { | ||
return [[CPRouteChoice alloc] initWithSummaryVariants:[RCTConvert NSStringArray:json[@"additionalInformationVariants"]] additionalInformationVariants:[RCTConvert NSStringArray:json[@"selectionSummaryVariants"]] selectionSummaryVariants:[RCTConvert NSStringArray:json[@"summaryVariants"]]]; | ||
} | ||
|
||
+ (CPPointOfInterest*)CPPointOfInterest:(id)json { | ||
MKMapItem *location = [RCTConvert MKMapItem:json[@"location"]]; | ||
NSString *title = [RCTConvert NSString:json[@"title"]]; | ||
NSString *subtitle = [RCTConvert NSString:json[@"subtitle"]]; | ||
NSString *summary = [RCTConvert NSString:json[@"summary"]]; | ||
NSString *detailTitle = [RCTConvert NSString:json[@"detailTitle"]]; | ||
NSString *detailSubtitle = [RCTConvert NSString:json[@"detailSubtitle"]]; | ||
NSString *detailSummary = [RCTConvert NSString:json[@"detailSummary"]]; | ||
|
||
CPPointOfInterest *poi = [[CPPointOfInterest alloc] initWithLocation:location title:title subtitle:subtitle summary:summary detailTitle:detailTitle detailSubtitle:detailSubtitle detailSummary:detailSummary pinImage:nil]; | ||
return poi; | ||
} | ||
|
||
+ (CPAlertActionStyle)CPAlertActionStyle:(NSString*) json { | ||
if ([json isEqualToString:@"cancel"]) { | ||
return CPAlertActionStyleCancel; | ||
} else if ([json isEqualToString:@"destructive"]) { | ||
return CPAlertActionStyleDestructive; | ||
} | ||
return CPAlertActionStyleDefault; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <CarPlay/CarPlay.h> | ||
|
||
@interface RNCPStore : NSObject { | ||
CPInterfaceController *interfaceController; | ||
CPWindow *window; | ||
} | ||
|
||
@property (nonatomic, retain) CPInterfaceController *interfaceController; | ||
@property (nonatomic, retain) CPWindow *window; | ||
|
||
+ (id)sharedManager; | ||
- (CPTemplate*) findTemplateById: (NSString*)templateId; | ||
- (NSString*) setTemplate:(NSString*)templateId template:(CPTemplate*)carPlayTemplate; | ||
- (CPTrip*) findTripById: (NSString*)tripId; | ||
- (NSString*) setTrip:(NSString*)tripId trip:(CPTrip*)trip; | ||
- (CPNavigationSession*) findNavigationSessionById:(NSString*)navigationSessionId; | ||
- (NSString*) setNavigationSession:(NSString*)navigationSessionId navigationSession:(CPNavigationSession*)navigationSession; | ||
- (Boolean) isConnected; | ||
- (void) setConnected:(Boolean) isConnected; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#import "RNCPStore.h" | ||
|
||
@implementation RNCPStore { | ||
NSMutableDictionary* _templatesStore; | ||
NSMutableDictionary* _navigationSessionsStore; | ||
NSMutableDictionary* _tripsStore; | ||
Boolean _connected; | ||
} | ||
|
||
@synthesize window; | ||
@synthesize interfaceController; | ||
|
||
-(instancetype)init { | ||
if (self = [super init]) { | ||
_templatesStore = [[NSMutableDictionary alloc] init]; | ||
_navigationSessionsStore = [[NSMutableDictionary alloc] init]; | ||
_tripsStore = [[NSMutableDictionary alloc] init]; | ||
_connected = false; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
+ (RNCPStore*) sharedManager { | ||
static RNCPStore *shared = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
shared = [[self alloc] init]; | ||
}); | ||
return shared; | ||
} | ||
|
||
- (void) setConnected:(Boolean) isConnected { | ||
_connected = isConnected; | ||
} | ||
|
||
- (Boolean) isConnected { | ||
return _connected; | ||
} | ||
|
||
- (CPTemplate*) findTemplateById:(NSString*)templateId { | ||
return [_templatesStore objectForKey:templateId]; | ||
} | ||
|
||
- (NSString*) setTemplate:(NSString*)templateId template:(CPTemplate*)carPlayTemplate { | ||
[_templatesStore setObject:carPlayTemplate forKey:templateId]; | ||
return templateId; | ||
} | ||
|
||
- (CPTrip*) findTripById:(NSString*)tripId { | ||
return [_tripsStore objectForKey:tripId]; | ||
} | ||
|
||
- (NSString*) setTrip:(NSString*)tripId trip:(CPTrip*)trip { | ||
[_tripsStore setObject:trip forKey:tripId]; | ||
return tripId; | ||
} | ||
|
||
- (CPNavigationSession*) findNavigationSessionById:(NSString*)navigationSessionId { | ||
return [_navigationSessionsStore objectForKey:navigationSessionId]; | ||
} | ||
|
||
- (NSString*) setNavigationSession:(NSString*)navigationSessionId navigationSession:(CPNavigationSession*)navigationSession { | ||
[_navigationSessionsStore setObject:navigationSession forKey:navigationSessionId]; | ||
return navigationSessionId; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <CarPlay/CarPlay.h> | ||
#import <React/RCTBridgeModule.h> | ||
#import <React/RCTEventEmitter.h> | ||
#import "RCTConvert+RNCarPlay.h" | ||
#import "RNCPStore.h" | ||
|
||
typedef void(^SearchResultUpdateBlock)(NSArray<CPListItem *> * _Nonnull); | ||
typedef void(^SelectedResultBlock)(void); | ||
|
||
@interface RNCarPlay : RCTEventEmitter<RCTBridgeModule, CPInterfaceControllerDelegate, CPSearchTemplateDelegate, CPListTemplateDelegate, CPMapTemplateDelegate, CPTabBarTemplateDelegate, CPPointOfInterestTemplateDelegate, CPNowPlayingTemplateObserver> { | ||
CPInterfaceController *interfaceController; | ||
CPWindow *window; | ||
SearchResultUpdateBlock searchResultBlock; | ||
SelectedResultBlock selectedResultBlock; | ||
BOOL isNowPlayingActive; | ||
} | ||
|
||
@property (nonatomic, retain) CPInterfaceController *interfaceController; | ||
@property (nonatomic, retain) CPWindow *window; | ||
@property (nonatomic, copy) SearchResultUpdateBlock searchResultBlock; | ||
@property (nonatomic, copy) SelectedResultBlock selectedResultBlock; | ||
@property (nonatomic) BOOL isNowPlayingActive; | ||
|
||
+ (void) connectWithInterfaceController:(CPInterfaceController*)interfaceController window:(CPWindow*)window; | ||
+ (void) disconnect; | ||
- (NSArray<CPListSection*>*) parseSections:(NSArray*)sections; | ||
|
||
@end |
Oops, something went wrong.