mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
45 lines
36 KiB
HTML
45 lines
36 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<meta name="generator" content="Docusaurus v2.0.0-alpha.66">
|
|
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="React Native Blog RSS Feed">
|
|
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="React Native Blog Atom Feed">
|
|
<link rel="preconnect" href="https://www.google-analytics.com">
|
|
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-41298772-2","auto"),ga("send","pageview")</script>
|
|
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
|
<link rel="preconnect" href="https://www.google-analytics.com">
|
|
<link rel="preconnect" href="https://www.googletagmanager.com">
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-41298772-2"></script>
|
|
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","UA-41298772-2",{})</script>
|
|
<link rel="search" type="application/opensearchdescription+xml" title="React Native" href="/opensearch.xml">
|
|
<script src="https://cdn.jsdelivr.net/npm/focus-visible@5.2.0/dist/focus-visible.min.js" defer="defer"></script>
|
|
<script src="https://snack.expo.io/embed.js" defer="defer"></script><title data-react-helmet="true">Pressable · React Native</title><meta data-react-helmet="true" property="twitter:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" name="twitter:image:alt" content="Image for React Native"><meta data-react-helmet="true" name="docsearch:language" content="en"><meta data-react-helmet="true" name="docsearch:version" content="0.63"><meta data-react-helmet="true" name="docsearch:docusaurus_tag" content="docs-default-0.63"><meta data-react-helmet="true" property="og:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" name="twitter:card" content="summary"><meta data-react-helmet="true" name="twitter:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" property="og:title" content="Pressable · React Native"><meta data-react-helmet="true" name="description" content="Pressable is a Core Component wrapper that can detect various stages of press interactions on any of its defined children."><meta data-react-helmet="true" property="og:description" content="Pressable is a Core Component wrapper that can detect various stages of press interactions on any of its defined children."><meta data-react-helmet="true" property="og:url" content="https://reactnative.dev/docs/pressable"><link data-react-helmet="true" rel="shortcut icon" href="/img/favicon.ico"><link data-react-helmet="true" rel="preconnect" href="https://BH4D9OD16A-dsn.algolia.net" crossorigin="anonymous"><link data-react-helmet="true" rel="canonical" href="https://reactnative.dev/docs/pressable"><link rel="stylesheet" href="/styles.654d26b0.css">
|
|
<link rel="stylesheet" href="/main.c541a094.css">
|
|
<link rel="preload" href="/styles.cc2cf098.js" as="script">
|
|
<link rel="preload" href="/runtime~main.9893e186.js" as="script">
|
|
<link rel="preload" href="/main.259a8b48.js" as="script">
|
|
<link rel="preload" href="/1.55a8a1b3.js" as="script">
|
|
<link rel="preload" href="/2.8585ac8b.js" as="script">
|
|
<link rel="preload" href="/1f391b9e.8301d553.js" as="script">
|
|
<link rel="preload" href="/939.3c971b89.js" as="script">
|
|
<link rel="preload" href="/ee5b3385.4adebc95.js" as="script">
|
|
<link rel="preload" href="/17896441.6dff1a67.js" as="script">
|
|
<link rel="preload" href="/d13ff743.8249b111.js" as="script">
|
|
</head>
|
|
<body>
|
|
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
|
|
<nav class="navbar navbar--fixed-top navbar--dark"><div class="navbar__inner"><div class="navbar__items"><div aria-label="Navigation bar toggle" class="navbar__toggle" role="button" tabindex="0"><svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></div><a class="navbar__brand" href="/"><img class="navbar__logo" src="/img/header_logo.svg" alt="React Native"><strong class="navbar__title">React Native</strong></a><div class="navbar__item dropdown dropdown--hoverable dropdown--left"><a class="navbar__item navbar__link" href="/docs/getting-started">0.63</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/docs/next/pressable">Next</a></li><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/docs/pressable">0.63</a></li><li><a class="dropdown__link" href="/docs/0.62/getting-started">0.62</a></li><li><a class="dropdown__link" href="/docs/0.61/getting-started">0.61</a></li><li><a class="dropdown__link" href="/docs/0.60/getting-started">0.60</a></li><li><a class="dropdown__link" href="/versions">All versions</a></li></ul></div></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/docs/getting-started">Docs</a><a class="navbar__item navbar__link navbar__link--active" href="/docs/components-and-apis">Components</a><a class="navbar__item navbar__link" href="/docs/accessibilityinfo">API</a><a class="navbar__item navbar__link" href="/help">Community</a><a class="navbar__item navbar__link" href="/blog">Blog</a><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar-github-link" aria-label="GitHub repository"></a><div class="react-toggle react-toggle--disabled displayOnlyInLargeViewport_3lWe"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_gnXW">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_gnXW">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" disabled="" aria-label="Dark mode toggle" class="react-toggle-screenreader-only"></div><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span><span class="DocSearch-Button-Key">⌘</span><span class="DocSearch-Button-Key">K</span></button></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img class="navbar__logo" src="/img/header_logo.svg" alt="React Native"><strong class="navbar__title">React Native</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/getting-started">Docs</a></li><li class="menu__list-item"><a class="menu__link navbar__link--active" href="/docs/components-and-apis">Components</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/accessibilityinfo">API</a></li><li class="menu__list-item"><a class="menu__link" href="/help">Community</a></li><li class="menu__list-item"><a class="menu__link" href="/blog">Blog</a></li><li class="menu__list-item"><a role="button" class="menu__link menu__link--sublist">Versions</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/next/pressable">Next</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active" href="/docs/pressable">0.63</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.62/getting-started">0.62</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.61/getting-started">0.61</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.60/getting-started">0.60</a></li><li class="menu__list-item"><a class="menu__link" href="/versions">All versions</a></li></ul></li><li class="menu__list-item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="menu__link navbar-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><div class="docPage_2UBv"><div class="docSidebarContainer_1hqR" role="complementary"><div class="sidebar_MSwm"><div class="menu menu--responsive menu_2hiu"><button aria-label="Open Menu" aria-haspopup="true" class="button button--secondary button--sm menu__button" type="button"><svg aria-label="Menu" class="sidebarMenuIcon_37TU" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 32 32" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><ul class="menu__list"><li class="menu__list-item"><a class="menu__link menu__link--sublist menu__link--active" href="#!">Core Components</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/components-and-apis">Core Components and APIs</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/activityindicator">ActivityIndicator</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/button">Button</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/flatlist">FlatList</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/image">Image</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/imagebackground">ImageBackground</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/keyboardavoidingview">KeyboardAvoidingView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/modal">Modal</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active active" tabindex="0" href="/docs/pressable">Pressable</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/refreshcontrol">RefreshControl</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/scrollview">ScrollView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/sectionlist">SectionList</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/statusbar">StatusBar</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/switch">Switch</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/text">Text</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/textinput">TextInput</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/touchablehighlight">TouchableHighlight</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/touchableopacity">TouchableOpacity</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/touchablewithoutfeedback">TouchableWithoutFeedback</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/view">View</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/virtualizedlist">VirtualizedList</a></li><li class="menu__list-item"><a class="menu__link menu__link--sublist" href="#!" tabindex="0">Android Components</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/drawerlayoutandroid">DrawerLayoutAndroid</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/touchablenativefeedback">TouchableNativeFeedback</a></li></ul></li><li class="menu__list-item"><a class="menu__link menu__link--sublist" href="#!" tabindex="0">iOS Components</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/inputaccessoryview">InputAccessoryView</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/maskedviewios">🚧 MaskedViewIOS</a></li><li class="menu__list-item"><a class="menu__link" tabindex="0" href="/docs/safeareaview">SafeAreaView</a></li></ul></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Props</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/image-style-props">Image Style Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/layout-props">Layout Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/shadow-props">Shadow Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/text-style-props">Text Style Props</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/view-style-props">View Style Props</a></li></ul></li><li class="menu__list-item menu__list-item--collapsed"><a class="menu__link menu__link--sublist" href="#!">Object Types</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/pressevent">PressEvent Object Type</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/react-node">React Node Object Type</a></li><li class="menu__list-item"><a class="menu__link" tabindex="-1" href="/docs/rect">Rect Object Type</a></li></ul></li></ul></div></div></div><main class="docMainContainer_1rYT"><div class="container padding-vert--lg docItemWrapper_1Hme"><div class="row"><div class="col docItemCol_2AGf"><div class="docItemContainer_1tAC"><article><header><h1 class="docTitle_cWlf">Pressable</h1></header><div class="markdown"><p>Pressable is a Core Component wrapper that can detect various stages of press interactions on any of its defined children.</p><div class="mdxCodeBlock_xYIz"><div class="codeBlockContent_rlEb"><button tabindex="0" type="button" aria-label="Copy code to clipboard" class="copyButton_kOW4">Copy</button><div class="prism-code language-jsx codeBlock_1AP7"><div class="codeBlockLines_1boI" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token tag punctuation" style="color:#657b83"><</span><span class="token tag class-name" style="color:#fac863">Pressable</span><span class="token tag" style="color:#fc929e"> </span><span class="token tag attr-name" style="color:#c5a5c5">onPress</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:#657b83">=</span><span class="token tag script language-javascript punctuation" style="color:#657b83">{</span><span class="token tag script language-javascript" style="color:#fc929e">onPressFunction</span><span class="token tag script language-javascript punctuation" style="color:#657b83">}</span><span class="token tag punctuation" style="color:#657b83">></span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token tag punctuation" style="color:#657b83"><</span><span class="token tag class-name" style="color:#fac863">Text</span><span class="token tag punctuation" style="color:#657b83">></span><span class="token constant" style="color:#5a9bcf">I</span><span class="token plain">'m pressable</span><span class="token operator" style="color:#fc929e">!</span><span class="token tag punctuation" style="color:#657b83"></</span><span class="token tag class-name" style="color:#fac863">Text</span><span class="token tag punctuation" style="color:#657b83">></span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"></span><span class="token tag punctuation" style="color:#657b83"></</span><span class="token tag class-name" style="color:#fac863">Pressable</span><span class="token tag punctuation" style="color:#657b83">></span></div></div></div></div></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="how-it-works"></a>How it works<a aria-hidden="true" tabindex="-1" class="hash-link" href="#how-it-works" title="Direct link to heading">#</a></h2><p>On an element wrapped by <code>Pressable</code>:</p><ul><li><a href="#onpressin"><code>onPressIn</code></a> is called when a press is activated.</li><li><a href="#onpressout"><code>onPressOut</code></a> is called when the press gesture is deactivated.</li></ul><p>After pressing <a href="#onpressin"><code>onPressIn</code></a>, one of two things will happen:</p><ol><li>The person will remove their finger, triggering <a href="#onpressout"><code>onPressOut</code></a> followed by <a href="#onpress"><code>onPress</code></a>.</li><li>If the person leaves their finger longer than 500 milliseconds before removing it, <a href="#onlongpress"><code>onLongPress</code></a> is triggered. (<a href="#onpressout"><code>onPressOut</code></a> will still fire when they remove their finger.)</li></ol><img src="/docs/assets/d_pressable_pressing.svg" width="1000" alt="Diagram of the onPress events in sequence."><p>Fingers are not the most precise instruments, and it is common for users to accidentally activate the wrong element or miss the activation area. To help, <code>Pressable</code> has an optional <code>HitRect</code> you can use to define how far a touch can register away from the wrapped element. Presses can start anywhere within a <code>HitRect</code>.</p><p><code>PressRect</code> allows presses to move beyond the element and its <code>HitRect</code> while maintaining activation and being eligible for a "press"—think of sliding your finger slowly away from a button you're pressing down on.</p><blockquote><p>The touch area never extends past the parent view bounds and the Z-index of sibling views always takes precedence if a touch hits two overlapping views.</p></blockquote><figure><img src="/docs/assets/d_pressable_anatomy.svg" width="1000" alt="Diagram of HitRect and PressRect and how they work."><figcaption>You can set <code>HitRect</code> with <code>hitSlop</code> and set <code>PressRect</code> with <code>pressRetentionOffset</code>.</figcaption></figure><blockquote><p><code>Pressable</code> uses React Native's <code>Pressability</code> API. For more information around the state machine flow of Pressability and how it works, check out the implementation for <a href="https://github.com/facebook/react-native/blob/16ea9ba8133a5340ed6751ec7d49bf03a0d4c5ea/Libraries/Pressability/Pressability.js#L347" target="_blank" rel="noopener noreferrer">Pressability</a>.</p></blockquote><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="example"></a>Example<a aria-hidden="true" tabindex="-1" class="hash-link" href="#example" title="Direct link to heading">#</a></h2><div class="snack-player" data-snack-name="Pressable" data-snack-description="Example usage" data-snack-code="import%20React%2C%20%7B%20useState%20%7D%20from%20'react'%3B%0Aimport%20%7B%20Pressable%2C%20StyleSheet%2C%20Text%2C%20View%20%7D%20from%20'react-native'%3B%0A%0Aconst%20App%20%3D%20()%20%3D%3E%20%7B%0A%20%20const%20%5BtimesPressed%2C%20setTimesPressed%5D%20%3D%20useState(0)%3B%0A%0A%20%20let%20textLog%20%3D%20''%3B%0A%20%20if%20(timesPressed%20%3E%201)%20%7B%0A%20%20%20%20textLog%20%3D%20timesPressed%20%2B%20'x%20onPress'%3B%0A%20%20%7D%20else%20if%20(timesPressed%20%3E%200)%20%7B%0A%20%20%20%20textLog%20%3D%20'onPress'%3B%0A%20%20%7D%0A%0A%20%20return%20(%0A%20%20%20%20%3CView%20style%3D%7Bstyles.container%7D%3E%0A%20%20%20%20%20%20%3CPressable%0A%20%20%20%20%20%20%20%20onPress%3D%7B()%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20setTimesPressed((current)%20%3D%3E%20current%20%2B%201)%3B%0A%20%20%20%20%20%20%20%20%7D%7D%0A%20%20%20%20%20%20%20%20style%3D%7B(%7B%20pressed%20%7D)%20%3D%3E%20%5B%0A%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20backgroundColor%3A%20pressed%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3F%20'rgb(210%2C%20230%2C%20255)'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3A%20'white'%0A%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20styles.wrapperCustom%0A%20%20%20%20%20%20%20%20%5D%7D%3E%0A%20%20%20%20%20%20%20%20%7B(%7B%20pressed%20%7D)%20%3D%3E%20(%0A%20%20%20%20%20%20%20%20%20%20%3CText%20style%3D%7Bstyles.text%7D%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%7Bpressed%20%3F%20'Pressed!'%20%3A%20'Press%20Me'%7D%0A%20%20%20%20%20%20%20%20%20%20%3C%2FText%3E%0A%20%20%20%20%20%20%20%20)%7D%0A%20%20%20%20%20%20%3C%2FPressable%3E%0A%20%20%20%20%20%20%3CView%20style%3D%7Bstyles.logBox%7D%3E%0A%20%20%20%20%20%20%20%20%3CText%20testID%3D%22pressable_press_console%22%3E%7BtextLog%7D%3C%2FText%3E%0A%20%20%20%20%20%20%3C%2FView%3E%0A%20%20%20%20%3C%2FView%3E%0A%20%20)%3B%0A%7D%3B%0A%0Aconst%20styles%20%3D%20StyleSheet.create(%7B%0A%20%20container%3A%20%7B%0A%20%20%20%20flex%3A%201%2C%0A%20%20%20%20justifyContent%3A%20%22center%22%2C%0A%20%20%7D%2C%0A%20%20text%3A%20%7B%0A%20%20%20%20fontSize%3A%2016%0A%20%20%7D%2C%0A%20%20wrapperCustom%3A%20%7B%0A%20%20%20%20borderRadius%3A%208%2C%0A%20%20%20%20padding%3A%206%0A%20%20%7D%2C%0A%20%20logBox%3A%20%7B%0A%20%20%20%20padding%3A%2020%2C%0A%20%20%20%20margin%3A%2010%2C%0A%20%20%20%20borderWidth%3A%20StyleSheet.hairlineWidth%2C%0A%20%20%20%20borderColor%3A%20'%23f0f0f0'%2C%0A%20%20%20%20backgroundColor%3A%20'%23f9f9f9'%0A%20%20%7D%0A%7D)%3B%0A%0Aexport%20default%20App%3B" data-snack-dependencies="" data-snack-platform="web" data-snack-supported-platforms="ios,android,web" data-snack-theme="light" data-snack-preview="true" data-snack-loading="lazy"></div><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="props"></a>Props<a aria-hidden="true" tabindex="-1" class="hash-link" href="#props" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="android_disablesound-android"></a><code>android_disableSound</code> <div class="label android">Android</div><a aria-hidden="true" tabindex="-1" class="hash-link" href="#android_disablesound-android" title="Direct link to heading">#</a></h3><p>If true, doesn't play Android system sound on press.</p><table><thead><tr><th>Type</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td>boolean</td><td>No</td><td><code>false</code></td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="android_ripple-android"></a><code>android_ripple</code> <div class="label android">Android</div><a aria-hidden="true" tabindex="-1" class="hash-link" href="#android_ripple-android" title="Direct link to heading">#</a></h3><p>Enables the Android ripple effect and configures its properties.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/pressable#rippleconfig">RippleConfig</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="children"></a><code>children</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#children" title="Direct link to heading">#</a></h3><p>Either children or a function that receives a boolean reflecting whether the component is currently pressed.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/react-node">React Node</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="delaylongpress"></a><code>delayLongPress</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#delaylongpress" title="Direct link to heading">#</a></h3><p>Duration (in milliseconds) from <code>onPressIn</code> before <code>onLongPress</code> is called.</p><table><thead><tr><th>Type</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td>number</td><td>No</td><td><code>500</code></td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="disabled"></a><code>disabled</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#disabled" title="Direct link to heading">#</a></h3><p>Whether the press behavior is disabled.</p><table><thead><tr><th>Type</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td>boolean</td><td>No</td><td><code>false</code></td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="hitslop"></a><code>hitSlop</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#hitslop" title="Direct link to heading">#</a></h3><p>Sets additional distance outside of element in which a press can be detected.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/rect">Rect</a> or number</td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="onlongpress"></a><code>onLongPress</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#onlongpress" title="Direct link to heading">#</a></h3><p>Called if the time after <code>onPressIn</code> lasts longer than 500 milliseconds. This time period can be customized with <a href="#delaylongpress"><code>delayLongPress</code></a>.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/pressevent">PressEvent</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="onpress"></a><code>onPress</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#onpress" title="Direct link to heading">#</a></h3><p>Called after <code>onPressOut</code>.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/pressevent">PressEvent</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="onpressin"></a><code>onPressIn</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#onpressin" title="Direct link to heading">#</a></h3><p>Called immediately when a touch is engaged, before <code>onPressOut</code> and <code>onPress</code>.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/pressevent">PressEvent</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="onpressout"></a><code>onPressOut</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#onpressout" title="Direct link to heading">#</a></h3><p>Called when a touch is released.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/pressevent">PressEvent</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="pressretentionoffset"></a><code>pressRetentionOffset</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#pressretentionoffset" title="Direct link to heading">#</a></h3><p>Additional distance outside of this view in which a touch is considered a press before <code>onPressOut</code> is triggered.</p><table><thead><tr><th>Type</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td><a href="/docs/rect">Rect</a> or number</td><td>No</td><td><code>{ bottom: 30, left: 20, right: 20, top: 20 }</code></td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="style"></a><code>style</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#style" title="Direct link to heading">#</a></h3><p>Either view styles or a function that receives a boolean reflecting whether the component is currently pressed and returns view styles.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td><a href="/docs/view-style-props">ViewStyleProp</a></td><td>No</td></tr></tbody></table><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="testonly_pressed"></a><code>testOnly_pressed</code><a aria-hidden="true" tabindex="-1" class="hash-link" href="#testonly_pressed" title="Direct link to heading">#</a></h3><p>Used only for documentation or testing (e.g. snapshot testing).</p><table><thead><tr><th>Type</th><th>Required</th><th>Default</th></tr></thead><tbody><tr><td>boolean</td><td>No</td><td><code>false</code></td></tr></tbody></table><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="type-definitions"></a>Type Definitions<a aria-hidden="true" tabindex="-1" class="hash-link" href="#type-definitions" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_3pqN" id="rippleconfig"></a>RippleConfig<a aria-hidden="true" tabindex="-1" class="hash-link" href="#rippleconfig" title="Direct link to heading">#</a></h3><p>Ripple effect configuration for the <code>android_ripple</code> property.</p><table><thead><tr><th>Type</th></tr></thead><tbody><tr><td>object</td></tr></tbody></table><p><strong>Properties:</strong></p><table><thead><tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td>color</td><td><a href="/docs/colors">color</a></td><td>No</td><td>Defines the color of the ripple effect.</td></tr><tr><td>borderless</td><td>boolean</td><td>No</td><td>Defines if ripple effect should not include border.</td></tr><tr><td>radius</td><td>number</td><td>No</td><td>Defines the radius of the ripple effect.</td></tr></tbody></table></div></article><div class="docMetadata margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/facebook/react-native-website/blob/master/website/versioned_docs/version-0.63/pressable.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 40 40" style="margin-right:0.3em;vertical-align:sub"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col text--right"><em><small class="docMetadata-updated">Last updated on <time datetime="2020-10-29T13:04:25.000Z" class="docLastUpdatedAt_1gIo">10/29/2020</time></small></em></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Blog list page navigation"><div class="pagination-nav__item"><a class="pagination-nav__link" href="/docs/modal"><div class="pagination-nav__sublabel">Previous</div><div class="pagination-nav__label">« Modal</div></a></div><div class="pagination-nav__item pagination-nav__item--next"><a class="pagination-nav__link" href="/docs/refreshcontrol"><div class="pagination-nav__sublabel">Next</div><div class="pagination-nav__label">RefreshControl »</div></a></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_3iuQ"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#how-it-works" class="table-of-contents__link">How it works</a></li><li><a href="#example" class="table-of-contents__link">Example</a></li><li><a href="#props" class="table-of-contents__link">Props</a><ul><li><a href="#android_disablesound-android" class="table-of-contents__link"><code>android_disableSound</code> <div class="label android">Android</div></a></li><li><a href="#android_ripple-android" class="table-of-contents__link"><code>android_ripple</code> <div class="label android">Android</div></a></li><li><a href="#children" class="table-of-contents__link"><code>children</code></a></li><li><a href="#delaylongpress" class="table-of-contents__link"><code>delayLongPress</code></a></li><li><a href="#disabled" class="table-of-contents__link"><code>disabled</code></a></li><li><a href="#hitslop" class="table-of-contents__link"><code>hitSlop</code></a></li><li><a href="#onlongpress" class="table-of-contents__link"><code>onLongPress</code></a></li><li><a href="#onpress" class="table-of-contents__link"><code>onPress</code></a></li><li><a href="#onpressin" class="table-of-contents__link"><code>onPressIn</code></a></li><li><a href="#onpressout" class="table-of-contents__link"><code>onPressOut</code></a></li><li><a href="#pressretentionoffset" class="table-of-contents__link"><code>pressRetentionOffset</code></a></li><li><a href="#style" class="table-of-contents__link"><code>style</code></a></li><li><a href="#testonly_pressed" class="table-of-contents__link"><code>testOnly_pressed</code></a></li></ul></li><li><a href="#type-definitions" class="table-of-contents__link">Type Definitions</a><ul><li><a href="#rippleconfig" class="table-of-contents__link">RippleConfig</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/getting-started">Getting Started</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/tutorial">Tutorial</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/components-and-apis">Components and APIs</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/more-resources">More Resources</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/help">The React Native Community</a></li><li class="footer__item"><a class="footer__link-item" href="/showcase">Who's using React Native?</a></li><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">Ask Questions on Stack Overflow</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md" target="_blank" rel="noopener noreferrer" class="footer__link-item">Contributor Guide</a></li><li class="footer__item"><a href="https://dev.to/t/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">DEV Community</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Find us</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/blog">Blog</a></li><li class="footer__item"><a href="https://twitter.com/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://reactjs.org/" target="_blank" rel="noopener noreferrer" class="footer__link-item">React</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/privacy" target="_blank" rel="noopener noreferrer" class="footer__link-item">Privacy Policy</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/terms" target="_blank" rel="noopener noreferrer" class="footer__link-item">Terms of Service</a></li></ul></div></div><div class="text--center"><div class="margin-bottom--sm"><a href="https://opensource.facebook.com" target="_blank" rel="noopener noreferrer" class="footerLogoLink_19Ac"><img class="footer__logo" alt="Facebook Open Source Logo" src="/img/oss_logo.png"></a></div><div>Copyright © 2021 Facebook, Inc.</div></div></div></footer></div>
|
|
<script src="/styles.cc2cf098.js"></script>
|
|
<script src="/runtime~main.9893e186.js"></script>
|
|
<script src="/main.259a8b48.js"></script>
|
|
<script src="/1.55a8a1b3.js"></script>
|
|
<script src="/2.8585ac8b.js"></script>
|
|
<script src="/1f391b9e.8301d553.js"></script>
|
|
<script src="/939.3c971b89.js"></script>
|
|
<script src="/ee5b3385.4adebc95.js"></script>
|
|
<script src="/17896441.6dff1a67.js"></script>
|
|
<script src="/d13ff743.8249b111.js"></script>
|
|
</body>
|
|
</html> |