Skip to content

Instantly share code, notes, and snippets.

View Maluen's full-sized avatar

Manuel Dell'Elce Maluen

View GitHub Profile
@Maluen
Maluen / rootReducer.js
Created September 5, 2018 11:18
Root reducer with ROOT_RESET action to reset the state back to its initial value
import { combineReducers } from 'redux';
import * as reducers from './index';
const appReducer = combineReducers({
...reducers,
});
const rootReducer = (state, action) => {
if (action.type === 'ROOT_RESET') {
state = undefined;
@Maluen
Maluen / react-native-store.js
Created September 5, 2018 11:11
React native store.js using redux-persist
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to AsyncStorage for react-native
import rootReducer from './reducers/root';
const persistedReducer = persistReducer({
key: 'root',
storage,
@Maluen
Maluen / react-navigation-drawer-stack.js
Created September 5, 2018 09:57
React Navigation: combining drawer and stack navigator
const StackNavigator = createStackNavigator({
Home: HomeScreen,
Search: SearchScreen,
Details: DetailsScreen,
Credits: CreditsScreen,
}, {
navigationOptions: {
header: null,
},
});
startResetAnimation = () => {
this.resetAnimation = Animated.timing(this.state.screenOpacityAnim, {
toValue: 0,
duration: 500,
});
this.resetAnimationFinished = false;
this.resetAnimation.start(({ finished }) => {
if (finished) {
this.resetAnimationFinished = true;
}
<Button
dark
title="C"
containerStyle={styles.deleteButtonContainer}
onPress={this.handleDelete}
onLongPressStarted={this.startResetAnimation}
onLongPressCancelled={this.cancelResetAnimation}
onLongPressEnd={this.finalizeResetAnimation}
/>
import React from 'react';
import PropTypes from 'prop-types';
import { Text, View, ViewPropTypes } from 'react-native';
import { GestureHandler } from 'expo';
import styles from './styles';
const { LongPressGestureHandler, State, RectButton } = GestureHandler;
class Button extends React.Component {
function unicodeForSymbol(code) {
var codeHex = code.toString(16).toUpperCase();
while (codeHex.length < 4) {
codeHex = "0" + codeHex;
}
return "\\u" + codeHex;
}
console.log(unicodeForSymbol(58840)); // \uE5D8
@Maluen
Maluen / isPageLoggedIn.js
Created April 21, 2017 18:50
Extensions: simple heuristic way to check if the user is logged in (in any page)
export default function isPageLoggedIn() {
return Boolean(Array.from(document.body.querySelectorAll('a, button')).find(el => {
return el.innerText && el.innerText.match(/sign out|signout|log out|logout/i) !== null;
}));
}