-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add documentation page for Pressable component
#2992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
290d3db
prepare new pressable docs page
latekvo 3cb6530
add props documentation
latekvo 5d5c6c2
improve a couple of descriptions
latekvo f3190a9
add component description
latekvo a0e7a2a
update example page link and text
latekvo ae8c0cb
add example code
latekvo 86eaeda
add importing section
latekvo 77a0b11
improve prop descriptions
latekvo c25a016
add presentation gif
latekvo 26557d0
fix capitalization and remove dead todo
latekvo 96cb11a
improve prop grouping and platform specification
latekvo 5162390
improve pressable example to reflect documentation more accurately
latekvo 9854dcc
remove accidental line from example
latekvo df0118e
align docs example with repo example
latekvo a017724
Merge branch 'main' into @latekvo/add-pressable-documentation
latekvo aa45acc
improve descriptions
latekvo 29c282d
expand `onLongPress` description
latekvo d3b2757
add drop-in replacement note
latekvo a0efc60
fix naming scheme inconsistency
latekvo 9794c10
remove unnecessary info boxes
latekvo 4f306fb
wrap booleans in inline code blocks
latekvo a34d741
apply wording and capitalization suggestions
latekvo b3c4890
add import statements to example
latekvo f7891d0
remove unnecessary word
latekvo 3388fb1
use oxford notation for a list of actions
latekvo 7cb3872
remove borders from example
latekvo f91708c
add note that hitslop and retentionoffset work only on android and ios
latekvo 51034ef
add param type specifications to non-oblivious props
latekvo 94399de
change phrasing of long press / short press relation description
latekvo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| --- | ||
| id: pressable | ||
| title: Pressable | ||
| sidebar_label: Pressable | ||
| --- | ||
|
|
||
| import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
| import GifGallery from '@site/components/GifGallery'; | ||
|
|
||
| <GifGallery> | ||
| <img src={useBaseUrl('gifs/pressable.gif')} width="70%" /> | ||
| </GifGallery> | ||
|
|
||
| :::info | ||
| This component is a drop-in replacement for the `Pressable` component. | ||
| ::: | ||
|
|
||
| `Pressable` is a component that can detect various stages of tap, press, and hover interactions on any of its children. | ||
|
|
||
| ### Usage: | ||
|
|
||
| To use `Pressable`, import it in the following way: | ||
|
|
||
| ```js | ||
| import { Pressable } from 'react-native-gesture-handler'; | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| ### `children` | ||
|
|
||
| either children or a render function that receives a boolean reflecting whether | ||
| the component is currently pressed. | ||
|
|
||
| ### `style` | ||
|
|
||
| either view styles or a function that receives a boolean reflecting whether | ||
| the component is currently pressed and returns view styles. | ||
|
|
||
| ### `onPress` | ||
|
|
||
| called after `onPressOut` when a single tap gesture is detected. | ||
|
|
||
| ### `onPressIn` | ||
|
|
||
| called before `onPress` when a touch is engaged. | ||
|
|
||
| ### `onPressOut` | ||
|
|
||
| called before `onPress` when a touch is released. | ||
|
|
||
| ### `onLongPress` | ||
|
|
||
| called immidiately after pointer has been down for at least `delayLongPress` milliseconds (`500` ms by default). | ||
|
|
||
| After `onLongPress` has been called, `onPressOut` will be called as soon as the pointer is lifted and `onPress` will not be called at all. | ||
|
|
||
| ### `cancelable` | ||
|
|
||
| whether a press gesture can be interrupted by a parent gesture such as a scroll event. Defaults to `true`. | ||
|
|
||
| ### `onHoverIn` (Web only) | ||
|
|
||
| called when pointer is hovering over the element. | ||
|
|
||
| ### `onHoverOut` (Web only) | ||
|
|
||
| called when pointer stops hovering over the element. | ||
|
|
||
| ### `delayHoverIn` (Web only) | ||
|
|
||
| duration to wait after hover in before calling `onHoverIn`. | ||
|
|
||
| ### `delayHoverOut` (Web only) | ||
|
|
||
| duration to wait after hover out before calling `onHoverOut`. | ||
|
|
||
| ### `delayLongPress` | ||
|
|
||
| duration (in milliseconds) from `onPressIn` before `onLongPress` is called. | ||
|
|
||
| ### `disabled` | ||
|
|
||
| whether the `Pressable` behavior is disabled. | ||
|
|
||
| ### `hitSlop` (Android & iOS only) | ||
|
|
||
| additional distance outside of the view in which a press is detected and `onPressIn` is triggered. | ||
|
|
||
| Accepts values of type `number` or [`Rect`](https://reactnative.dev/docs/rect) | ||
|
|
||
| ### `pressRetentionOffset` (Android & iOS only) | ||
|
|
||
| additional distance outside of the view (or `hitSlop` if present) in which a touch is considered a | ||
| press before `onPressOut` is triggered. | ||
|
|
||
| Accepts values of type `number` or [`Rect`](https://reactnative.dev/docs/rect) | ||
|
|
||
| ### `android_disableSound` (Android only) | ||
|
|
||
| if `true`, doesn't play system sound on touch. | ||
|
|
||
| ### `android_ripple` (Android only) | ||
|
|
||
| enables the Android ripple effect and configures its color, radius and other parameters. | ||
|
|
||
| Accepts values of type [`RippleConfig`](https://reactnative.dev/docs/pressable#rippleconfig) | ||
|
|
||
| ### `testOnly_pressed` | ||
|
|
||
| used only for documentation or testing (e.g. snapshot testing). | ||
|
|
||
| ### `unstable_pressDelay` | ||
|
|
||
| duration (in milliseconds) to wait after press down before calling `onPressIn`. | ||
|
|
||
| ### Example: | ||
|
|
||
| See the full [pressable example](https://github.com/software-mansion/react-native-gesture-handler/blob/main/example/src/new_api/pressable/index.tsx) from `GestureHandler` example app. | ||
|
|
||
| import GestureStateFlowExample from '@site/src/examples/GestureStateFlowExample'; | ||
|
|
||
| ```js | ||
| import { View, Text, StyleSheet } from 'react-native'; | ||
| import { Pressable } from 'react-native-gesture-handler'; | ||
|
|
||
| export default function Example() { | ||
| return ( | ||
| <Pressable | ||
| style={({ pressed }) => (pressed ? styles.highlight : styles.pressable)} | ||
| hitSlop={20} | ||
| pressRetentionOffset={20}> | ||
| <View style={styles.textWrapper}> | ||
| <Text style={styles.text}>Pressable!</Text> | ||
| </View> | ||
| </Pressable> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| pressable: { | ||
| width: 120, | ||
| height: 120, | ||
| backgroundColor: 'mediumpurple', | ||
| borderWidth: StyleSheet.hairlineWidth, | ||
| }, | ||
| highlight: { | ||
| width: 120, | ||
| height: 120, | ||
| backgroundColor: 'red', | ||
| borderWidth: StyleSheet.hairlineWidth, | ||
| }, | ||
| textWrapper: { | ||
| flex: 1, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }, | ||
| text: { | ||
| color: 'black', | ||
| }, | ||
| }); | ||
| ``` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.