Skip to content

Commit

Permalink
feat: add delay long press support (#3536)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak authored Dec 19, 2022
1 parent 88949dc commit fb052a4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ export type Props = React.ComponentProps<typeof Surface> & {
* Function to execute on long press.
*/
onLongPress?: (e: GestureResponderEvent) => void;
/**
* The number of milliseconds a user must touch the element before executing `onLongPress`.
*/
delayLongPress?: number;
/**
* Style of button's inner content.
* Use this prop to apply custom height and width and to set the icon on the right with `flexDirection: 'row-reverse'`.
Expand Down Expand Up @@ -173,6 +177,7 @@ const Button = ({
onPressIn,
onPressOut,
onLongPress,
delayLongPress,
style,
theme,
uppercase = !theme.isV3,
Expand Down Expand Up @@ -298,6 +303,7 @@ const Button = ({
onLongPress={onLongPress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
delayLongPress={delayLongPress}
accessibilityLabel={accessibilityLabel}
accessibilityHint={accessibilityHint}
accessibilityRole="button"
Expand Down
24 changes: 15 additions & 9 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ type Mode = 'elevated' | 'outlined' | 'contained';

export type Props = React.ComponentProps<typeof Surface> & {
/**
* Changes Card shadow and background on iOS and Android.
* Mode of the Card.
* - `elevated` - Card with elevation.
* - `contained` - Card with without outline and elevation @supported Available in v5.x with theme version 3
* - `outlined` - Card with an outline.
*/
elevation?: 0 | 1 | 2 | 3 | 4 | 5 | Animated.Value;
mode?: Mode;
/**
* Content of the `Card`.
*/
children: React.ReactNode;
/**
* Function to execute on long press.
*/
Expand All @@ -53,16 +60,13 @@ export type Props = React.ComponentProps<typeof Surface> & {
*/
onPress?: (e: GestureResponderEvent) => void;
/**
* Mode of the Card.
* - `elevated` - Card with elevation.
* - `contained` - Card with without outline and elevation @supported Available in v5.x with theme version 3
* - `outlined` - Card with an outline.
* The number of milliseconds a user must touch the element before executing `onLongPress`.
*/
mode?: Mode;
delayLongPress?: number;
/**
* Content of the `Card`.
* Changes Card shadow and background on iOS and Android.
*/
children: React.ReactNode;
elevation?: 0 | 1 | 2 | 3 | 4 | 5 | Animated.Value;
style?: StyleProp<ViewStyle>;
/**
* @optional
Expand Down Expand Up @@ -124,6 +128,7 @@ export type Props = React.ComponentProps<typeof Surface> & {
const Card = ({
elevation: cardElevation = 1,
onLongPress,
delayLongPress,
onPress,
mode: cardMode = 'elevated',
children,
Expand Down Expand Up @@ -256,6 +261,7 @@ const Card = ({
<TouchableWithoutFeedback
delayPressIn={0}
disabled={!(onPress || onLongPress)}
delayLongPress={delayLongPress}
onLongPress={onLongPress}
onPress={onPress}
onPressIn={onPress || onLongPress ? handlePressIn : undefined}
Expand Down
8 changes: 7 additions & 1 deletion src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export type Props = React.ComponentProps<typeof Surface> & {
* Function to execute on long press.
*/
onLongPress?: () => void;
/**
* The number of milliseconds a user must touch the element before executing `onLongPress`.
*/
delayLongPress?: number;
/**
* Function to execute on close button press. The close button appears only when this prop is specified.
*/
Expand Down Expand Up @@ -150,6 +154,7 @@ const Chip = ({
closeIconAccessibilityLabel = 'Close',
onPress,
onLongPress,
delayLongPress,
onClose,
closeIcon,
textStyle,
Expand Down Expand Up @@ -259,9 +264,10 @@ const Chip = ({
borderless
style={[{ borderRadius }, styles.touchable]}
onPress={onPress}
onLongPress={onLongPress}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onLongPress={onLongPress}
delayLongPress={delayLongPress}
underlayColor={underlayColor}
disabled={disabled}
accessibilityLabel={accessibilityLabel}
Expand Down
6 changes: 6 additions & 0 deletions src/components/FAB/AnimatedFAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export type Props = $RemoveChildren<typeof Surface> & {
* Function to execute on long press.
*/
onLongPress?: () => void;
/**
* The number of milliseconds a user must touch the element before executing `onLongPress`.
*/
delayLongPress?: number;
/**
* Whether icon should be translated to the end of extended `FAB` or be static and stay in the same place. The default value is `dynamic`.
*/
Expand Down Expand Up @@ -192,6 +196,7 @@ const AnimatedFAB = ({
disabled,
onPress,
onLongPress,
delayLongPress,
theme,
style,
visible = true,
Expand Down Expand Up @@ -403,6 +408,7 @@ const AnimatedFAB = ({
borderless
onPress={onPress}
onLongPress={onLongPress}
delayLongPress={delayLongPress}
rippleColor={rippleColor}
disabled={disabled}
accessibilityLabel={accessibilityLabel}
Expand Down
6 changes: 6 additions & 0 deletions src/components/FAB/FAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export type Props = $RemoveChildren<typeof Surface> & {
* Function to execute on long press.
*/
onLongPress?: () => void;
/**
* The number of milliseconds a user must touch the element before executing `onLongPress`.
*/
delayLongPress?: number;
/**
* @supported Available in v5.x with theme version 3
*
Expand Down Expand Up @@ -162,6 +166,7 @@ const FAB = React.forwardRef<View, Props>(
disabled,
onPress,
onLongPress,
delayLongPress,
theme,
style,
visible = true,
Expand Down Expand Up @@ -259,6 +264,7 @@ const FAB = React.forwardRef<View, Props>(
borderless
onPress={onPress}
onLongPress={onLongPress}
delayLongPress={delayLongPress}
rippleColor={rippleColor}
disabled={disabled}
accessibilityLabel={accessibilityLabel}
Expand Down
6 changes: 6 additions & 0 deletions src/components/List/ListAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export type Props = {
* Function to execute on long press.
*/
onLongPress?: (e: GestureResponderEvent) => void;
/**
* The number of milliseconds a user must touch the element before executing `onLongPress`.
*/
delayLongPress?: number;
/**
* Content of the section.
*/
Expand Down Expand Up @@ -156,6 +160,7 @@ const ListAccordion = ({
testID,
onPress,
onLongPress,
delayLongPress,
expanded: expandedProp,
accessibilityLabel,
pointerEvents = 'none',
Expand Down Expand Up @@ -203,6 +208,7 @@ const ListAccordion = ({
style={[styles.container, style]}
onPress={handlePress}
onLongPress={onLongPress}
delayLongPress={delayLongPress}
rippleColor={rippleColor}
accessibilityRole="button"
accessibilityState={{ expanded: isExpanded }}
Expand Down

0 comments on commit fb052a4

Please sign in to comment.