Code Monkey home page Code Monkey logo

react-tv's Introduction

react-tv: React Renderer for low memory applications.

react-tv-cli: React Packager for TVs.

Currently under development.

React-TV Logo

import React from 'react'
import ReactTV, { Platform } from 'react-tv'

class Clock extends React.Component {
  state = { date: new Date() }

  componentDidMount() {
    setInterval(() => this.setState({date: new Date()}), 1000)
  }

  render() {
    if (Platform('webos')) {
      return (
        <h1>Time is {this.state.date.toLocaleTimeString()}</h1>
      )
    }

    return <h2>This App is available only at LG WebOS</h2>
  }
}

ReactTV.render(<Clock/>, document.getElementById('root'))

Summary

About React-TV

React-TV is an ecosystem for TV based React applications (from the renderer to CLI for pack/build applications).
At the moment we're focusing on WebOS and SmartTV.
React-TV's aims to be a better tool for building and developing fast for TVs.

Understanding the Problem

tl;dr: Crafting a high-performance TV user interface using React

Crafting a high-performance TV user interface using React is a real challenge, because of some reasons:

  • Limited graphics acceleration
  • Single core CPUs
  • High Memory Usage for a common TV App

These restrictions make super responsive 60fps experiences especially tricky. The strategy is step in the renderer: Applying reactive concepts to unblock the processing on the renderer layer, plug the TV's keyListener, avoid React.createElement.

In addition: Unify the build for multiple TV platforms.

Articles

Friendly list of tutorials and articles:

To install react-tv-cli (CLI Packager):

$ yarn global add react-tv-cli

Developing for WebOS

Short Description: WebOS, also known as Open WebOS or LG WebOS, (previously known as HP WebOS and Palm WebOS, stylized as webOS) is a Linux kernel-based multitasking operating system for smart devices such as Smart TVs and it has been used as a mobile operating system.


First of all, setup your WebOS Environment:

Then, init your react-tv project.

$ react-tv init <my-app-name>

Add the files related to your app on the React-TV entry on package.json:

{
  "name": "my-app-name",
  "react-tv": {
    "files": [
      "index.html",
      "bundle.js",
      "style.css"
    ]
  }
}

Running it on specific device:

$ react-tv run-webos <device>
  • When you not specify the device, it runs on VirtualBox WebOS Simulator

To install react-tv (React Renderer):

$ yarn add react-tv

Platform

When building a cross-platform TV app, you'll want to re-use as much code as possible. You'll probably have different scenarios where different code might be necessary.
For instance, you may want to implement separated visual components for LG-WebOS and Samsung-Tizen.

React-TV provides the Platform module to easily organize your code and separate it by platform:

import { Platform } from 'react-tv'

console.log(Platform('webos')) // true
console.log(Platform('tizen')) // false
console.log(Platform('orsay')) // false

renderOnAppLoaded

Takes a component and returns a higher-order component version of that component, which renders only after application was launched, allows to not write diffent logics for many devices.

import { renderOnAppLoaded } from 'react-tv'

const Component = () => (<div></div>)
const App = renderOnAppLoaded(Component)

Spatial Navigation

React-TV provides a spatial navigation system on render level.

Just add focusable for navigable elements and focused for an element which starts focused.

<div>
  <div focusable onBlur={() => console.log('blur') } >
    Item with Blur Handler
  </div>
  <div className="my-horizontal-list">
    <div className="item" focusable onPress={() => console.log('pressed') } >
      Horizontal Item 1 with Press Handler
    </div>
    <div className="item" focusable focused>
      Horizontal Item 2 which started focused
    </div>
  </div>
  <div className="item" focusable onFocus={() => console.log('focused') } >
    Item with Focus Handler
  </div>
</div>

See examples/navigation for more details about usage.

Examples

Clock App Example

Youtube App Example

References:

WebOS

Videos

Windows
OSX

Essentials to beginner

Developing for SmartTV Guidelines

React Basics and Renderer Architecture

Roadmap

Stage 1

Initial proof-of-concept. [DONE]

  • CLI Build Abstraction of LG Webos (run-webos, run-webos-dev)
  • Create a guide or script to Install all LG WebOS environment
  • Renderer ReactElements to simple DOM
    • Support HOF and HOC
    • Support State and Lifecycle
    • Keyboard Navigation
  • Check webos Platform
  • Migrate to React-Reconciler

Stage 2 [IN PROGRESS]

Implement essential functionality needed for daily use by early adopters.

  • Support render to Canvas instead DOM using React.CanvasComponent
  • run-webos support TV device as param
  • Optmizate DOMRenderer for TV
  • Start CLI for Tizen
  • Develop helpers for WebOS debbug (e.g: Log System).
  • Support Cross Platform
    • Check executable bin path for Windows, OSX and Linux
  • Bind all TV key listeners on React.Element
  • Improve documentation
  • Benchmark it

Stage 3

Add additional features users expect from a Renderer. Then fix bugs and stabilize through continuous daily use. At this point we can start to experiment with innovative ideas and paradigms.

  • Start CLI for Orsay
  • Update Benchmarks
  • Handle common errors
  • Reactive Renderer
  • Testing and stability

See ReactTV's Changelog.

Currently ReactTV is licensed by MIT License

Credits

Thanks react-dom for be example and a inspiration code :)

react-tv's People

Contributors

raphamorim avatar ntmedina avatar antonybudianto avatar dead avatar matheusml avatar thgmhz avatar

Watchers

Marcelo Jorge Vieira avatar James Cloos avatar

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.