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, { 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={{ |
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
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 |
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
const transition = ( | |
<Transition.Together> | |
<Transition.In type="fade" /> | |
<Transition.Out type="fade" /> | |
<Transition.Change interpolation="easeInOut" /> | |
</Transition.Together> | |
); |
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
const ROOT_REF = React.createRef(); | |
function easeInOut() { | |
ROOT_REF.current.animateNextTransition(); | |
} | |
export default function AppContainer() { | |
return ( | |
<Transitioning.View | |
style={styles.root} |
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
export default class App extends React.Component { | |
state = { | |
items: ['aquamarine'], | |
}; | |
insertAtRandom = () => { | |
LayoutAnimation.spring(); | |
this.setState({ | |
items: insertColorAtRandom(this.state.items), | |
}); | |
}; |
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
const defaultPokemon = { | |
Pokemon: () => ({ | |
level: 10 | |
}) | |
}; | |
const maxLvlPokemon = { | |
Pokemon: () => ({ | |
level: 30 | |
}) |
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 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); |
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 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); |
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
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), | |
[ |
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 damping(dt, velocity, mass = 1, damping = 12) { | |
const acc = divide(multiply(-1, damping, velocity), mass); | |
return set(velocity, add(velocity, multiply(dt, acc))); | |
} |