Skip to content

Instantly share code, notes, and snippets.

View bogoslavskiy's full-sized avatar

Artem Bogoslavskiy bogoslavskiy

View GitHub Profile
constructor(initialState) {
this.initialState = initialState;
this._createClampedScroll();
this.scrollY.addListener(this._updateScroll);
}
_updateScroll = ({value}) => {
const diff = value - this._scrollValue;
this._scrollValue = Math.max(value, this.topPartHeight); // Fix normal state
scrollToOffset(offset, animated) {
if(offset != this.scrollY._value) {
this.initialState.scrollToOffset({offset, animated});
}
}
minimizeBar = () => {
if(Math.round(this.scrollY._value) == 0) { // Full
this.scrollToOffset(this.topPartHeight);
} else { // Clamped
maxActionAnimated = 88; // Location input height + padding (Bottom part)
actionAnimated = new Animated.Value(0);
getTransformWrapper() {
let byScroll = Animated.add(
Animated.multiply(this.clampedScroll, -1),
this.scrollY.interpolate({ // To negative
inputRange: [0, 1],
outputRange: [0, -1],
}).interpolate({ // Add bottom height part
_setStateBar(state) {
let toValue = state == 'full' ? this.maxActionAnimated : 0;
Animated.timing(this.actionAnimated, {
toValue: toValue,
duration: 250,
useNativeDriver: true,
}).start();
}
minimizeBar = () => {
_handleIntermediateState = (scrollToOffset) => {
let scrollY = this.scrollY._value;
if(scrollY < this.topPartHeight) { // Full
scrollToOffset(scrollY > (this.topPartHeight / 2) ? this.topPartHeight : 0);
} else { // Clamped
if(
this._clampedScrollValue < this.maxClamp &&
this._clampedScrollValue > this.minClamp
) {
let scrollTo;
_updateScroll = ({value, manually}) => {
if(value && manually) {
this._clampedScrollValue = value;
} else {
const diff = value - this._scrollValue;
this._scrollValue = Math.max(value, this.topPartHeight); // Fix normal state
this._clampedScrollValue = Math.min(
Math.max(this._clampedScrollValue + diff, this.minClamp),
this.maxClamp
);
[...]
_renderHeader = (animation, canJumpToTab) => props => (
<SearchBar
animation={animation}
changeInputFocus={suggestionFocus =>
this.setState({suggestionFocus})
}
renderTabBar={() => (
<TabBar
onTabPress={({route}) => {
export default class SearchBarProvider extends React.Component {
constructor(props) {
super(props);
[...]
this.state = {
currentTab: null,
canJumpToTab: true,
contextProvider: {
animation: this.searchBarAnimation.animationProps,
class FlatListHelper extends React.PureComponent {
[...]
_onMomentumScrollBegin = () => this.props._canJumpToTab(false);
_onMomentumScrollEnd = () => this.props._canJumpToTab(true);
[...]
render() {
class FlatListHelper extends React.PureComponent {
[...]
_onScrollEndDrag = e => {
if(e.nativeEvent.velocity.y == 0) {
this.props.animation.handleIntermediateState(this.scrollToOffset);
}
};
[...]