Instantly share code, notes, and snippets.
Frontend Software Architect working on multiscreen TV Streaming Apps and SDK components at Norigin Media in Oslo, Norway.
-
Norigin Media
- Oslo, Norway
- https://www.linkedin.com/in/asgvard
asgvard
/ spatial-nav-hooks-focus-maps.jsx
Created
March 17, 2022 14:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GalleryRow({items, focused}) { | |
const [focusedItemIndex, setFocusedItemIndex] = useState(0); | |
const onSetFocus = useCallback(({newFocusedIndex}) => { | |
if (!focused) { | |
return; | |
} | |
setFocusedItemIndex(Math.clamp(newFocusedIndex, 0, items.length - 1)); | |
}, [focused]); |
asgvard
/ spatial-nav-hooks-example.jsx
Created
March 17, 2022 14:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Button() { | |
const { ref, focused } = useFocusable(); | |
return (<div ref={ref} className={focused ? 'button-focused' : 'button'}> | |
Press me | |
</div>); | |
} |
asgvard
/ spatial-nav-hooks-full-example.jsx
Created
March 17, 2022 15:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { useFocusable, init, FocusContext } from '@noriginmedia/norigin-spatial-navigation'; | |
init(); | |
const MENU_FOCUS_KEY = 'MENU'; | |
const menuItems = [1, 2, 3, 4, 5]; | |
const rowItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
OlderNewer