raphamorim / react-ape

🦍• React Renderer to build UI interfaces using canvas/WebGL (TV and Hardware-Accelerated GPU development based)
https://raphamorim.io/react-ape/
MIT License
1.57k stars 48 forks source link

Navigation based on focus #8

Open raphamorim opened 6 years ago

raphamorim commented 6 years ago

Following similar patterns of https://medium.com/netflix-techblog/pass-the-remote-user-input-on-tv-devices-923f6920c9a8 and https://github.com/react-tv/react-tv-navigation

draft api:

import { Text, withFocusable, withNavigation } from 'react-ape'

const Item = ({focused, setFocus, focusPath}) => {
  focused = (focused) ? 'focused' : 'unfocused'
  return (
    <Text onClick={() => { setFocus() }} >
      It's {focused} Item
    </Text>
  )
}
raphamorim commented 6 years ago

cc @fabiomcosta

fabiomcosta commented 6 years ago

My suggestion:

import { Text, withFocus } from 'react-ape';

const Item = ({focusPath}) => {
  const style = focused ? { outline: '1px solid blue' } : {};
  return (
    <Text style={style}>
      Its {focused} Item
    </Text>
  )
}

export default withFocus(Item);
import { FocusableItem } from './FocusableItem'

class Navigation extends React.Component {
  render() {
    return (
      <FocusableItem focused={ true }>
        Tshow
      </FocusableItem>
    );
  }
}
raphamorim commented 5 years ago

Resolution in #12