Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from 'react';
import { StyleSheet, View, Button } from 'react-native';
import Animated, { Easing } from 'react-native-reanimated';
const { call, block } = Animated;
const Wat = ({ backgroundColor, translateX }) => (
<Animated.View
style={{
commit 5481972781bed131186169d4608ad20311a71dda
Author: Krzysztof Magiera <[email protected]>
Date: Wed Oct 23 14:16:02 2019 +0200
Override removeAllViews to avoid pager from adding new views while unmounting.
The default ViewManager implementation of removeAllViews iterates over all existing children and calls removeViewAt(index) method. When this happens the ViewPager implementation triggers a code path that adds new tab views (the path starts from calling notifyDatasetChanged in ReactViewPager.java which ends up triggering TabLayout view updates that clean up all the views and add individual tabs from scratch https://android.googlesource.com/platform/frameworks/support/+/5c7d7bb/design/src/android/support/design/widget/TabLayout.java#616).
Apparently when using libraries that provides Android's native transition (e.g. react-native-screens v2) it is undesirable for the views being unmounted to remove and then add back children. It is because these libraries rely on a mechanism cal
const transition = (
<Transition.Together>
<Transition.In type="fade" />
<Transition.Out type="fade" />
<Transition.Change interpolation="easeInOut" />
</Transition.Together>
);
const ROOT_REF = React.createRef();
function easeInOut() {
ROOT_REF.current.animateNextTransition();
}
export default function AppContainer() {
return (
<Transitioning.View
style={styles.root}
export default class App extends React.Component {
state = {
items: ['aquamarine'],
};
insertAtRandom = () => {
LayoutAnimation.spring();
this.setState({
items: insertColorAtRandom(this.state.items),
});
};
@kmagiera
kmagiera / pokemonMock.js
Created November 22, 2018 13:36 — forked from barsumek/pokemonMock.js
Detox your GraphQL: Mock the Pokemon's level
const defaultPokemon = {
Pokemon: () => ({
level: 10
})
};
const maxLvlPokemon = {
Pokemon: () => ({
level: 30
})
function interaction(gestureTranslation, gestureState) {
const dragging = new Value(0);
const start = new Value(0);
const position = new Value(0);
const anchor = new Value(0);
const velocity = new Value(0);
const clock = new Clock();
const dt = divide(diff(clock), 1000);
function interaction(gestureTranslation, gestureState) {
const dragging = new Value(0);
const start = new Value(0);
const position = new Value(0);
const anchor = new Value(0);
const velocity = new Value(0);
const clock = new Clock();
const dt = divide(diff(clock), 1000);
const EPS = 1e-3;
const EMPTY_FRAMES_THRESHOLDS = 5;
function stopWhenNeeded(dt, position, velocity, clock) {
const ds = diff(position);
const noMovementFrames = new Value(0);
return cond(
lessThan(abs(ds), EPS),
[
function damping(dt, velocity, mass = 1, damping = 12) {
const acc = divide(multiply(-1, damping, velocity), mass);
return set(velocity, add(velocity, multiply(dt, acc)));
}