Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Official Expo team skill for building native UI in Expo apps, fine-tuned for Opus models and usable with Claude Code or Cursor.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/controls.md
1# Native Controls23Native iOS controls provide built-in haptics, accessibility, and platform-appropriate styling.45## Switch67Use for binary on/off settings. Has built-in haptics.89```tsx10import { Switch } from "react-native";11import { useState } from "react";1213const [enabled, setEnabled] = useState(false);1415<Switch value={enabled} onValueChange={setEnabled} />;16```1718### Customization1920```tsx21<Switch22value={enabled}23onValueChange={setEnabled}24trackColor={{ false: "#767577", true: "#81b0ff" }}25thumbColor={enabled ? "#f5dd4b" : "#f4f3f4"}26ios_backgroundColor="#3e3e3e"27/>28```2930## Segmented Control3132Use for non-navigational tabs or mode selection. Avoid changing default colors.3334```tsx35import SegmentedControl from "@react-native-segmented-control/segmented-control";36import { useState } from "react";3738const [index, setIndex] = useState(0);3940<SegmentedControl41values={["All", "Active", "Done"]}42selectedIndex={index}43onChange={({ nativeEvent }) => setIndex(nativeEvent.selectedSegmentIndex)}44/>;45```4647### Rules4849- Maximum 4 options — use a picker for more50- Keep labels short (1-2 words)51- Avoid custom colors — native styling adapts to dark mode5253### With Icons (iOS 14+)5455```tsx56<SegmentedControl57values={[58{ label: "List", icon: "list.bullet" },59{ label: "Grid", icon: "square.grid.2x2" },60]}61selectedIndex={index}62onChange={({ nativeEvent }) => setIndex(nativeEvent.selectedSegmentIndex)}63/>64```6566## Slider6768Continuous value selection.6970```tsx71import Slider from "@react-native-community/slider";72import { useState } from "react";7374const [value, setValue] = useState(0.5);7576<Slider77value={value}78onValueChange={setValue}79minimumValue={0}80maximumValue={1}81/>;82```8384### Customization8586```tsx87<Slider88value={value}89onValueChange={setValue}90minimumValue={0}91maximumValue={100}92step={1}93minimumTrackTintColor="#007AFF"94maximumTrackTintColor="#E5E5EA"95thumbTintColor="#007AFF"96/>97```9899### Discrete Steps100101```tsx102<Slider103value={value}104onValueChange={setValue}105minimumValue={0}106maximumValue={10}107step={1}108/>109```110111## Date/Time Picker112113Compact pickers with popovers. Has built-in haptics.114115```tsx116import DateTimePicker from "@react-native-community/datetimepicker";117import { useState } from "react";118119const [date, setDate] = useState(new Date());120121<DateTimePicker122value={date}123onChange={(event, selectedDate) => {124if (selectedDate) setDate(selectedDate);125}}126mode="datetime"127/>;128```129130### Modes131132- `date` — Date only133- `time` — Time only134- `datetime` — Date and time135136### Display Styles137138```tsx139// Compact inline (default)140<DateTimePicker value={date} mode="date" />141142// Spinner wheel143<DateTimePicker144value={date}145mode="date"146display="spinner"147style={{ width: 200, height: 150 }}148/>149150// Full calendar151<DateTimePicker value={date} mode="date" display="inline" />152```153154### Time Intervals155156```tsx157<DateTimePicker158value={date}159mode="time"160minuteInterval={15}161/>162```163164### Min/Max Dates165166```tsx167<DateTimePicker168value={date}169mode="date"170minimumDate={new Date(2020, 0, 1)}171maximumDate={new Date(2030, 11, 31)}172/>173```174175## Stepper176177Increment/decrement numeric values.178179```tsx180import { Stepper } from "react-native";181import { useState } from "react";182183const [count, setCount] = useState(0);184185<Stepper186value={count}187onValueChange={setCount}188minimumValue={0}189maximumValue={10}190/>;191```192193## TextInput194195Native text input with various keyboard types.196197```tsx198import { TextInput } from "react-native";199200<TextInput201placeholder="Enter text..."202placeholderTextColor="#999"203style={{204padding: 12,205fontSize: 16,206borderRadius: 8,207backgroundColor: "#f0f0f0",208}}209/>210```211212### Keyboard Types213214```tsx215216<TextInput keyboardType="email-address" autoCapitalize="none" />217218// Phone219<TextInput keyboardType="phone-pad" />220221// Number222<TextInput keyboardType="numeric" />223224// Password225<TextInput secureTextEntry />226227// Search228<TextInput229returnKeyType="search"230enablesReturnKeyAutomatically231/>232```233234### Multiline235236```tsx237<TextInput238multiline239numberOfLines={4}240textAlignVertical="top"241style={{ minHeight: 100 }}242/>243```244245## Picker (Wheel)246247For selection from many options (5+ items).248249```tsx250import { Picker } from "@react-native-picker/picker";251import { useState } from "react";252253const [selected, setSelected] = useState("js");254255<Picker selectedValue={selected} onValueChange={setSelected}>256<Picker.Item label="JavaScript" value="js" />257<Picker.Item label="TypeScript" value="ts" />258<Picker.Item label="Python" value="py" />259<Picker.Item label="Go" value="go" />260</Picker>;261```262263## Best Practices264265- **Haptics**: Switch and DateTimePicker have built-in haptics — don't add extra266- **Accessibility**: Native controls have proper accessibility labels by default267- **Dark Mode**: Avoid custom colors — native styling adapts automatically268- **Spacing**: Use consistent padding around controls (12-16pt)269- **Labels**: Place labels above or to the left of controls270- **Grouping**: Group related controls in sections with headers271