Skip to content

Commit

Permalink
Merge branch 'main' into expo-image
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Dec 5, 2023
2 parents 03435e5 + 8d934ae commit 047cc65
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 210 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import KeyboardShortcut from '@libs/KeyboardShortcut';
import * as StyleUtils from '@styles/StyleUtils';
import useThemeStyles from '@styles/useThemeStyles';
import CONST from '@src/CONST';
import PressableProps from './types';
import PressableProps, {PressableRef} from './types';

function GenericPressable(
{
Expand All @@ -34,7 +34,7 @@ function GenericPressable(
accessible = true,
...rest
}: PressableProps,
ref: ForwardedRef<View>,
ref: PressableRef,
) {
const styles = useThemeStyles();
const {isExecuting, singleExecution} = useSingleExecution();
Expand Down Expand Up @@ -124,7 +124,7 @@ function GenericPressable(
<Pressable
hitSlop={shouldUseAutoHitSlop ? hitSlop : undefined}
onLayout={shouldUseAutoHitSlop ? onLayout : undefined}
ref={ref}
ref={ref as ForwardedRef<View>}
onPress={!isDisabled ? singleExecution(onPressHandler) : undefined}
onLongPress={!isDisabled && onLongPress ? onLongPressHandler : undefined}
onKeyDown={!isDisabled ? onKeyDown : undefined}
Expand Down
7 changes: 3 additions & 4 deletions src/components/Pressable/GenericPressable/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {ForwardedRef, forwardRef} from 'react';
import {View} from 'react-native';
import React, {forwardRef} from 'react';
import GenericPressable from './BaseGenericPressable';
import PressableProps from './types';
import PressableProps, {PressableRef} from './types';

function NativeGenericPressable(props: PressableProps, ref: ForwardedRef<View>) {
function NativeGenericPressable(props: PressableProps, ref: PressableRef) {
return (
<GenericPressable
focusable
Expand Down
8 changes: 4 additions & 4 deletions src/components/Pressable/GenericPressable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {ForwardedRef, forwardRef} from 'react';
import {Role, View} from 'react-native';
import React, {forwardRef} from 'react';
import {Role} from 'react-native';
import GenericPressable from './BaseGenericPressable';
import PressableProps from './types';
import PressableProps, {PressableRef} from './types';

function WebGenericPressable({focusable = true, ...props}: PressableProps, ref: ForwardedRef<View>) {
function WebGenericPressable({focusable = true, ...props}: PressableProps, ref: PressableRef) {
const accessible = props.accessible ?? props.accessible === undefined ? true : props.accessible;

return (
Expand Down
7 changes: 5 additions & 2 deletions src/components/Pressable/GenericPressable/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ElementRef, RefObject} from 'react';
import {GestureResponderEvent, HostComponent, PressableStateCallbackType, PressableProps as RNPressableProps, StyleProp, ViewStyle} from 'react-native';
import {ElementRef, ForwardedRef, RefObject} from 'react';
import {GestureResponderEvent, HostComponent, PressableStateCallbackType, PressableProps as RNPressableProps, StyleProp, View, ViewStyle} from 'react-native';
import {ValueOf} from 'type-fest';
import {Shortcut} from '@libs/KeyboardShortcut';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -138,4 +138,7 @@ type PressableProps = RNPressableProps &
noDragArea?: boolean;
};

type PressableRef = ForwardedRef<HTMLDivElement | View>;

export default PressableProps;
export type {PressableRef};
14 changes: 7 additions & 7 deletions src/components/Pressable/PressableWithDelayToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable react-native-a11y/has-valid-accessibility-descriptors */
import React, {ForwardedRef, forwardRef} from 'react';
import {ImageSourcePropType, Text as RNText, StyleProp, TextStyle, View, ViewStyle} from 'react-native';
import {SvgProps} from 'react-native-svg';
import React, {forwardRef} from 'react';
import {StyleProp, TextStyle, ViewStyle} from 'react-native';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import Text from '@components/Text';
Expand All @@ -12,7 +11,8 @@ import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import variables from '@styles/variables';
import PressableProps from './GenericPressable/types';
import IconAsset from '@src/types/utils/IconAsset';
import PressableProps, {PressableRef} from './GenericPressable/types';
import PressableWithoutFeedback from './PressableWithoutFeedback';

type PressableWithDelayToggleProps = PressableProps & {
Expand All @@ -38,10 +38,10 @@ type PressableWithDelayToggleProps = PressableProps & {
iconStyles?: StyleProp<ViewStyle>;

/** The icon to display */
icon?: React.FC<SvgProps>;
icon?: IconAsset;

/** The icon to display once the pressable is pressed */
iconChecked?: React.FC<SvgProps> | ImageSourcePropType;
iconChecked?: IconAsset;

/**
* Should be set to `true` if this component is being rendered inline in
Expand All @@ -65,7 +65,7 @@ function PressableWithDelayToggle(
iconStyles,
icon,
}: PressableWithDelayToggleProps,
ref: ForwardedRef<RNText | View>,
ref: PressableRef,
) {
const styles = useThemeStyles();
const theme = useTheme();
Expand Down
9 changes: 5 additions & 4 deletions src/components/Pressable/PressableWithFeedback.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {ForwardedRef, forwardRef, useState} from 'react';
import {StyleProp, View, ViewStyle} from 'react-native';
import React, {forwardRef, useState} from 'react';
import {StyleProp, ViewStyle} from 'react-native';
import {AnimatedStyle} from 'react-native-reanimated';
import OpacityView from '@components/OpacityView';
import variables from '@styles/variables';
import GenericPressable from './GenericPressable';
import PressableProps from './GenericPressable/types';
import PressableProps, {PressableRef} from './GenericPressable/types';

type PressableWithFeedbackProps = PressableProps & {
/** Style for the wrapper view */
Expand Down Expand Up @@ -37,7 +37,7 @@ function PressableWithFeedback(
hoverDimmingValue = variables.hoverDimValue,
...rest
}: PressableWithFeedbackProps,
ref: ForwardedRef<View>,
ref: PressableRef,
) {
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);
Expand Down Expand Up @@ -88,3 +88,4 @@ function PressableWithFeedback(
PressableWithFeedback.displayName = 'PressableWithFeedback';

export default forwardRef(PressableWithFeedback);
export type {PressableWithFeedbackProps};
7 changes: 3 additions & 4 deletions src/components/Pressable/PressableWithoutFeedback.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, {ForwardedRef} from 'react';
import {View} from 'react-native';
import React from 'react';
import GenericPressable from './GenericPressable';
import PressableProps from './GenericPressable/types';
import PressableProps, {PressableRef} from './GenericPressable/types';

function PressableWithoutFeedback(
{pressStyle, hoverStyle, focusStyle, disabledStyle, screenReaderActiveStyle, shouldUseHapticsOnPress, shouldUseHapticsOnLongPress, ...rest}: PressableProps,
ref: ForwardedRef<View>,
ref: PressableRef,
) {
return (
<GenericPressable
Expand Down
51 changes: 0 additions & 51 deletions src/components/PressableWithSecondaryInteraction/index.native.js

This file was deleted.

61 changes: 61 additions & 0 deletions src/components/PressableWithSecondaryInteraction/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, {forwardRef} from 'react';
import {GestureResponderEvent, TextProps} from 'react-native';
import {PressableRef} from '@components/Pressable/GenericPressable/types';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Text from '@components/Text';
import PressableWithSecondaryInteractionProps from './types';

/** This is a special Pressable that calls onSecondaryInteraction when LongPressed. */
function PressableWithSecondaryInteraction(
{
children,
onSecondaryInteraction,
inline = false,
needsOffscreenAlphaCompositing = false,
suppressHighlighting = false,
activeOpacity = 1,
preventDefaultContextMenu,
withoutFocusOnSecondaryInteraction,
enableLongPressWithHover,
...rest
}: PressableWithSecondaryInteractionProps,
ref: PressableRef,
) {
const executeSecondaryInteraction = (event: GestureResponderEvent) => {
event.preventDefault();
onSecondaryInteraction?.(event);
};

// Use Text node for inline mode to prevent content overflow.
if (inline) {
return (
<Text
// ESLint is disabled here to propagate all the props, enhancing PressableWithSecondaryInteraction's versatility across different use cases.
// eslint-disable-next-line react/jsx-props-no-spreading
{...(rest as TextProps)}
suppressHighlighting={suppressHighlighting}
onLongPress={onSecondaryInteraction ? executeSecondaryInteraction : undefined}
>
{children}
</Text>
);
}

return (
<PressableWithFeedback
// ESLint is disabled here to propagate all the props, enhancing PressableWithSecondaryInteraction's versatility across different use cases.
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
ref={ref}
onLongPress={onSecondaryInteraction ? executeSecondaryInteraction : undefined}
needsOffscreenAlphaCompositing={needsOffscreenAlphaCompositing}
pressDimmingValue={activeOpacity}
>
{children}
</PressableWithFeedback>
);
}

PressableWithSecondaryInteraction.displayName = 'PressableWithSecondaryInteraction';

export default forwardRef(PressableWithSecondaryInteraction);
Loading

0 comments on commit 047cc65

Please sign in to comment.