Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 2x 9x | import { useState } from 'react';
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useWindowDimensions } from 'react-native';
import { PlusCircleIcon } from '@repo/ui/icons/PlusCircle';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { useTheme } from '@repo/ui/themes/ThemeContext';
import { textStyles } from '@repo/ui/themes/typography';
import { ASSETS } from '@/constants/assets';
const BASE_WIDTH = 375;
const BALLOON_SIZE = 400;
const BALLOON_PADDING = 30;
const TEXT_SIZE = 38;
const MASCOT_WIDTH = 150;
const MASCOT_HEIGHT = 200;
const MASCOT_OFFSET = 0;
const CONNECTOR_HEIGHT = 64;
const BUTTON_SIZE = 60;
const MIN_IMAGE_BUTTON_SPACING = 10;
const BALLOON_WRAPPER_TOP_PERCENT_MIN = -0.1;
const BALLOON_WRAPPER_TOP_PERCENT_MAX = -0.35;
interface NewRequestCardProps {
onPress?: () => void;
}
export const NewRequestCard = ({ onPress }: NewRequestCardProps) => {
const { theme } = useTheme();
const styles = useStyles();
const [containerHeight, setContainerHeight] = useState(500);
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
const scaleW = screenWidth / BASE_WIDTH;
const scaleH = screenHeight / 812;
const scale = Math.min(scaleW, scaleH);
const balloonSize = BALLOON_SIZE * scale;
const fontSize = TEXT_SIZE * scale;
const mascotWidth = MASCOT_WIDTH * scale;
const mascotHeight = MASCOT_HEIGHT * scale;
const mascotBottom = MASCOT_OFFSET * scale;
const textPaddingBottom = BALLOON_PADDING * scale;
const scaledConnectorHeight = CONNECTOR_HEIGHT * scale;
const verticalProgress = Math.min(Math.max((812 - containerHeight) / (812 - 500), 0), 1);
const currentPercent =
BALLOON_WRAPPER_TOP_PERCENT_MIN +
(BALLOON_WRAPPER_TOP_PERCENT_MAX - BALLOON_WRAPPER_TOP_PERCENT_MIN) * verticalProgress;
const balloonWrapperTop = containerHeight * currentPercent;
const balloonBottom = balloonWrapperTop + balloonSize;
const connectorBottom = balloonBottom + scaledConnectorHeight;
const buttonBottomPosition = connectorBottom + BUTTON_SIZE;
const maxImageHeight =
containerHeight + mascotBottom - buttonBottomPosition - MIN_IMAGE_BUTTON_SPACING;
const imageStyle = maxImageHeight > 0 ? { maxHeight: maxImageHeight } : undefined;
return (
<View style={styles.container} onLayout={e => setContainerHeight(e.nativeEvent.layout.height)}>
<View style={[styles.balloonWrapper, { top: balloonWrapperTop }]}>
<View style={styles.centerContent}>
<View style={[styles.balloonContainer, { width: balloonSize, height: balloonSize }]}>
<View style={styles.balloonBorder} />
<View style={styles.balloon}>
<View style={[styles.textWrapper, { paddingBottom: textPaddingBottom }]}>
<Text style={[styles.text, { fontSize }]}>CREATE A NEW</Text>
<Text style={[styles.text, { fontSize }]}>REQUEST?</Text>
</View>
</View>
</View>
<View style={[styles.connector, { height: scaledConnectorHeight }]} />
<View style={styles.buttonWrapper}>
<TouchableOpacity
onPress={onPress}
accessibilityRole="button"
accessibilityLabel="Create new request"
accessibilityHint="Open the screen to create a new request"
style={styles.button}
>
<PlusCircleIcon color={theme.colors.white} />
</TouchableOpacity>
</View>
</View>
</View>
<View style={[styles.mascotContainer, { bottom: mascotBottom }]}>
<Image
source={ASSETS.IMAGES.COFFEE_MASCOT}
style={[{ width: mascotWidth, height: mascotHeight }, imageStyle]}
resizeMode="contain"
/>
</View>
</View>
);
};
const useStyles = makeStyles(theme => ({
container: {
...StyleSheet.absoluteFillObject,
flex: 1,
backgroundColor: theme.colors.background.secondary,
borderRadius: theme.metrics.borderRadius[6],
overflow: 'hidden',
shadowColor: theme.colors.shadow.black,
shadowOffset: { width: theme.metrics.spacing[0], height: theme.metrics.spacing[0.5] },
shadowOpacity: 0.1,
shadowRadius: 8,
elevation: 5,
justifyContent: 'flex-end',
},
balloonWrapper: {
position: 'absolute',
left: theme.metrics.spacing[0],
right: theme.metrics.spacing[0],
},
centerContent: {
alignItems: 'center',
},
balloonContainer: {
position: 'relative',
},
balloonBorder: {
position: 'absolute',
width: theme.metrics.sizing.full,
height: theme.metrics.sizing.full,
borderRadius: theme.metrics.borderRadius.circle,
borderWidth: theme.metrics.borderWidth.default,
borderColor: theme.colors.text.primary,
transform: [{ translateX: 15 }, { translateY: -5 }],
zIndex: 10,
},
balloon: {
width: theme.metrics.sizing.full,
height: theme.metrics.sizing.full,
borderRadius: theme.metrics.borderRadius.circle,
backgroundColor: theme.colors.badge.medium,
justifyContent: 'flex-end',
},
textWrapper: {
gap: theme.metrics.spacing[1],
marginBottom: theme.metrics.spacing[10],
},
text: {
color: theme.colors.text.white,
textAlign: 'center',
...textStyles.title,
},
connector: {
width: theme.metrics.spacing[0.25],
height: theme.metrics.spacing[16],
backgroundColor: theme.colors.text.primary,
},
buttonWrapper: {
width: BUTTON_SIZE,
height: BUTTON_SIZE,
borderRadius: theme.metrics.borderRadius.circle,
backgroundColor: theme.colors.badge.medium,
alignItems: 'center',
justifyContent: 'center',
},
button: {
width: theme.metrics.spacing[10],
height: theme.metrics.spacing[10],
borderRadius: theme.metrics.borderRadius.circle,
borderWidth: theme.metrics.borderWidth[2],
borderColor: theme.colors.text.white,
alignItems: 'center',
justifyContent: 'center',
},
mascotContainer: {
position: 'absolute',
left: theme.metrics.spacing[0],
right: theme.metrics.spacing[0],
alignItems: 'center',
justifyContent: 'flex-end',
},
}));
|