-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[Docs] Clickable
#4022
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
Open
m-bert
wants to merge
10
commits into
@mbert/clickable
Choose a base branch
from
@mbert/clickable-docs
base: @mbert/clickable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+290
−1
Open
[Docs] Clickable
#4022
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d422f33
Update SKILL
m-bert db37209
Merge branch '@mbert/clickable' into @mbert/clickable-docs
m-bert ff74f2b
Docs
m-bert a9688b5
Merge branch '@mbert/clickable' into @mbert/clickable-docs
m-bert 78d4273
update SKILL
m-bert 6888721
Merge branch '@mbert/clickable' into @mbert/clickable-docs
m-bert a3b2c87
Minor adjustments
m-bert 90197cf
Update onPressIn and onPressOut type definitions to include GestureEv…
m-bert bce2aa5
rephrase
m-bert cad279b
Copilot review
m-bert 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
275 changes: 275 additions & 0 deletions
275
packages/docs-gesture-handler/docs/components/clickable.mdx
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,275 @@ | ||
| --- | ||
| id: clickable | ||
| title: Clickable | ||
| sidebar_label: Clickable | ||
| --- | ||
|
|
||
| import HeaderWithBadges from '@site/src/components/HeaderWithBadges'; | ||
|
|
||
| `Clickable` is a versatile new component introduced in Gesture Handler 3 to succeed previous button implementations. Designed for maximum flexibility, it provides a highly customizable interface for native touch handling while ensuring consistent behavior across platforms. | ||
|
|
||
| With `Clickable`, you have more control over animations. It is possible to choose between animating the entire component or just the underlay, along with specifying desired `opacity` values. This allows you to effortlessly replicate both `RectButton` and `BorderlessButton` effects using a single unified component. Furthermore, it resolves many legacy issues found in earlier versions. On Android, you can opt for the native ripple effect or leverage JS-based animations via the [Animated API](https://reactnative.dev/docs/animated). | ||
|
|
||
| ## Replacing old buttons | ||
|
|
||
| If you were using `RectButton`, or `BorderlessButton` in your app, you can easily replace them with `Clickable`. Check out full code in [example](#example) section below. | ||
|
|
||
| ### RectButton | ||
|
|
||
| To replace `RectButton` with `Clickable`, simply add `underlayActiveOpacity={0.105}` to your `Clickable` component. This will animate the underlay when the button is pressed. | ||
|
|
||
| ```tsx | ||
| <Clickable | ||
| ... | ||
| underlayActiveOpacity={0.105}/> | ||
m-bert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### BorderlessButton | ||
|
|
||
| Replacing `BorderlessButton` with `Clickable` is as easy as replacing `RectButton`. Just add `activeOpacity={0.3}` to your `Clickable` component. This will animate the whole component when the button is pressed. | ||
|
|
||
| ```tsx | ||
| <Clickable | ||
| ... | ||
| activeOpacity={0.3}/> | ||
| ``` | ||
m-bert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Example | ||
|
|
||
| In this example we will demonstrate how to recreate `RectButton` and `BorderlessButton` effects using `Clickable` component. | ||
|
|
||
| <CollapsibleCode | ||
| label="Show full example" | ||
| expandedLabel="Hide full example" | ||
| lineBounds={[7, 40]} | ||
| src={` | ||
| import React from 'react'; | ||
| import { StyleSheet, Text } from 'react-native'; | ||
| import { | ||
| GestureHandlerRootView, | ||
| Clickable, | ||
| } from 'react-native-gesture-handler'; | ||
|
|
||
| export default function ClickableExample() { | ||
| return ( | ||
| <GestureHandlerRootView style={styles.container}> | ||
| <Clickable | ||
| onPress={() => { | ||
| console.log('BaseButton built with Clickable'); | ||
| }} | ||
| style={[styles.button, { backgroundColor: '#7d63d9' }]}> | ||
| <Text style={styles.buttonText}>BaseButton</Text> | ||
| </Clickable> | ||
|
|
||
| <Clickable | ||
| onPress={() => { | ||
| console.log('RectButton built with Clickable'); | ||
| }} | ||
| style={[styles.button, { backgroundColor: '#4f9a84' }]} | ||
| underlayActiveOpacity={0.105}> | ||
| <Text style={styles.buttonText}>RectButton</Text> | ||
| </Clickable> | ||
|
|
||
| <Clickable | ||
| onPress={() => { | ||
| console.log('BorderlessButton built with Clickable'); | ||
| }} | ||
| style={[styles.button, { backgroundColor: '#5f97c8' }]} | ||
| activeOpacity={0.3}> | ||
| <Text style={styles.buttonText}>BorderlessButton</Text> | ||
| </Clickable> | ||
| </GestureHandlerRootView> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
|
|
||
| gap: 20, | ||
| }, | ||
| button: { | ||
| width: 200, | ||
| height: 70, | ||
| borderRadius: 15, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }, | ||
| buttonText: { | ||
| color: 'white', | ||
| fontSize: 14, | ||
| fontWeight: '600', | ||
| }, | ||
| }); | ||
| `}/> | ||
|
|
||
|
|
||
| ## Properties | ||
|
|
||
| ### exclusive | ||
|
|
||
| ```ts | ||
| exclusive?: boolean; | ||
| ``` | ||
|
|
||
| Defines if more than one button could be pressed simultaneously. By default set to `true`. | ||
|
|
||
| <HeaderWithBadges platforms={['android']}> | ||
| ### touchSoundDisabled | ||
| </HeaderWithBadges> | ||
|
|
||
| ```ts | ||
| touchSoundDisabled?: boolean; | ||
| ``` | ||
|
|
||
| If set to `true`, the system will not play a sound when the button is pressed. | ||
|
|
||
| ### onPressIn | ||
|
|
||
| <CollapsibleCode | ||
| label="Show composed types definitions" | ||
| expandedLabel="Hide composed types definitions" | ||
| lineBounds={[0, 1]} | ||
| src={` | ||
| onPressIn?: (e: GestureEvent<NativeHandlerData>) => void; | ||
|
|
||
| type GestureEvent<NativeHandlerData> = { | ||
| handlerTag: number; | ||
| numberOfPointers: number; | ||
| pointerType: PointerType; | ||
| pointerInside: boolean; | ||
| } | ||
|
|
||
| enum PointerType { | ||
| TOUCH, | ||
| STYLUS, | ||
| MOUSE, | ||
| KEY, | ||
| OTHER, | ||
| } | ||
| `}/> | ||
|
|
||
| Triggered when the button gets pressed (analogous to `onPressIn` in `TouchableHighlight` from RN core). | ||
|
|
||
| ### onPressOut | ||
|
|
||
| <CollapsibleCode | ||
| label="Show composed types definitions" | ||
| expandedLabel="Hide composed types definitions" | ||
| lineBounds={[0, 1]} | ||
| src={` | ||
| onPressOut?: (e: GestureEvent<NativeHandlerData>) => void; | ||
|
|
||
| type GestureEvent<NativeHandlerData> = { | ||
| handlerTag: number; | ||
| numberOfPointers: number; | ||
| pointerType: PointerType; | ||
| pointerInside: boolean; | ||
| } | ||
|
|
||
| enum PointerType { | ||
| TOUCH, | ||
| STYLUS, | ||
| MOUSE, | ||
| KEY, | ||
| OTHER, | ||
| } | ||
| `}/> | ||
|
|
||
| Triggered when the button gets released (analogous to `onPressOut` in `TouchableHighlight` from RN core). | ||
m-bert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### onPress | ||
|
|
||
| ```ts | ||
| onPress?: (pointerInside: boolean) => void; | ||
| ``` | ||
|
|
||
| Triggered when the button gets pressed (analogous to `onPress` in `TouchableHighlight` from RN core). | ||
|
|
||
| ### onLongPress | ||
|
|
||
| ```ts | ||
| onLongPress?: () => void; | ||
| ``` | ||
|
|
||
| Triggered when the button gets pressed for at least [`delayLongPress`](#delaylongpress) milliseconds. | ||
|
|
||
|
|
||
| ### onActiveStateChange | ||
|
|
||
| ```ts | ||
| onActiveStateChange?: (active: boolean) => void; | ||
| ``` | ||
|
|
||
| Triggered when the button transitions between active and inactive states. It passes the current active state as a boolean variable to the method as the first parameter. | ||
|
|
||
| ### delayLongPress | ||
|
|
||
| ```ts | ||
| delayLongPress?: number; | ||
| ``` | ||
|
|
||
| Defines the delay, in milliseconds, after which the [`onLongPress`](#onlongpress) callback gets called. By default set to `600`. | ||
|
|
||
| ### underlayColor | ||
|
|
||
| ```ts | ||
| underlayColor?: string; | ||
| ``` | ||
|
|
||
| Background color of underlay. This only takes effect when `underlayActiveOpacity` is set. | ||
|
|
||
| ### underlayActiveOpacity | ||
|
|
||
| ```ts | ||
| underlayActiveOpacity?: number; | ||
| ``` | ||
|
|
||
| Defines the opacity of underlay when the button is active. If not set, underlay won't be rendered. | ||
|
|
||
| ### activeOpacity | ||
|
|
||
| ```ts | ||
| activeOpacity?: number; | ||
| ``` | ||
|
|
||
| Defines the opacity of the whole component when the button is active. | ||
|
|
||
| ### underlayInitialOpacity | ||
|
|
||
| ```ts | ||
| underlayInitialOpacity?: number; | ||
| ``` | ||
|
|
||
| Defines the initial opacity of underlay when the button is inactive. By default set to `0`. | ||
|
|
||
| ### initialOpacity | ||
|
|
||
| ```ts | ||
| initialOpacity?: number; | ||
| ``` | ||
|
|
||
| Defines the initial opacity of the whole component when the button is inactive. By default set to `1` | ||
|
|
||
| <HeaderWithBadges platforms={['android']}> | ||
| ### androidRipple | ||
| </HeaderWithBadges> | ||
|
|
||
| <CollapsibleCode | ||
| label="Show composed types definitions" | ||
| expandedLabel="Hide composed types definitions" | ||
| lineBounds={[0, 1]} | ||
| src={` | ||
| androidRipple?: PressableAndroidRippleConfig; | ||
|
|
||
| type PressableAndroidRippleConfig = { | ||
| color?: (string | OpaqueColorValue); | ||
| borderless?: boolean; | ||
| radius?: number; | ||
| foreground?: boolean; | ||
| } | ||
| `}/> | ||
|
|
||
| Configuration for the ripple effect on Android. If not provided, the ripple effect will be disabled. If `{}` is provided, the ripple effect will be enabled with default configuration. | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe we would like to keep
RawButton? This would keep more flexibility for advanced users. But that's just a thought, not strong opinion - I'm not sure if we want to do that (cc @j-piasecki, @akwasniewski)