Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/ActionSheetAwareScrollView/index.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, {useCallback} from 'react';
import React, {forwardRef, useCallback} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {ScrollView} from 'react-native';
import Reanimated, {useAnimatedRef, useAnimatedStyle} from 'react-native-reanimated';
import {Actions, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider} from './ActionSheetAwareScrollViewContext';
import type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent} from './types';
import useActionSheetKeyboardSpacing from './useActionSheetKeyboardSpacing';

function ActionSheetAwareScrollView({style, children, ref, ...props}: ActionSheetAwareScrollViewProps) {
const ActionSheetAwareScrollView = forwardRef<ScrollView, ActionSheetAwareScrollViewProps>(({style, children, ...props}, ref) => {
const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();

const onRef = useCallback(
Expand Down Expand Up @@ -36,7 +38,7 @@ function ActionSheetAwareScrollView({style, children, ref, ...props}: ActionShee
{children}
</Reanimated.ScrollView>
);
}
});

export default ActionSheetAwareScrollView;

Expand Down
21 changes: 10 additions & 11 deletions src/components/ActionSheetAwareScrollView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// this whole file is just for other platforms
// iOS version has everything implemented
import React from 'react';
import React, {forwardRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import {ScrollView} from 'react-native';
import {Actions, ActionSheetAwareScrollViewContext, ActionSheetAwareScrollViewProvider} from './ActionSheetAwareScrollViewContext';
import type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent} from './types';

function ActionSheetAwareScrollView(props: ActionSheetAwareScrollViewProps) {
return (
<ScrollView
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
>
{props.children}
</ScrollView>
);
}
const ActionSheetAwareScrollView = forwardRef<ScrollView, ActionSheetAwareScrollViewProps>((props, ref) => (
<ScrollView
ref={ref}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
>
{props.children}
</ScrollView>
));

export default ActionSheetAwareScrollView;

Expand Down
10 changes: 3 additions & 7 deletions src/components/ActionSheetAwareScrollView/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type {PropsWithChildren, Ref} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {ScrollView, ScrollViewProps} from 'react-native';
import type {PropsWithChildren} from 'react';
import type {ScrollViewProps} from 'react-native';

type ActionSheetAwareScrollViewAnimationProps = {
ref?: Ref<ScrollView>;
};
type ActionSheetAwareScrollViewProps = PropsWithChildren<ScrollViewProps> & ActionSheetAwareScrollViewAnimationProps;
type ActionSheetAwareScrollViewProps = PropsWithChildren<ScrollViewProps>;
type RenderActionSheetAwareScrollViewComponent = ((props: ActionSheetAwareScrollViewProps) => React.ReactElement<ScrollViewProps>) | undefined;
export type {ActionSheetAwareScrollViewProps, RenderActionSheetAwareScrollViewComponent};
71 changes: 37 additions & 34 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useEffect, useMemo, useRef, useState} from 'react';
import React, {forwardRef, useEffect, useMemo, useRef, useState} from 'react';
import type {ForwardedRef} from 'react';
import {Keyboard, LogBox, View} from 'react-native';
import type {LayoutChangeEvent} from 'react-native';
import {GooglePlacesAutocomplete} from 'react-native-google-places-autocomplete';
Expand Down Expand Up @@ -48,38 +49,40 @@ function isPlaceMatchForSearch(search: string, place: PredefinedPlace): boolean
// VirtualizedList component with a VirtualizedList-backed instead
LogBox.ignoreLogs(['VirtualizedLists should never be nested']);

function AddressSearch({
canUseCurrentLocation = false,
containerStyles,
defaultValue,
errorText = '',
hint = '',
inputID,
limitSearchesToCountry,
label,
maxInputLength,
onFocus,
onBlur,
onInputChange,
onPress,
onCountryChange,
predefinedPlaces = [],
renamedInputKeys = {
street: 'addressStreet',
street2: 'addressStreet2',
city: 'addressCity',
state: 'addressState',
zipCode: 'addressZipCode',
lat: 'addressLat',
lng: 'addressLng',
},
resultTypes = 'address',
shouldSaveDraft = false,
value,
locationBias,
caretHidden,
ref,
}: AddressSearchProps) {
function AddressSearch(
{
canUseCurrentLocation = false,
containerStyles,
defaultValue,
errorText = '',
hint = '',
inputID,
limitSearchesToCountry,
label,
maxInputLength,
onFocus,
onBlur,
onInputChange,
onPress,
onCountryChange,
predefinedPlaces = [],
renamedInputKeys = {
street: 'addressStreet',
street2: 'addressStreet2',
city: 'addressCity',
state: 'addressState',
zipCode: 'addressZipCode',
lat: 'addressLat',
lng: 'addressLng',
},
resultTypes = 'address',
shouldSaveDraft = false,
value,
locationBias,
caretHidden,
}: AddressSearchProps,
ref: ForwardedRef<HTMLElement>,
) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -487,6 +490,6 @@ function AddressSearch({

AddressSearch.displayName = 'AddressSearchWithRef';

export default AddressSearch;
export default forwardRef(AddressSearch);

export type {AddressSearchProps};
5 changes: 1 addition & 4 deletions src/components/AddressSearch/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ForwardedRef, RefObject} from 'react';
import type {RefObject} from 'react';
import type {NativeSyntheticEvent, StyleProp, TextInputFocusEventData, View, ViewStyle} from 'react-native';
import type {Place} from 'react-native-google-places-autocomplete';
import type {Country} from '@src/CONST';
Expand Down Expand Up @@ -90,9 +90,6 @@ type AddressSearchProps = {

/** If true, caret is hidden. The default value is false. */
caretHidden?: boolean;

/** Reference to the outer element */
ref?: ForwardedRef<HTMLElement>;
};

type IsCurrentTargetInsideContainerType = (event: FocusEvent | NativeSyntheticEvent<TextInputFocusEventData>, containerRef: RefObject<View | HTMLElement | null>) => boolean;
Expand Down
9 changes: 5 additions & 4 deletions src/components/AmountPicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useState} from 'react';
import React, {forwardRef, useState} from 'react';
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import blurActiveElement from '@libs/Accessibility/blurActiveElement';
Expand All @@ -7,7 +8,7 @@ import callOrReturn from '@src/types/utils/callOrReturn';
import AmountSelectorModal from './AmountSelectorModal';
import type {AmountPickerProps} from './types';

function AmountPicker({value, description, title, errorText = '', onInputChange, furtherDetails, rightLabel, ref, ...rest}: AmountPickerProps) {
function AmountPicker({value, description, title, errorText = '', onInputChange, furtherDetails, rightLabel, ...rest}: AmountPickerProps, forwardedRef: ForwardedRef<View>) {
const [isPickerVisible, setIsPickerVisible] = useState(false);

const showPickerModal = () => {
Expand All @@ -30,7 +31,7 @@ function AmountPicker({value, description, title, errorText = '', onInputChange,
return (
<View>
<MenuItemWithTopDescription
ref={ref}
ref={forwardedRef}
shouldShowRightIcon
title={callOrReturn(title, value)}
description={description}
Expand All @@ -55,4 +56,4 @@ function AmountPicker({value, description, title, errorText = '', onInputChange,

AmountPicker.displayName = 'AmountPicker';

export default AmountPicker;
export default forwardRef(AmountPicker);
5 changes: 0 additions & 5 deletions src/components/AmountPicker/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type {ForwardedRef} from 'react';
import type {View} from 'react-native';
import type {MenuItemBaseProps} from '@components/MenuItem';
import type {NumberWithSymbolFormProps} from '@components/NumberWithSymbolForm';

Expand Down Expand Up @@ -49,9 +47,6 @@ type AmountPickerProps = {

/** Whether to show the tooltip text */
shouldShowTooltips?: boolean;

/** Reference to the outer element */
ref?: ForwardedRef<View>;
} & Pick<MenuItemBaseProps, 'rightLabel' | 'description'> &
Pick<
NumberWithSymbolFormProps,
Expand Down
24 changes: 7 additions & 17 deletions src/components/AmountWithoutCurrencyInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, {useCallback, useMemo} from 'react';
import type {ForwardedRef} from 'react';
import useLocalize from '@hooks/useLocalize';
import getAmountInputKeyboard from '@libs/getAmountInputKeyboard';
import {handleNegativeAmountFlipping, replaceAllDigits, replaceCommasWithPeriod, stripSpacesFromAmount} from '@libs/MoneyRequestUtils';
import TextInput from './TextInput';
import type {BaseTextInputProps} from './TextInput/BaseTextInput/types';
import type {BaseTextInputProps, BaseTextInputRef} from './TextInput/BaseTextInput/types';

type AmountFormProps = {
/** Amount supplied by the FormProvider */
Expand All @@ -22,21 +23,10 @@ type AmountFormProps = {
toggleNegative?: () => void;
} & Partial<BaseTextInputProps>;

function AmountWithoutCurrencyInput({
value: amount,
shouldAllowNegative = false,
inputID,
name,
defaultValue,
accessibilityLabel,
role,
label,
onInputChange,
allowFlippingAmount,
toggleNegative,
ref,
...rest
}: AmountFormProps) {
function AmountWithoutCurrencyInput(
{value: amount, shouldAllowNegative = false, inputID, name, defaultValue, accessibilityLabel, role, label, onInputChange, allowFlippingAmount, toggleNegative, ...rest}: AmountFormProps,
ref: ForwardedRef<BaseTextInputRef>,
) {
const {toLocaleDigit} = useLocalize();
const separator = useMemo(
() =>
Expand Down Expand Up @@ -104,4 +94,4 @@ function AmountWithoutCurrencyInput({

AmountWithoutCurrencyInput.displayName = 'AmountWithoutCurrencyInput';

export default AmountWithoutCurrencyInput;
export default React.forwardRef(AmountWithoutCurrencyInput);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to go back to this:

function AmountWithoutCurrencyInput(
    {value: amount, shouldAllowNegative = false, inputID, name, defaultValue, accessibilityLabel, role, label, onInputChange, ...rest}: AmountFormProps,
    ref: ForwardedRef<BaseTextInputRef>,
) {

But add the new props that has been added

10 changes: 5 additions & 5 deletions src/components/Attachments/AttachmentCarousel/Pager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type AttachmentCarouselPagerProps = {

/** Callback for attachment errors */
onAttachmentError?: (source: AttachmentSource) => void;

/** Reference to the outer element */
ref?: ForwardedRef<AttachmentCarouselPagerHandle>;
};

function AttachmentCarouselPager({items, activeAttachmentID, initialPage, setShouldShowArrows, onPageSelected, onClose, reportID, onAttachmentError, ref}: AttachmentCarouselPagerProps) {
function AttachmentCarouselPager(
{items, activeAttachmentID, initialPage, setShouldShowArrows, onPageSelected, onClose, reportID, onAttachmentError}: AttachmentCarouselPagerProps,
ref: ForwardedRef<AttachmentCarouselPagerHandle>,
) {
const {handleTap, handleScaleChange, isScrollEnabled} = useCarouselContextEvents(setShouldShowArrows);
const styles = useThemeStyles();
const pagerRef = useRef<PagerView>(null);
Expand Down Expand Up @@ -153,5 +153,5 @@ function AttachmentCarouselPager({items, activeAttachmentID, initialPage, setSho
}
AttachmentCarouselPager.displayName = 'AttachmentCarouselPager';

export default AttachmentCarouselPager;
export default React.forwardRef(AttachmentCarouselPager);
export type {AttachmentCarouselPagerHandle};
21 changes: 5 additions & 16 deletions src/components/CheckboxWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,12 @@ type CheckboxWithLabelProps = RequiredLabelProps & {

/** An accessibility label for the checkbox */
accessibilityLabel?: string;

/** Reference to the outer element */
ref?: ForwardedRef<View>;
};

function CheckboxWithLabel({
errorText = '',
isChecked: isCheckedProp = false,
defaultValue = false,
onInputChange = () => {},
LabelComponent,
label,
accessibilityLabel,
style,
value,
ref,
}: CheckboxWithLabelProps) {
function CheckboxWithLabel(
{errorText = '', isChecked: isCheckedProp = false, defaultValue = false, onInputChange = () => {}, LabelComponent, label, accessibilityLabel, style, value}: CheckboxWithLabelProps,
ref: ForwardedRef<View>,
) {
const styles = useThemeStyles();
// We need to pick the first value that is strictly a boolean
// https://github.com/Expensify/App/issues/16885#issuecomment-1520846065
Expand Down Expand Up @@ -117,6 +106,6 @@ function CheckboxWithLabel({

CheckboxWithLabel.displayName = 'CheckboxWithLabel';

export default CheckboxWithLabel;
export default React.forwardRef(CheckboxWithLabel);

export type {CheckboxWithLabelProps};
49 changes: 24 additions & 25 deletions src/components/ContextMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ForwardedRef} from 'react';
import React, {useImperativeHandle} from 'react';
import React, {forwardRef, useImperativeHandle} from 'react';
import type {GestureResponderEvent, StyleProp, View, ViewStyle} from 'react-native';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -61,35 +61,34 @@ type ContextMenuItemProps = {

/** Whether the menu item should show loading icon */
shouldShowLoadingSpinnerIcon?: boolean;

/** Reference to the outer element */
ref?: ForwardedRef<ContextMenuItemHandle>;
};

type ContextMenuItemHandle = {
triggerPressAndUpdateSuccess?: () => void;
};

function ContextMenuItem({
onPress,
successIcon,
successText = '',
icon,
text,
isMini = false,
description = '',
isAnonymousAction = false,
isFocused = false,
shouldLimitWidth = true,
wrapperStyle,
shouldPreventDefaultFocusOnPress = true,
buttonRef = {current: null},
onFocus = () => {},
onBlur = () => {},
disabled = false,
shouldShowLoadingSpinnerIcon = false,
ref,
}: ContextMenuItemProps) {
function ContextMenuItem(
{
onPress,
successIcon,
successText = '',
icon,
text,
isMini = false,
description = '',
isAnonymousAction = false,
isFocused = false,
shouldLimitWidth = true,
wrapperStyle,
shouldPreventDefaultFocusOnPress = true,
buttonRef = {current: null},
onFocus = () => {},
onBlur = () => {},
disabled = false,
shouldShowLoadingSpinnerIcon = false,
}: ContextMenuItemProps,
ref: ForwardedRef<ContextMenuItemHandle>,
) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {windowWidth} = useWindowDimensions();
Expand Down Expand Up @@ -152,5 +151,5 @@ function ContextMenuItem({

ContextMenuItem.displayName = 'ContextMenuItem';

export default ContextMenuItem;
export default forwardRef(ContextMenuItem);
export type {ContextMenuItemHandle};
Loading
Loading