Giter Site home page Giter Site logo

grabbou / react-bmw Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 0.0 186 KB

Sheer development pleasure with React and Online Apps Platform

Home Page: https://labs.bmw.com

License: MIT License

TypeScript 91.58% HTML 8.42%
react bmw idrive connected-car

react-bmw's Introduction

This is a React renderer for BMW OAP apps that helps creating awesome UI with minimal effort.

Getting started

Install this package from private Github registry:

$ npm install @grabbou/[email protected]

Note: Make sure to have it configured before installing. Otherwise, you will receive a 404 error as this package is not publicly available due to security concerns.

Usage

Import the package directly from your app and create your first component:

import React from 'react';
import * as ReactBMW from 'react-bmw';

const MainApp = (
  <Scene>
    <Body>
      <Text>Hello world!</Text>
    </Body>
  </Scene>
);

ReactBMW.render(<MainApp />, '$$yourUUIDgoesHere');

Motivation

The purpose of this project is to make development of the OAP easy and enjoyable using a consistent developer experience based on JavaScript and React.

We found that the implementation of UI is a real challenge for newbies (maybe not only for newbies :) ). There are HMI, XML and JSON files that represent the same UI. We decided to try to make it easier with well known library - React. Thanks to that we are able to building user interfaces declaratively by breaking them into reusable components and generate needed files for OAP.

What are the advantages:

  • The declarative nature of components promotes predictability
  • By unifying your markup with its corresponding view logic, React can actually make views easier to extend and maintain
  • Promotes reusability of the already created UI components
  • Reduces time spent on creating layouts
  • Opens possibility to write apps in well known and documented library
  • Faster development loop with in-browser emulator and layout debugger
  • Cross-platform by default, allows to run same code on the browser, mobile and different iDrive systems
  • Significant performance improvements with batched updates
  • Automatic component resolution - no more getting elements by their IDs and keeping them in sync

How does it work?

React builds in-memory representation of the application tree which is then projected onto xml and json files that are needed for BMW. This happens during the build step and is known as "server-side rendering" on the web.

During runtime, React executes the application logic and registers handlers, listening for changes and making sure the updates are delivered in the most performant way possible.

React code

Please find a sample Scene component below. Please note that the naming is different from BMW internal nomenclature, that is, we have Scene, Body, Text and Button instead of LayoutGroup, Container and Component. This is a concept heavily borrowed from the semantic web.

<Scene>
  <Body>
    <Text>React</Text>
    <Text>Is</Text>
    <Text>Really</Text>
    <Text>Helpful</Text>
    <Button onPress={() => navigateTo(NextState)}>Yes, go to settings!</Button>
  </Body>
</Scene>

Generated code

During the build step, the following XML and JSON files are generated.

XML

<?xml version="1.0"?>
<application>
  <container id="8" widget="LT_State_Wide" type="state">
    <layoutGroup id="7" name="List">
      <component id="2" widget="LT_Label_2Row_1TextDyn" type="label">
        <property id="3" value="0"/>
      </component>
      <component id="3" widget="LT_Label_2Row_1TextDyn" type="label">
        <property id="3" value="0"/>
      </component>
      <component id="4" widget="LT_Label_2Row_1TextDyn" type="label">
        <property id="3" value="0"/>
      </component>
      <component id="5" widget="LT_Label_2Row_1TextDyn" type="label">
        <property id="3" value="0"/>
      </component>
      <component id="6" type="button"/>
    </layoutGroup>
  </container>
</application>

JSON

{
  "schemaVersion": "1.3.0",
  "containers": {
    "8": {
      "type": "state",
      "name": "a88c0b5d-0250-4ec5-b27a-8c0f06a3ecae",
      "properties": {
        "OptionComponents": {
          "type": "Text"
        }
      },
      "components": {
        "7": {
          "2": {
            "type": "label",
            "name": "d68f81cd-3e20-4860-878c-15501dcc1331",
            "properties": {
              "Focusable": {
                "value": 0,
                "type": "UInt"
              }
            },
            "rows": [
              {
                "Text": {
                  "value": "React",
                  "type": "Text"
                }
              }
            ]
          },
          "3": {
            "type": "label",
            "name": "d0128350-ab49-461c-8205-4a2f4e2ea52e",
            "properties": {
              "Focusable": {
                "value": 0,
                "type": "UInt"
              }
            },
            "rows": [
              {
                "Text": {
                  "value": "Is",
                  "type": "Text"
                }
              }
            ]
          },
          "4": {
            "type": "label",
            "name": "571a986f-7f73-4590-929b-0de473ddec67",
            "properties": {
              "Focusable": {
                "value": 0,
                "type": "UInt"
              }
            },
            "rows": [
              {
                "Text": {
                  "value": "Really",
                  "type": "Text"
                }
              }
            ]
          },
          "5": {
            "type": "label",
            "name": "38a7e8f6-4e84-4667-b49b-4021030ad656",
            "properties": {
              "Focusable": {
                "value": 0,
                "type": "UInt"
              }
            },
            "rows": [
              {
                "Text": {
                  "value": "Helpful",
                  "type": "Text"
                }
              }
            ]
          },
          "6": {
            "type": "button",
            "name": "f8bffed9-e687-4a27-931d-84e6f34f0c10",
            "rows": [
              {
                "Text": {
                  "value": "Yes, go to settings!",
                  "type": "Text"
                }
              }
            ]
          }
        }
      }
    }
  }
}

react-bmw's People

Contributors

dratwas avatar grabbou avatar haeussler247 avatar schnedo avatar tsiq-swyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-bmw's Issues

Prepare `react-bmw` framework

We need to package the framework into tgz so that it can be easily distributed over the network to the test machines

OAP Hackathon: Informations

The track

App Store

Team

  • Mike (Captain)
  • Piotr
  • Dominik
  • Johannes

Roles

The roles and responsibilities have been split based on the access to the OAP or not

Mike & Piotr (Callstack) - development of the React BMW framework and features on top of it

Dominik & Johannes (Synyx) - pilot project with the framework and feedback for further improvements for the purposes of the demo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.