Skip to content

Instantly share code, notes, and snippets.

View asgvard's full-sized avatar

Dmitriy Bryokhin asgvard

View GitHub Profile
@asgvard
asgvard / ReactNativeComponentBoilerplate.js
Last active September 7, 2017 12:21
React Native Component Boilerplate
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {
View,
StyleSheet
} from 'react-native';
const styles = StyleSheet.create({
});
@asgvard
asgvard / FlatSwiper.js
Created November 10, 2017 20:48
Horizontal Paging Swiper based on FlatList
/**
* TODO Finish this for optimized Android swiping
* Inspired by react-native-swiper but based on cross-platform and optimized FlatList
*/
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {
StyleSheet,
FlatList,
@asgvard
asgvard / RootResponder.js
Created March 2, 2018 12:07
Root responder for global interception of touch events in RN
/**
* Wrapper for creating Global (RootContainer) PanResponder
* Responder events are bubbled up by the View hierarchy, but sometimes it's needed to "move"
* touch handling to a sibling component. Instead we're creating Root Responder to capture the touch and
* delegate the callbacks to any component that wants to listen to it.
*
* Any component in the App can hook into the Root Responder lifecycle callbacks
* For capturing of the Root Responder the *Capture callbacks should return true
*
* Only one component at a time can be attached to Root Responder
@asgvard
asgvard / spatial-nav-distributed-logic.js
Last active April 13, 2019 19:00
Spatial Navigation article. Distributed logic example
const HomeScreen extends PureComponent {
constructor(props) {
this.state = {
focusedIndex: 0
};
this.onKeyPress = this.onKeyPress.bind(this);
}
componentDidMount() {
const HomeScreen extends PureComponent {
constructor(props) {
this.state = {
focusedKey: null
};
this.onSetFocus = this.onSetFocus.bind(this);
}
componentDidUpdate(oldProps) {
@asgvard
asgvard / focusable-wrapper-example.js
Created April 13, 2019 21:53
Focusable wrapper example
<Focusable>
<Component />
</Focusable>
@asgvard
asgvard / focusable-hoc-example.js
Created April 13, 2019 21:58
focusable-hoc-example
const FocusableComponent = withFocusable()(Component);
@asgvard
asgvard / spatial-nav-context-example.js
Created April 13, 2019 22:31
spatial-nav-context-example
const SpatialNavigableApp = withSpatialNavigation()(App);
@asgvard
asgvard / spatial-nav-full-example.js
Last active May 10, 2019 14:56
spatial-nav-full-example
// 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];
function GalleryRow({items, focused}) {
const [focusedItemIndex, setFocusedItemIndex] = useState(0);
const onKeyPress = useCallback(({keyCode}) => {
if (!focused) {
return;
}
let newIndex;