Giter VIP home page Giter VIP logo

react-tv-navigation's Introduction

Navigation for TVs using React-TV

CircleCI

tl;dr: Based on Netflix TV Navigation System

React-TV Navigation Example

See code from this example

React-TV-Navigation is a separated package from React-TV renderer to manage focusable components.

Installing

yarn add react-tv-navigation

React and React-TV are peer-dependencies.

withFocusable and withNavigation

React-TV Navigation exports two functions: withFocusable and withNavigation.

A declarative navigation system based on HOC's for focus and navigation control.

import React from 'react'
import ReactTV from 'react-tv'
import { withFocusable, withNavigation } from 'react-tv-navigation'

const Item = ({focused, setFocus, focusPath}) => {
  focused = (focused) ? 'focused' : 'unfocused'
  return (
    <div onClick={() => { setFocus() }} >
      It's {focused} Item
    </div>
  )
}

const Button = ({setFocus}) => {
  return (
    <div onClick={() => { setFocus('item-1') }}>
      Back To First Item!
    </div>
  )
}

const FocusableItem = withFocusable(Item)
const FocusableButton = withFocusable(Button)

function App({currentFocusPath}) {
  return (
    <div>
      <h1>Current FocusPath: '{currentFocusPath}'</h1>,
      <FocusableItem focusPath='item-1'/>
      <FocusableItem focusPath='item-2'/>
      <FocusableButton
        focusPath='button'
        onEnterPress={() => console.log('Pressed enter on Button!')}/>
    </div>
  )
}

const NavigableApp = withNavigation(App)

ReactTV.render(<NavigableApp/>, document.querySelector('#app'))

Soon we'll write a decent README.md :)

License by MIT

react-tv-navigation's People

Contributors

celiolatorraca avatar raphamorim avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-tv-navigation's Issues

Actual package placement?

There is big link React-TV-Navigation was migrated to raphamorim/react-tv on the top of README, and I see source code in raphamorim/react-tv repository, but NPM package, as I can see, still has link to this repository.

So my question is, where is actual sources, where to make PRs?

Makes focusPath prop optional

For now, the focusPath is required. What would be the best approach to change it?

What is the problem?

As a react-based component, we lay on react lifecycle...

  • After a component mounts, we register it to focus manager and if there is no focusPath provided, the manager generates a new one.
  • When this component is re-rendered, as a normal react component, we unregister this component from the focus manager while unmounting it, then register again after mounting the new one.

But, if we are generating a new focusPath for components that didn't provide one, after this cycle we would have a currentFocusPath (injected by withNavigation) pointing to an element that was already unmounted...

What do you think we can do to avoid this?

Initial react-tv setup throws and error with react-tv-navigation

Hi all. First of all, thank you for your great effort to create an ecosystem around smart tv's.

I've just set up my development environment as instructed and started dev server with yarn start command and navigated to http://localhost:8080 with chrome browser. On the page, I had this error in console;

Uncaught Error: Argument appears to not be a ReactComponent. Keys: tag,key,type,stateNode,return,child,sibling,index,ref,pendingProps,memoizedProps,updateQueue,memoizedState,mode,effectTag,nextEffect,firstEffect,lastEffect,expirationTime,alternate,_debugID,_debugSource,_debugOwner,_debugIsCurrentlyTiming

Complete output here: http://dpaste.com/3EHE8C5

It's default boilerplate code of the react-tv-cli nothing added.

So I just removed withFocusable HOC and tried to render with standard component and everything just worked.
I couldn't quite figure out what is the problem here. Couple days ago I tried react-tv-navigation with react-dom (just replaced ReactTV.findDOMNode with ReactDOM.findDOMNode) to test if it is capable of achieving my needs on tv app and it just worked that time.

So, what could cause this, any idea?

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.