Tutorial: the dashboard on iOS and Android
This follows the Web sales dashboard. Reuse its sample data and chart component. On Native, give the screen a safe area and use scroll views instead of CSS overflow. No browser or WebView is involved.
The packed-consumer check builds each step with Metro for iOS and Android. That checks compilation and module resolution, not what appears on a device. The run-through at the end is a manual check.
1. Set up Metro and show the figures
Section titled “1. Set up Metro and show the figures”Start with a running React Native CLI app, using the
Metro guide. Keep its app name, index.js and
platform projects. In an Expo project use expo/metro-config as described
in the Metro guide instead; the checked build below uses React Native CLI.
npm install --save-dev @hozo/metro @hozo/compilernpm install @hozo/core @hozo/ui react-native-safe-area-contextReplace your Metro config with this file (rename the starter’s
metro.config.js to metro.config.cjs so there is only one config):
const { getDefaultConfig } = require('@react-native/metro-config')const { withHozo } = require('@hozo/metro/config')module.exports = withHozo(getDefaultConfig(__dirname), { css: 'theme.css' })@import "tailwindcss";@import "@hozo/ui/theme.css";Copy src/data.ts from step 2 of the Web tutorial
without changes. Place the following files at the app root and under
src/ as named:
If your project type-checks with TypeScript, set allowImportingTsExtensions
to true in tsconfig.json so the explicit .ts and .tsx imports work.
import { Heading, ScrollView, View } from '@hozo/core'import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'import { DashboardBody } from './src/DashboardBody.tsx'export default function App() { return ( <SafeAreaProvider> <SafeAreaView style={{ flex: 1 }}> <ScrollView className="flex-1 bg-hozo-surface-sunken"> <View className="gap-4 p-4"> <Heading level={1} className="text-2xl font-bold text-hozo-text"> Sales overview </Heading> <DashboardBody /> </View> </ScrollView> </SafeAreaView> </SafeAreaProvider> )}import { Text, View } from '@hozo/core'import { Card, Stack } from '@hozo/ui'import { money, ORDERS, REVENUE } from './data.ts'export function KeyFigures() { const revenue = REVENUE.reduce((sum, month) => sum + month.online + month.store, 0) const online = REVENUE.reduce((sum, month) => sum + month.online, 0) const figures = [ { label: 'Revenue', value: money(revenue) }, { label: 'Online share', value: `${Math.round((online / revenue) * 100)}%` }, { label: 'Orders this week', value: String(ORDERS.length) }, ] return ( <View className="gap-4"> {figures.map((figure) => ( <Card key={figure.label}> <Stack gap="tight"> <Text className="text-sm text-hozo-text-muted">{figure.label}</Text> <Text className="text-2xl font-bold text-hozo-text">{figure.value}</Text> </Stack> </Card> ))} </View> )}import { KeyFigures } from './KeyFigures.tsx'export function DashboardBody() { return <KeyFigures />}The cards stack vertically on a phone. SafeAreaView reserves system-bar
space; ScrollView scrolls when the content is taller than the screen.
2. Reuse the chart
Section titled “2. Reuse the chart”npm install @hozo/charts react-native-svgFor the RN CLI on iOS, run npx pod-install after adding native dependencies
and rebuild the app. On Android, rebuild too so autolinking includes the SVG
renderer. In Expo, install native peers with npx expo install react-native-svg react-native-safe-area-context
to use the versions supported by your SDK.
Copy src/RevenueChart.tsx from
step 3 of the Web tutorial without changing it.
The LineChart draws using the Native SVG renderer, and
SegmentedControl uses the same React state and data as on the Web.
import { KeyFigures } from './KeyFigures.tsx'import { RevenueChart } from './RevenueChart.tsx'export function DashboardBody() { return ( <> <KeyFigures /> <RevenueChart /> </> )}3. Add the scrolling orders table
Section titled “3. Add the scrolling orders table”Keep the same Table family and Badge, but replace the browser’s
overflow-x-auto wrapper with a horizontal ScrollView. Give the table a
minimum width so the columns can scroll instead of squeezing into a small
handset viewport.
import { Heading, ScrollView, Table, TableBody, TableCell, TableHead, TableHeader, TableRow,} from '@hozo/core'import { Badge, Card, Stack } from '@hozo/ui'import { money, ORDERS } from './data.ts'const TONE = { Paid: 'accent', Shipped: 'neutral', Refunded: 'danger' } as constconst HEADINGS = ['Order', 'Customer', 'Total', 'Status']export function RecentOrders() { return ( <Card> <Stack gap="normal"> <Heading level={2} className="text-lg font-semibold text-hozo-text"> Recent orders </Heading> <ScrollView horizontal> <Table accessibilityLabel="Recent orders" className="min-w-[440px]"> <TableHeader> <TableRow> {HEADINGS.map((label) => ( <TableHead key={label} scope="col" className="p-2 font-semibold"> {label} </TableHead> ))} </TableRow> </TableHeader> <TableBody> {ORDERS.map((order) => ( <TableRow key={order.id}> <TableCell className="p-2">{order.id}</TableCell> <TableCell className="p-2">{order.customer}</TableCell> <TableCell className="p-2">{money(order.total)}</TableCell> <TableCell className="p-2"> <Badge tone={TONE[order.status]}>{order.status}</Badge> </TableCell> </TableRow> ))} </TableBody> </Table> </ScrollView> </Stack> </Card> )}import { KeyFigures } from './KeyFigures.tsx'import { RecentOrders } from './RecentOrders.tsx'import { RevenueChart } from './RevenueChart.tsx'export function DashboardBody() { return ( <> <KeyFigures /> <RevenueChart /> <RecentOrders /> </> )}Check on a device
Section titled “Check on a device”Use the RN starter’s npm run android or npm run ios on the relevant host.
Verify that the three figures are visible, that tapping “3 months” changes
the plotted range, and that you can scroll the table sideways without
losing vertical scrolling on the screen. Switch the system between light
and dark, and check the chart labels and table text in both.
With TalkBack or VoiceOver, check the range control, chart values and order headers. A Metro bundle alone can’t tell you what the screen reader announces.