From 83541339e909061353546cba8f081cc101f09ec9 Mon Sep 17 00:00:00 2001 From: Jakob Stornig Date: Mon, 4 Dec 2023 23:31:05 +0100 Subject: [PATCH] feat: HomeScreen Plus Symbol. (Not functional) --- app/index.tsx | 22 ++++++++++++++++++---- components/common/plus/plus.tsx | 28 ++++++++++++++++++++++++++++ components/index.jsx | 6 +++++- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 components/common/plus/plus.tsx diff --git a/app/index.tsx b/app/index.tsx index 198b8be..780e71a 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -1,12 +1,14 @@ -import { StyleSheet, View, Text } from 'react-native'; +import { StyleSheet, View, Text, NativeSyntheticEvent, NativeScrollEvent } from 'react-native'; import { useThemeColor } from "../hooks/hooks"; import { SafeAreaView } from 'react-native-safe-area-context'; -import { ExpenseItem } from '../components'; +import { ExpenseItem, Plus } from '../components'; import { FlatList } from 'react-native-gesture-handler'; -import { ExpenseItemProps } from '../components/home/expenseItem/expenseItem'; +import { useRef, useState } from 'react'; export default function Page() { + const [plusShow, setPlusShow] = useState(true); + const prevOffset = useRef(0); const styles = StyleSheet.create({ container: { flex: 1, @@ -19,6 +21,14 @@ export default function Page() { fontWeight: "bold" } }); + + const handleScroll = (event: NativeSyntheticEvent)=>{ + const currentOffset = event.nativeEvent.contentOffset.y >= 0 ? event.nativeEvent.contentOffset.y : 0 + const isScrollingUp : boolean = currentOffset <= prevOffset.current; + const isTop : boolean = currentOffset === 0 + prevOffset.current = currentOffset + setPlusShow(isScrollingUp || isTop) + } const data = [ {id:"1",category: "Category 1", color: "blue", date:"01.01.2023 18:00", title:"Super fancy sepnding with long name that will not display", value: "€ 30,00"}, @@ -38,14 +48,18 @@ export default function Page() { return ( + {plusShow && } } keyExtractor={item => item.id} ItemSeparatorComponent={()=>} + onScroll={handleScroll} + scrollEventThrottle={20} > - + + ); } \ No newline at end of file diff --git a/components/common/plus/plus.tsx b/components/common/plus/plus.tsx new file mode 100644 index 0000000..5121ffa --- /dev/null +++ b/components/common/plus/plus.tsx @@ -0,0 +1,28 @@ +import { View, Text, ViewProps, StyleSheet } from 'react-native' +import { AntDesign } from '@expo/vector-icons' +import React from 'react' + +const Plus = (props : ViewProps) => { + return ( + + {props.children} + + + ) +} +const style = StyleSheet.create({ + plus:{ + position: "absolute", + right: 20, + bottom: 20, + zIndex: 1, + backgroundColor: "orange", + padding: 20, + borderRadius: 500, + height: 60, + width: 60, + alignItems: 'center', + justifyContent: "center" + } +}) +export default Plus \ No newline at end of file diff --git a/components/index.jsx b/components/index.jsx index 7d1f5b7..793a530 100644 --- a/components/index.jsx +++ b/components/index.jsx @@ -1,7 +1,11 @@ //home import ExpenseItem from "./home/expenseItem/expenseItem" +//common +import Plus from "./common/plus/plus" + export { - ExpenseItem + ExpenseItem, + Plus }