From 62211d082bc241190dfe89a0a04ec4e376834d64 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 12 Jun 2024 11:47:23 -0700 Subject: [PATCH] make linear gradient background easily reusable --- src/components/LinearGradientBackground.tsx | 26 +++++++++++++++++++ .../StarterPack/ProfileStarterPacks.tsx | 11 +++----- src/components/StarterPack/QrCode.tsx | 16 ++++-------- src/lib/routes/links.ts | 2 +- src/screens/StarterPack/Landing/index.tsx | 12 +++------ 5 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 src/components/LinearGradientBackground.tsx diff --git a/src/components/LinearGradientBackground.tsx b/src/components/LinearGradientBackground.tsx new file mode 100644 index 0000000000..d2a18d1a80 --- /dev/null +++ b/src/components/LinearGradientBackground.tsx @@ -0,0 +1,26 @@ +import React from 'react' +import {StyleProp, ViewStyle} from 'react-native' +import {LinearGradient} from 'expo-linear-gradient' + +import {useTheme} from '#/alf' + +export function LinearGradientBackground({ + style, + children, +}: { + style: StyleProp + children: React.ReactNode +}) { + const t = useTheme() + + const gradient = + t.name === 'light' + ? [t.palette.primary_500, t.palette.primary_300] + : [t.palette.primary_600, t.palette.primary_400] + + return ( + + {children} + + ) +} diff --git a/src/components/StarterPack/ProfileStarterPacks.tsx b/src/components/StarterPack/ProfileStarterPacks.tsx index 20afb47330..ccad672f9d 100644 --- a/src/components/StarterPack/ProfileStarterPacks.tsx +++ b/src/components/StarterPack/ProfileStarterPacks.tsx @@ -6,7 +6,6 @@ import { View, ViewStyle, } from 'react-native' -import {LinearGradient} from 'expo-linear-gradient' import {AppBskyGraphDefs, AppBskyGraphGetActorStarterPacks} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -20,6 +19,7 @@ import {List, ListRef} from 'view/com/util/List' import {Text} from 'view/com/util/text/Text' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' +import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {StarterPackCard} from '#/components/StarterPack/StarterPackCard' interface SectionRef { @@ -134,14 +134,9 @@ function EmptyComponent() { const {_} = useLingui() const t = useTheme() const navigation = useNavigation() - const gradient = - t.name === 'light' - ? [t.palette.primary_500, t.palette.primary_400] - : [t.palette.primary_600, t.palette.primary_500] return ( - Create - + ) } diff --git a/src/components/StarterPack/QrCode.tsx b/src/components/StarterPack/QrCode.tsx index a69c1772c0..97a2cd3a13 100644 --- a/src/components/StarterPack/QrCode.tsx +++ b/src/components/StarterPack/QrCode.tsx @@ -2,14 +2,15 @@ import React from 'react' import {View} from 'react-native' import QRCode from 'react-native-qrcode-styled' import ViewShot from 'react-native-view-shot' -import {LinearGradient} from 'expo-linear-gradient' import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {Trans} from '@lingui/macro' +import {makeStarterPackLink} from 'lib/routes/links' import {Logo} from 'view/icons/Logo' import {Logotype} from 'view/icons/Logotype' import {useTheme} from '#/alf' import {atoms as a} from '#/alf' +import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {Text} from '#/components/Typography' interface Props { @@ -20,22 +21,15 @@ export const QrCode = React.forwardRef(function QrCode( {starterPack}, ref, ) { - const t = useTheme() const {record} = starterPack - const gradient = - t.name === 'light' - ? [t.palette.primary_500, t.palette.primary_300] - : [t.palette.primary_600, t.palette.primary_400] - if (!AppBskyGraphStarterpack.isRecord(record)) { return null } return ( - (function QrCode( Join the conversation - + @@ -75,7 +69,7 @@ export const QrCode = React.forwardRef(function QrCode( style={{marginTop: 6, marginLeft: 2}} /> - + ) }) diff --git a/src/lib/routes/links.ts b/src/lib/routes/links.ts index 66f6530ba1..a08f8f8899 100644 --- a/src/lib/routes/links.ts +++ b/src/lib/routes/links.ts @@ -46,7 +46,7 @@ export function makeStarterPackLink( rkey?: string, ) { if (typeof starterPackOrName === 'string') { - return `/starter-pack/${starterPackOrName}/${rkey}` + return `/start/${starterPackOrName}/${rkey}` } else { const rkey = new AtUri(starterPackOrName.uri).rkey return makeProfileLink(starterPackOrName.creator, 'starter-pack', rkey) diff --git a/src/screens/StarterPack/Landing/index.tsx b/src/screens/StarterPack/Landing/index.tsx index 82dad620e0..4e1a7d36f6 100644 --- a/src/screens/StarterPack/Landing/index.tsx +++ b/src/screens/StarterPack/Landing/index.tsx @@ -1,6 +1,5 @@ import React from 'react' import {ScrollView, View} from 'react-native' -import {LinearGradient} from 'expo-linear-gradient' import { AppBskyActorDefs, AppBskyGraphDefs, @@ -25,6 +24,7 @@ import {Logo} from 'view/icons/Logo' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import {Divider} from '#/components/Divider' +import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {ListMaybePlaceholder} from '#/components/Lists' import {Text} from '#/components/Typography' @@ -78,11 +78,6 @@ function LandingScreenInner({ const setUsedStarterPack = useSetUsedStarterPack() const {isTabletOrDesktop} = useWebMediaQueries() - const gradient = - t.name === 'light' - ? [t.palette.primary_500, t.palette.primary_300] - : [t.palette.primary_600, t.palette.primary_400] - const sampleProfiles = listItemsSample?.map(item => item.subject) const userSets = { first: sampleProfiles?.slice(0, 4), @@ -98,8 +93,7 @@ function LandingScreenInner({ - - + {record.description ? (