Skip to content

Commit

Permalink
Update AnimatedFlatList component in AnimatedFlatList.tsx, ScrollView…
Browse files Browse the repository at this point in the history
… component in ScrollView.tsx, and Site component in Site.tsx
  • Loading branch information
plahteenlahti committed Apr 27, 2024
1 parent a3fad89 commit 8fe4d6c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 40 deletions.
88 changes: 69 additions & 19 deletions src/components/layout/AnimatedFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ import { FlatListProps, RefreshControl, StyleSheet, View } from 'react-native'
import { TouchableOpacity } from 'react-native-gesture-handler'
import Animated, {
Extrapolation,
FadeInLeft,
FadeOutRight,
interpolate,
interpolateColor,
useAnimatedScrollHandler,
useAnimatedStyle,
useSharedValue
} from 'react-native-reanimated'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import {
Defs,
LinearGradient,
Mask,
Rect,
Stop,
Svg,
Text,
Use
} from 'react-native-svg'

type Props<T> = {
refreshing: boolean
onRefresh: () => void
extraElement?: React.ReactNode
withLogo?: boolean
title: string
} & FlatListProps<T>

Expand All @@ -30,6 +39,7 @@ export const AnimatedFlatList = <T,>({
extraElement,
refreshing,
onRefresh,
withLogo,
...rest
}: Props<T>) => {
const { top } = useSafeAreaInsets()
Expand Down Expand Up @@ -72,24 +82,64 @@ export const AnimatedFlatList = <T,>({
return (
<View className="flex-1">
<Animated.FlatList
className="bg-blue-500"
className="bg-white"
onScroll={scrollHandler}
// refreshControl={
// <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
// }
ListFooterComponent={<View className="h-28" />}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
ListHeaderComponent={
<Animated.View
className="flex-row mb-12 pl-2 bg-red-300"
style={[largeTitleStyle, s.largeTitleContainer, { paddingTop }]}>
{extraElement}
<Animated.Text
className={`text-3xl font-display font-semibold ${
!!extraElement && 'ml-2'
}`}>
{title}
</Animated.Text>
</Animated.View>
<>
<Animated.View
className="mb-12 pl-2"
style={[largeTitleStyle, s.largeTitleContainer, { paddingTop }]}>
<Svg height={30} width={80} viewBox="0 0 800 300">
<Defs>
<LinearGradient
id="Gradient"
gradientUnits="userSpaceOnUse"
x1="0"
y1="0"
x2="0"
y2="300">
<Stop offset="0" stopColor="white" stopOpacity="0.8" />
<Stop offset="1" stopColor="white" stopOpacity="1" />
</LinearGradient>
<Mask
id="Mask"
maskUnits="userSpaceOnUse"
x="0"
y="0"
width="800"
height="300">
<Rect
x="0"
y="0"
width="800"
height="300"
fill="url(#Gradient)"
/>
</Mask>
<Text
id="Text"
x="400"
y="200"
fontFamily="Verdana"
fontSize="100"
textAnchor="middle">
Netli.fyi
</Text>
</Defs>
<Use href="#Text" fill="#333" mask="url(#Mask)" />
</Svg>

<Animated.Text
className={`text-3xl font-display font-semibold text-gray-800 ${
!!extraElement && 'ml-2'
}`}>
{title}
</Animated.Text>
</Animated.View>
</>
}
{...rest}
/>
Expand All @@ -108,7 +158,7 @@ export const AnimatedFlatList = <T,>({
<View className="flex-1 justify-center">
<TouchableOpacity />
</View>
<View className="flex-1 justify-center items-center">
<View className="flex-1">
<Animated.Text className="text-gray-800 font-medium text-base">
{title}
</Animated.Text>
Expand Down
9 changes: 4 additions & 5 deletions src/components/layout/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ export const AnimatedScrollView = ({
return (
<View className="flex-1">
<Animated.ScrollView
className="bg-blue-400"
onScroll={scrollHandler}
// refreshControl={
// <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
// }
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
{...rest}>
<Animated.View
className="flex-row pl-2 mb-12 bg-red-200"
className="flex-row pl-2 mb-1"
style={[largeTitleStyle, s.largeTitleContainer, { paddingTop }]}>
{extraElement}
<Animated.Text
Expand Down
17 changes: 3 additions & 14 deletions src/views/Site.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import { NativeStackScreenProps } from '@react-navigation/native-stack'

import {
FlatList,
Image,
ListRenderItem,
RefreshControl,
ScrollView,
View
} from 'react-native'
import { Image, RefreshControl, ScrollView, View } from 'react-native'
import { BuildSettings } from '../components/BuildSettings'
import { Card } from '../components/Card'
import { DeploysPreview } from '../components/DeploysPreview'
import { NoPreview } from '../components/NoPreview'
import { SiteInformation } from '../components/SiteInformation'
import { SubmissionsPreview } from '../components/SubmissionsPreview'
import { HooksPreview } from '../components/previews/hook'
import { Text } from '../components/text/Text'
import { useDeploys } from '../hooks/deploy'
import { useHooks } from '../hooks/hook'
import { useSite } from '../hooks/site'
import { useSubmissions } from '../hooks/submissions'
import { RootStackParamList } from '../navigators/RootStack'
import Animated from 'react-native-reanimated'
import { CardTitle } from '../components/CardTitle'
import { Card } from '../components/Card'
import { NoPreview } from '../components/NoPreview'
import { HStack } from '../components/layout/HStack'

type Props = NativeStackScreenProps<RootStackParamList, 'Site'>

Expand Down
3 changes: 1 addition & 2 deletions src/views/Sites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export const Sites = ({

return (
<AnimatedFlatList
title="Netli.fyi"
contentInsetAdjustmentBehavior="automatic"
title="Sites"
onRefresh={sites.refetch}
refreshing={sites.isRefetching}
data={sites.data}
Expand Down

0 comments on commit 8fe4d6c

Please sign in to comment.