All Projects → birkir → React Native Carplay

birkir / React Native Carplay

CarPlay with React Native

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Native Carplay

vue-smooth-height
Transition an elements height in response to data changes
Stars: ✭ 40 (-87.54%)
Mutual labels:  auto
Phnt
Native API header files for the Process Hacker project.
Stars: ✭ 276 (-14.02%)
Mutual labels:  native
Stevia
🍃 Concise Autolayout code
Stars: ✭ 3,182 (+891.28%)
Mutual labels:  auto
Common
A set of common utils for consuming Web APIs with Angular
Stars: ✭ 259 (-19.31%)
Mutual labels:  native
React Native Mmkv Storage
An Efficient(0.0002s read/write), small & encrypted mobile key-value storage framework for React Native
Stars: ✭ 273 (-14.95%)
Mutual labels:  native
Nat
A powerful kit for adding native functionalities to your weex app.
Stars: ✭ 294 (-8.41%)
Mutual labels:  native
ghostscript4js
Ghostscript4JS binds the Ghostscript C API to the Node.JS world.
Stars: ✭ 53 (-83.49%)
Mutual labels:  native
React Native Dom
An experimental, comprehensive port of React Native to the web.
Stars: ✭ 3,247 (+911.53%)
Mutual labels:  native
Onova
Unopinionated auto-update framework for desktop applications
Stars: ✭ 280 (-12.77%)
Mutual labels:  auto
Pyupdater
Pyinstaller auto-update library
Stars: ✭ 300 (-6.54%)
Mutual labels:  auto
Node Window Manager
Manage windows in Windows, macOS and Linux using Node.js
Stars: ✭ 263 (-18.07%)
Mutual labels:  native
Android Camera2 Secret Picture Taker
Take pictures 📷 secretly (without preview or launching device's camera app) using Android CAMERA2 API
Stars: ✭ 275 (-14.33%)
Mutual labels:  native
Croppr.js
A vanilla JavaScript image cropper that's lightweight, awesome, and has absolutely zero dependencies.
Stars: ✭ 294 (-8.41%)
Mutual labels:  native
libvlc-nuget
NuGet packaging setup for LibVLC
Stars: ✭ 52 (-83.8%)
Mutual labels:  native
Babylonnative
Build cross-platform native applications with the power of the Babylon.js JavaScript framework
Stars: ✭ 299 (-6.85%)
Mutual labels:  native
PttAutoPush
PTT自動推文 推文機器人(Python)
Stars: ✭ 15 (-95.33%)
Mutual labels:  auto
Javapackager
📦 Gradle/Maven plugin to package Java applications as native Windows, Mac OS X, or GNU/Linux executables and create installers for them.
Stars: ✭ 285 (-11.21%)
Mutual labels:  native
Youxiang
获取淘宝优惠券、京东优惠券、拼多多(多多客)优惠券、苏宁易购优惠券、唯品会优惠券,通过接入淘宝联盟、京东联盟、拼多多(多多进宝)、苏宁联盟(苏宁推客)、唯品会及其对应的开放平台,获取优惠商品图片和对应商品信息,利用微信机器人推送到指定群聊。
Stars: ✭ 313 (-2.49%)
Mutual labels:  auto
Nut.js
Native UI testing / controlling with node
Stars: ✭ 309 (-3.74%)
Mutual labels:  native
Blog
📖 个人博客,分享一些前端工作学习中的收获,欢迎 ✨,博客地址>>
Stars: ✭ 297 (-7.48%)
Mutual labels:  native

CarPlay with React Native

What if you could create CarPlay with React Native. Well, now you can.

Animated Demo

Support

This version of react-native-carplay supports iOS 14. If you need support for versions before this please refer to version 1.3.1 of this package.

CarPlay Entitlement and XCode Project Setup

Read this section if you are new to CarPlay!

One of the most useful resources for undertanding the requirements, constraints and capabilities of CarPlay apps is the official App Programming Guidelines from Apple. It's a 50-page document that clearly lays out steps required and you are strongly encouraged to read it if you are new to CarPlay. Further to the above guide, when developing a CarPlay app or if contributing to this package; you'll find the CarPlay Documentation invaluable.

You can develop CarPlay capabilities with this project without waiting for Apple to send you back an entitlement, through the simulator.

If you want to build and run your app on an iPhone or share it with others through the App Store Connect or TestFlight, you will need to request a CarPlay entitlement from Apple first. The process will take anywhere from a few days to weeks - your mileage will vary. This depends on the type of Entitlement you are requesting. If you are part of the MFi program, this may help speed things up too. You then need to add the entitlement to your provisioning profile or signing certificate that you use for signing your app in XCode.

You can go to this Apple CarPlay entitlement request page to request a CarPlay Entitlement. You need to be logged in with an Apple Developer account.

To start a CarPlay simulator in XCode, within the Simulator window, go to the menu option IO, click on External Displays, then select CarPlay.

NB:

Whether you are running through a simulator or building the app for distribution, you need to ensure that the correct entitlement key is added in your Entitlements.plist file. If you don't have an Entitlements.plist file, create one in your iOS/ directory.

Installing

  1. Install the library
yarn add react-native-carplay --save
  1. Link using normal or cocoapods method
react-native link react-native-carplay
# in ios/Podfile:

pod 'react-native-carplay', path: '../node_modules/react-native-carplay'
  1. Edit your AppDelegate
// AppDelegate.h

// [step 1] add this line to the top
#import <CarPlay/CarPlay.h>

// [step 2] add the "CPApplicationDelegate" to the end, before ">":
@interface AppDelegate : UIResponder <UIApplicationDelegate, CPApplicationDelegate>
// AppDelegate.m

// [step 1] add this line to the top
#import <RNCarPlay.h>

// ...

// [step 2] add the following two methods before @end

- (void)application:(UIApplication *)application didConnectCarInterfaceController:(CPInterfaceController *)interfaceController toWindow:(CPWindow *)window {
  [RNCarPlay connectWithInterfaceController:interfaceController window:window];
}

- (void)application:(nonnull UIApplication *)application didDisconnectCarInterfaceController:(nonnull CPInterfaceController *)interfaceController fromWindow:(nonnull CPWindow *)window {
  [RNCarPlay disconnect];
}

@end

Basic Usage

See full example

The exported CarPlay class gives you the API needed to add / remove templates from the CarPlay view hierarchy.

import { CarPlay, GridTemplate } from 'react-native-carplay';

const template = new GridTemplate({
  title: 'Hello, World',
  buttons: [],
});

CarPlay.setRootTemplate(template);

Connect / Disconnect

When working with CarPlay it is important to detect and respond to the connect / disconnect events. The CarPlay class provides both a connected boolean and an on connect / disconnect event you can register a callback to.

When you are creating and displaying a template within your existing app screens you may want to ensure CarPlay is connected before calling any carplay apis. This can be done within a useEffect.

useEffect(() => {
  function onConnect() {
    // Do things now that carplay is connected
  }

  function onDisconnect() {
    // Do things now that carplay is disconnected
  }

  CarPlay.registerOnConnect(onConnect);
  CarPlay.registerOnDisconnect(onDisconnect);

  return () => {
    CarPlay.unregisterOnConnect(onConnect);
    CarPlay.unregisterOnDisconnect(onDisconnect);
  };
});

CarPlay API

CarPlay.setRootTemplate

Sets the root template of CarPlay. This must be called before running any other CarPlay commands. Can be called multiple times.

CarPlay.setRootTemplate(template, /* animated */ false);

CarPlay.pushTemplate

Pushes a new template to the navigation stack. Note you cannot push the same template twice.

CarPlay.pushTemplate(template, /* animated */ true);

CarPlay.popTemplate

Pop currently presented template from the stack.

CarPlay.popTemplate(/* animated */ false);

CarPlay.popToTemplate

Pop currently presented template from the stack to a specific template. The template must be in the stack.

CarPlay.popToTemplate(template, /* animated */ false);

CarPlay.popToRoot

Pop the stack to root template.

CarPlay.popToRoot(/* animated */ false);

Templates

Templates are used to render contents on the CarPlay screen from your app. Details of the templates supported by apple can be found in the developer guide

MapTemplate

Map Template Map Template

import { CarPlay } from 'react-native-carplay';

const mapTemplate = new MapTemplate({
  component: /* react native view */ MapView,
  onAlertActionPressed(e) {
    console.log(e);
  },
  onStartedTrip({ tripId, routeIndex }) {
    // start your navigation code
    onStartNavigation(routeIndex);
  },
});

CarPlay.setRootTemplate(mapTemplate);

ListTemplate

List Template

import { CarPlay } from 'react-native-carplay';

const listTemplate = new ListTemplate({
  sections: [],
  title: 'List Template',
  async onItemSelect({ index }) {
    // use the selected index
    setSelected(index);
  },
});

CarPlay.pushTemplate(listTemplate, true);

InformationTemplate

Information Template

import { CarPlay } from 'react-native-carplay';

const informationTemplate = new InformationTemplate({
  title: 'Information',
  items: [],
  actions: [{ id: 'x', title: 'demo' }],
  onActionButtonPressed({ id }) {
    // id of button pressed
    console.log('pressed', id);
  },
});

CarPlay.pushTemplate(informationTemplate);

GridTemplate

Grid Template

import { CarPlay } from 'react-native-carplay';

const gridTemplate = new GridTemplate({
  trailingNavigationBarButtons: [],
  buttons: [
    {
      id: 'List',
      titleVariants: ['List'],
      image: listImage,
    },
    {
      id: 'Grid',
      titleVariants: ['Grid'],
      image: gridImage,
    },
  ],
  title: 'Grid Template',
  onButtonPressed({ id }) {
    // id of button pressed
    setSelected(id);
  },
  onBarButtonPressed({ id }) {
    // id of bar button pressed
    setSelected(id);
  },
});

CarPlay.pushTemplate(gridTemplate, true);

SearchTemplate

Search Template

const searchTemplate = new SearchTemplate({
  async onSearch(query) {
    // use the query to search
    // and return item array
    return performSearch(query);
  },
  async onItemSelect({ index }) {
    // index of the selected item
    setSelected(index);
  },
  onSearchButtonPressed() {
    // on search button pressed, should display
    // list template with results
    navigation.navigate('List');
  },
});

CarPlay.pushTemplate(searchTemplate, true);

VoiceTemplate

Voice Template

This template is presented via CarPlay.presentTemplate. In order to implement voice recognition, take a look at the @react-native-voice/voice package.

const voiceControlTemplate = new VoiceControlTemplate({
  // pass the control states
  voiceControlStates: [
    {
      identifier: 'TEST',
      image: require('../images/cat.jpg'),
      repeats: true,
      titleVariants: ['Searching...'],
    },
  ],
});

CarPlay.presentTemplate(voiceControlTemplate, true);

AlertTemplate

Alert Template

This template is presented via CarPlay.presentTemplate.

const alertTemplate = new AlertTemplate({
  titleVariants: ['Hello world'],
  actions: [
    {
      id: 'ok',
      title: 'Ok',
    },
    {
      id: 'remove',
      title: 'Remove',
      style: 'destructive',
    },
  ],
  onActionButtonPressed({ id }) {
    // id of the pressed button
    if (id === 'remove') {
      // presentable templates can be
      // dismissed
      CarPlay.dismissTemplate();
    }
  },
});

CarPlay.presentTemplate(alertTemplate);

ActionSheetTemplate

ActionSheet Template

This template is presented via CarPlay.presentTemplate.

const actionSheetTemplate = new ActionSheetTemplate({
  title: 'Example',
  message: 'This is an message for you',
  actions: [
    {
      id: 'ok',
      title: 'Ok',
    },
    {
      id: 'remove',
      title: 'Remove',
      style: 'destructive',
    },
  ],
  onActionButtonPressed({ id }) {
    // the id of the button pressed
  },
});

CarPlay.presentTemplate(actionSheetTemplate);

TabTemplate

Tab Template

This template must be set as the root template and cannot be pushed on top of other templates.

const template1 = new ListTemplate({
  sections: [
    {
      header: 'Test 1',
      items: [{ text: 'Hello world 1' }],
    },
  ],
  title: 'AA',
});
const template2 = new ListTemplate({
  sections: [
    {
      header: 'Test 2',
      items: [{ text: 'Hello world 3' }],
    },
  ],
  title: 'BB',
});

const tabBarTemplate = new TabBarTemplate({
  templates: [template1, template2],
  onTemplateSelect(e: any) {
    console.log('selected', e);
  },
});

CarPlay.setRootTemplate(tabBarTemplate);

Example App

A working example app can be found here.

To run it you must first install dependencies and pods.

  1. install dependencies and build react-native-carplay
yarn install
  1. move to example dir and install dependencies
cd example
yarn install
  1. run build dev in root dir, this will copy the output to the examples node modules.
cd ..
yarn build:dev
  1. install pods in example app and start the metro bundler
cd example/ios
pod install
yarn start
  1. start xcode and run the project on your simulator or device

Not working / In progress

UI Elements

  • [ ] Contact Template
  • [ ] Now Playing Template
  • [ ] Point of Interest Template

Getters

  • [ ] topTemplate
  • [ ] rootTemplate
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].