diff --git a/src/components/Lists/WebSectionList.js b/src/components/Lists/WebSectionList.js index 04cb1e5..021c9e5 100644 --- a/src/components/Lists/WebSectionList.js +++ b/src/components/Lists/WebSectionList.js @@ -4,7 +4,7 @@ import * as React from 'react'; import {ERROR_TYPE, readData} from "../../utils/WebData"; import i18n from "i18n-js"; import {Snackbar} from 'react-native-paper'; -import {RefreshControl, SectionList, View} from "react-native"; +import {Animated, RefreshControl, View} from "react-native"; import ErrorView from "../Custom/ErrorView"; import BasicLoadingScreen from "../Custom/BasicLoadingScreen"; @@ -19,6 +19,7 @@ type Props = { createDataset: Function, updateData: number, itemHeight: number | null, + onScroll: Function, } type State = { @@ -178,7 +179,7 @@ export default class WebSectionList extends React.PureComponent { return ( {/*$FlowFixMe*/} - { } removeClippedSubviews={true} getItemLayout={this.props.itemHeight !== null ? this.itemLayout : undefined} + // Animations + onScroll={this.props.onScroll} /> { +class HomeScreen extends React.Component { colors: Object; isLoggedIn: boolean | null; + isAnimationDownPlaying: boolean; + isAnimationUpPlaying: boolean; + + downAnimation; + upAnimation; + + state = { + showFab: true, + fabPosition: new Animated.Value(0), + }; constructor(props) { super(props); this.colors = props.theme.colors; - + this.isAnimationDownPlaying = false; + this.isAnimationUpPlaying = false; this.isLoggedIn = null; } @@ -379,7 +398,7 @@ class HomeScreen extends React.Component { } dashboardRowRenderItem = ({item}: Object) => { - return( + return ( { */ getDashboardRow(content: Array) { return ; + }} + />; } /** @@ -441,6 +460,38 @@ class HomeScreen extends React.Component { openScanner = () => this.props.navigation.navigate("scanner"); + onScroll = ({nativeEvent}: Object) => { + if (nativeEvent.velocity.y > 0.2) { // Go down + if (!this.isAnimationDownPlaying) { + this.isAnimationDownPlaying = true; + if (this.isAnimationUpPlaying) + this.upAnimation.stop(); + this.downAnimation = Animated.spring(this.state.fabPosition, { + toValue: 100, + duration: 50, + useNativeDriver: true, + }); + this.downAnimation.start(() => { + this.isAnimationDownPlaying = false + }); + } + } else if (nativeEvent.velocity.y < -0.2) { // Go up + if (!this.isAnimationUpPlaying) { + this.isAnimationUpPlaying = true; + if (this.isAnimationDownPlaying) + this.downAnimation.stop(); + this.upAnimation = Animated.spring(this.state.fabPosition, { + toValue: 0, + duration: 50, + useNativeDriver: true, + }); + this.upAnimation.start(() => { + this.isAnimationUpPlaying = false + }); + } + } + }; + render() { const nav = this.props.navigation; return ( @@ -453,9 +504,13 @@ class HomeScreen extends React.Component { fetchUrl={DATA_URL} renderItem={this.getRenderItem} itemHeight={FEED_ITEM_HEIGHT} + onScroll={this.onScroll} /> -