Pressable is a lower level primitive if you need more flexibility than a button and access to hover, pressed and focus events.
Pressable accepts most of the utility style system props.
function Example() {
return <Pressable onPress={() => Alert.alert("hello")} p={2} borderWidth={1} _light={{
borderColor: "dark.200"
}} _dark={{
borderColor: "dark.600"
}}>
<Text>hello world</Text>
</Pressable>;
}
Accessing events (hover, focus and pressed)
Pressable accepts a render prop children, which receives isHovered, isFocused and isPressed props.
function Example() {
return <Pressable p={4} borderWidth={1} _light={{
borderColor: "dark.200"
}} _dark={{
borderColor: "dark.600"
}}>
{({
isHovered,
isFocused,
isPressed
}) => {
return <Text>
Pressable is in state{" :: "}
{isPressed ? "pressed" : isHovered ? "hovered" : isFocused ? "focused" : ""}
</Text>;
}}
</Pressable>;
}
Pressable implements
,
,
,
,
,
,
,
,
,
,
,
,
,
Called when a mouse enters the Pressable
Called when a mouse leaves the Pressable
Called when Pressable receives focus
Called when Pressable loses focus
Style props to be applied when hovered
Style props to be applied when pressed
Style props to be applied when focus
Style props to be applied when disabled
Style props to be applied when focus visible. These styles will be only applied when user is interacting the app using a keyboard. (Web only)
Either children or a render prop that receives a boolean reflecting whether the component is currently pressed.
Type: ReactNode | (({ isPressed, isHovered, isFocused, }: { isPressed: boolean; isHovered: boolean; isFocused: boolean; }) => any)