From ec8b8fc4195939cace2abf5972d77efc380788a2 Mon Sep 17 00:00:00 2001 From: Justin Hernandez Date: Wed, 11 Feb 2026 15:56:15 -0800 Subject: [PATCH] refactor(app): share homescreen card dimensions (#1733) * refactor(app): share homescreen card dimensions * formatting * fix logic --- app/src/components/homescreen/EmptyIdCard.tsx | 59 ++++---------- .../components/homescreen/ExpiredIdCard.tsx | 54 +++++-------- app/src/components/homescreen/IdCard.tsx | 77 ++++++------------ app/src/components/homescreen/KycIdCard.tsx | 59 ++++---------- .../components/homescreen/PendingIdCard.tsx | 54 +++++-------- .../homescreen/UnregisteredIdCard.tsx | 59 ++++---------- app/src/components/homescreen/cardStyles.ts | 31 +++++++ app/src/hooks/useCardDimensions.ts | 81 +++++++++++++++++++ 8 files changed, 225 insertions(+), 249 deletions(-) create mode 100644 app/src/components/homescreen/cardStyles.ts create mode 100644 app/src/hooks/useCardDimensions.ts diff --git a/app/src/components/homescreen/EmptyIdCard.tsx b/app/src/components/homescreen/EmptyIdCard.tsx index 8d46e487e..0ae3dfeb5 100644 --- a/app/src/components/homescreen/EmptyIdCard.tsx +++ b/app/src/components/homescreen/EmptyIdCard.tsx @@ -4,7 +4,7 @@ import type { FC } from 'react'; import React from 'react'; -import { Dimensions, Image, StyleSheet } from 'react-native'; +import { Image } from 'react-native'; import { Text, XStack, YStack } from 'tamagui'; import { @@ -18,6 +18,8 @@ import { dinot } from '@selfxyz/mobile-sdk-alpha/constants/fonts'; import SelfLogoUnverified from '@/assets/images/self_logo_unverified.svg'; import WavePatternBody from '@/assets/images/wave_pattern_body.png'; +import { cardStyles } from '@/components/homescreen/cardStyles'; +import { useCardDimensions } from '@/hooks/useCardDimensions'; interface EmptyIdCardProps { onRegisterPress: () => void; @@ -32,32 +34,23 @@ interface EmptyIdCardProps { * - Pill-shaped white button with gray border */ const EmptyIdCard: FC = ({ onRegisterPress }) => { - const { width: screenWidth } = Dimensions.get('window'); - - // Card dimensions (matching IdCardLayout) - const cardWidth = screenWidth * 0.95 - 16; - const cardHeight = cardWidth * 0.635; - const borderRadius = 12; - - // Figma exact dimensions (scaled from 353px reference width) - const scale = cardWidth / 353; - const headerHeight = 67 * scale; - const figmaPadding = 14 * scale; - const logoSize = 32 * scale; - const headerGap = 12 * scale; - - // Font sizes from Figma - const fontSize = { - header: 20 * scale, // 20px in Figma - subtitle: 7 * scale, // 7px in Figma - button: 16 * scale, // 16px in Figma - }; + const { + cardWidth, + borderRadius, + scale, + headerHeight, + figmaPadding, + logoSize, + headerGap, + expandedAspectRatio, + fontSize, + } = useCardDimensions(); return ( = ({ onRegisterPress }) => { {/* Body Section - White background with wave pattern */} - + {/* Wave pattern background - exact same as unverified_human.png */} @@ -158,22 +151,4 @@ const EmptyIdCard: FC = ({ onRegisterPress }) => { ); }; -const styles = StyleSheet.create({ - body: { - flex: 1, - position: 'relative', - overflow: 'hidden', - backgroundColor: 'white', - }, - wavePattern: { - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - width: '100%', - height: '100%', - }, -}); - export default EmptyIdCard; diff --git a/app/src/components/homescreen/ExpiredIdCard.tsx b/app/src/components/homescreen/ExpiredIdCard.tsx index 2f010fd7d..d315e03de 100644 --- a/app/src/components/homescreen/ExpiredIdCard.tsx +++ b/app/src/components/homescreen/ExpiredIdCard.tsx @@ -4,7 +4,7 @@ import type { FC } from 'react'; import React from 'react'; -import { Dimensions, Image, StyleSheet } from 'react-native'; +import { Image } from 'react-native'; import { Text, XStack, YStack } from 'tamagui'; import { @@ -17,6 +17,8 @@ import { dinot } from '@selfxyz/mobile-sdk-alpha/constants/fonts'; import SelfLogoInactive from '@/assets/images/self_logo_inactive.svg'; import WavePatternBody from '@/assets/images/wave_pattern_body.png'; +import { cardStyles } from '@/components/homescreen/cardStyles'; +import { useCardDimensions } from '@/hooks/useCardDimensions'; /** * Expired state card shown when user's identity document has expired. @@ -27,31 +29,23 @@ import WavePatternBody from '@/assets/images/wave_pattern_body.png'; * - Black "EXPIRED ID" badge in bottom right */ const ExpiredIdCard: FC = () => { - const { width: screenWidth } = Dimensions.get('window'); - - // Card dimensions (matching IdCardLayout) - const cardWidth = screenWidth * 0.95 - 16; - const cardHeight = cardWidth * 0.635; - const borderRadius = 12; - - // Figma exact dimensions (scaled from 353px reference width) - const scale = cardWidth / 353; - const headerHeight = 67 * scale; - const figmaPadding = 14 * scale; - const logoSize = 32 * scale; - const headerGap = 12 * scale; - - // Font sizes from Figma - const fontSize = { - header: 20 * scale, // 20px in Figma - subtitle: 7 * scale, // 7px in Figma - }; + const { + cardWidth, + borderRadius, + scale, + headerHeight, + figmaPadding, + logoSize, + headerGap, + expandedAspectRatio, + fontSize, + } = useCardDimensions(); return ( { {/* Body Section - White background with wave pattern */} - + {/* Wave pattern background */} @@ -133,7 +127,7 @@ const ExpiredIdCard: FC = () => { > { ); }; -const styles = StyleSheet.create({ - wavePattern: { - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - width: '100%', - height: '100%', - }, -}); - export default ExpiredIdCard; diff --git a/app/src/components/homescreen/IdCard.tsx b/app/src/components/homescreen/IdCard.tsx index db76832a5..2fc412239 100644 --- a/app/src/components/homescreen/IdCard.tsx +++ b/app/src/components/homescreen/IdCard.tsx @@ -4,7 +4,7 @@ import type { FC } from 'react'; import React from 'react'; -import { Dimensions, Image, StyleSheet } from 'react-native'; +import { Image, StyleSheet } from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; import { Text, XStack, YStack } from 'tamagui'; @@ -31,7 +31,9 @@ import DevCardWave from '@/assets/images/dev_card_wave.svg'; import SelfLogoPending from '@/assets/images/self_logo_pending.svg'; import WaveOverlay from '@/assets/images/wave_overlay.png'; import { getSecurityLevel } from '@/components/homescreen/cardSecurityBadge'; +import { cardStyles } from '@/components/homescreen/cardStyles'; import KycIdCard from '@/components/homescreen/KycIdCard'; +import { useCardDimensions } from '@/hooks/useCardDimensions'; import { getBackgroundIndex } from '@/utils/cardBackgroundSelector'; import { getDocumentAttributes } from '@/utils/documentAttributes'; @@ -292,6 +294,19 @@ const IdCardLayout: FC = ({ selected, hidden, }) => { + // Call hooks at the top, before any conditional returns + const { + cardWidth, + cardHeight, + borderRadius, + scale, + headerHeight, + figmaPadding, + logoSize, + headerGap, + fontSize, + } = useCardDimensions(selected); + if (!idDocument) { return null; } @@ -302,13 +317,6 @@ const IdCardLayout: FC = ({