Examples
Rate your stay
A review after a trip: the place's average for reference, your own rating in half stars, a score for each part of the stay, and a few words. Post review waits for the overall rating.
Loading…
import { useState } from 'react'; import { ScrollView, StyleSheet, View } from 'react-native'; import { Button, Card, CardContent, Heading, HStack, Rating, Text, TextArea, useTheme } from 'patine-ui'; const PLACE = { name: 'Casa do Mar', city: 'Ericeira', average: 4.6, reviews: 312 }; const CATEGORIES = ['Cleanliness', 'Location', 'Value']; const WORDS = ['', 'Awful', 'Poor', 'Okay', 'Good', 'Excellent']; export default function RateYourStay() { const { colors } = useTheme(); const [overall, setOverall] = useState(0); const [scores, setScores] = useState<Record<string, number>>({}); const [text, setText] = useState(''); const [posting, setPosting] = useState(false); const [posted, setPosted] = useState(false); const post = () => { setPosting(true); setTimeout(() => { setPosting(false); setPosted(true); }, 1000); }; return ( <View style={[styles.screen, { backgroundColor: colors.background }]}> <ScrollView contentContainerStyle={styles.content} keyboardShouldPersistTaps="handled"> <Heading level={2}>Rate your stay</Heading> <Card> <CardContent style={styles.place}> <Text weight="semibold"> {PLACE.name} · {PLACE.city} </Text> <HStack gap="sm" align="center"> <Rating value={PLACE.average} readOnly size={16} accessibilityLabel={`Average ${PLACE.average} out of 5`} /> <Text size="sm" color="textSecondary"> {PLACE.average} · {PLACE.reviews} reviews </Text> </HStack> </CardContent> </Card> <View style={styles.overall}> <HStack justify="space-between"> <Text weight="medium">Your rating</Text> <Text color="textSecondary">{overall ? `${overall} of 5 · ${WORDS[Math.ceil(overall)]}` : 'Tap the stars'}</Text> </HStack> <Rating step={0.5} size={40} value={overall} onValueChange={setOverall} accessibilityLabel="Your rating" /> </View> {CATEGORIES.map((category) => ( <HStack key={category} justify="space-between" align="center"> <Text>{category}</Text> <Rating size={22} value={scores[category] ?? 0} onValueChange={(value) => setScores((all) => ({ ...all, [category]: value }))} accessibilityLabel={category} /> </HStack> ))} <TextArea label="Tell other travellers" placeholder="What made it, what could be better" value={text} onValueChange={setText} maxLength={500} showCount minRows={3} /> </ScrollView> <View style={styles.footer}> <Button size="lg" loading={posting} disabled={!overall || posted} onPress={post}> {posted ? 'Thanks for your review' : 'Post review'} </Button> </View> </View> ); } const styles = StyleSheet.create({ screen: { flex: 1 }, content: { gap: 18, padding: 20 }, place: { gap: 6, paddingTop: 16 }, overall: { gap: 8 }, footer: { padding: 16 }, });
Components used
- Rating:
readOnlyfor the average,step={0.5}for half stars, and smaller rows per category - TextArea: the written review with a counter
- Card, Button, Heading, Text, HStack
How it works
- Half stars. With
step={0.5}, a tap on a star's left half gives the half; screen readers and arrow keys move in halves too. - A word for the number. The label beside Your rating says what the stars mean, so 4 reads as "Good" rather than a bare digit.