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-full-example.jsx
Created
March 17, 2022 15:00
This file contains 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]; |
asgvard
/ spatial-nav-hooks-example.jsx
Created
March 17, 2022 14:40
This file contains 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-focus-maps.jsx
Created
March 17, 2022 14:09
This file contains 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-distributed-logic.jsx
Created
March 17, 2022 13:55
This file contains 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 onKeyPress = useCallback(({keyCode}) => { | |
if (!focused) { | |
return; | |
} | |
let newIndex; | |
This file contains 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
// this example uses react-native-web syntax | |
import React, {PureComponent} from 'react'; | |
import {View, ScrollView} from 'react-native'; | |
import {initNavigation, withFocusable} from '@noriginmedia/react-spatial-navigation'; | |
initNavigation(); | |
const menuItems = [1, 2, 3, 4, 5]; | |
const rowItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
This file contains 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
const SpatialNavigableApp = withSpatialNavigation()(App); |
This file contains 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
const FocusableComponent = withFocusable()(Component); |
This file contains 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
<Focusable> | |
<Component /> | |
</Focusable> |
asgvard
/ spatial-nav-focus-map.js
Created
April 11, 2019 22:36
This file contains 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
const HomeScreen extends PureComponent { | |
constructor(props) { | |
this.state = { | |
focusedKey: null | |
}; | |
this.onSetFocus = this.onSetFocus.bind(this); | |
} | |
componentDidUpdate(oldProps) { |
asgvard
/ spatial-nav-distributed-logic.js
Last active
April 13, 2019 19:00
Spatial Navigation article. Distributed logic example
This file contains 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
const HomeScreen extends PureComponent { | |
constructor(props) { | |
this.state = { | |
focusedIndex: 0 | |
}; | |
this.onKeyPress = this.onKeyPress.bind(this); | |
} | |
componentDidMount() { |
NewerOlder