Skip to main content

View

The basic container. It renders a <div>, or the element that its role picks, with the React Native layout defaults.

import { StyleSheet, View } from 'react-native'

export function Toolbar({ children }) {
return (
<View role="navigation" style={styles.toolbar}>
{children}
</View>
)
}

const styles = StyleSheet.create({
toolbar: { flexDirection: 'row', gap: 8, padding: 12 },
})

Props​

PropOn the web
styleCompiles to atomic CSS. See Styles.
role, accessibilityRolePicks the element. See Semantic HTML.
accessibilityLabel and the other accessibility propsBecome ARIA attributes. See Accessibility props.
onLayoutFires after mount and after each size change, from a ResizeObserver. x and y are relative to the parent view. A move with no size change doesn't fire it.
pointerEventsnone, auto, box-none, and box-only, as on native.
focusable, tabIndexfocusable sets tabIndex to 0, or to -1 for false. tabIndex wins when you set both.
nativeID, id, testIDid, id, and data-testid.
hrefWeb only. Renders an <a>.
aria-levelWeb only. The heading level of role="heading", 1 to 6.
onClick, onKeyDown, and the other DOM handlersWeb only. Every React DOM event handler passes to the element.
collapsable, accessibleAccepted and ignored.

Any other prop that isn't a React Native prop is dropped.

Ref​

The ref is the DOM element, with the measure methods of a native host instance added. Each one calls its callback at once, with CSS pixels.

MethodOn the web
measure(callback)x and y in the parent element, width, height, then pageX and pageY in the window.
measureInWindow(callback)x and y in the window, width, height. The window is the visible area, so the values change when the page scrolls.
measureLayout(ancestor, onSuccess, onFail)left and top in the ancestor element, width, height. It calls onFail when the other node isn't an ancestor that is in the document.
setNativeProps({ style })Writes the style as an inline style, so it beats the style prop until you set it again. Any other prop has no effect and logs a warning.

The sizes come from getBoundingClientRect(), so they include a transform, as measure does on native. The types are HostInstance and ViewInstance.

note

A ref typed as useRef<HTMLElement>(null) no longer fits the ref prop. Use useRef<ViewInstance>(null), as on native.