Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. const HomeScreen extends PureComponent {
  2. constructor(props) {
  3. this.state = {
  4. focusedKey: null
  5. };
  6.  
  7. this.onSetFocus = this.onSetFocus.bind(this);
  8. }
  9.  
  10. componentDidUpdate(oldProps) {
  11. const {active} = this.props;
  12.  
  13. if (oldProps.active !== active) {
  14. this.setState({
  15. focusedKey: null
  16. });
  17. }
  18. }
  19.  
  20. onSetFocus(nextFocusKey) {
  21. if (nextFocusKey === SIDE_MENU) {
  22. this.props.onFocusSideMenu();
  23. } else {
  24. this.setState({
  25. focusedKey: nextFocusKey
  26. });
  27. }
  28. }
  29.  
  30. render() {
  31. const {rows} = this.props;
  32. const {focusedKey} = this.state;
  33.  
  34. return (<React.Fragment>
  35. {rows.map((rowData, index) => (<GalleryRow
  36. key={rowData.id}
  37. active={focusedKey === `ROW_${index}`}
  38. items={rowData.items}
  39. onSetFocus={this.onSetFocus}
  40. focusMap={{
  41. up: `ROW_${index - 1}`, // no clamping for simplification
  42. down: `ROW_${index + 1}`, // no clamping for simplification
  43. left: 'SIDE_MENU'
  44. }}
  45. />))}
  46. </React.Fragment>);
  47. }
  48. }
  49.  
  50. const GalleryRow extends PureComponent {
  51. // handles key events and calls the onSetFocus prop with the next key
  52. // called only if current row is active
  53. // next focus key is taken from focusMap prop based on direction
  54. // left direction can only be called when first item is focused
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement