Skip to content

Commit 7e73ed7

Browse files
authored
Merge pull request Expensify#68435 from software-mansion-labs/jakubkalinski0/Fix-console-errors-related-to-forwardRef-batch2
Jakubkalinski0/fix console errors related to forward ref batch2
2 parents 846f896 + 8d35fac commit 7e73ed7

30 files changed

Lines changed: 421 additions & 419 deletions

src/components/ButtonWithDropdownMenu/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {RefObject} from 'react';
2-
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
2+
import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
33
import {View} from 'react-native';
44
import type {GestureResponderEvent} from 'react-native';
55
import Button from '@components/Button';
@@ -17,13 +17,9 @@ import mergeRefs from '@libs/mergeRefs';
1717
import variables from '@styles/variables';
1818
import CONST from '@src/CONST';
1919
import type {AnchorPosition} from '@src/styles';
20-
import type {ButtonWithDropdownMenuProps} from './types';
20+
import type {ButtonWithDropdownMenuProps, ButtonWithDropdownMenuRef} from './types';
2121

22-
type ButtonWithDropdownMenuRef = {
23-
setIsMenuVisible: (visible: boolean) => void;
24-
};
25-
26-
function ButtonWithDropdownMenuInner<IValueType>(props: ButtonWithDropdownMenuProps<IValueType>, ref: React.Ref<ButtonWithDropdownMenuRef>) {
22+
function ButtonWithDropdownMenuInner<IValueType>({ref, ...props}: ButtonWithDropdownMenuProps<IValueType>) {
2723
const {
2824
success = true,
2925
isSplitButton = true,
@@ -319,7 +315,7 @@ function ButtonWithDropdownMenuInner<IValueType>(props: ButtonWithDropdownMenuPr
319315
}
320316

321317
ButtonWithDropdownMenuInner.displayName = 'ButtonWithDropdownMenu';
322-
const ButtonWithDropdownMenu = forwardRef(ButtonWithDropdownMenuInner) as <IValueType>(
318+
const ButtonWithDropdownMenu = ButtonWithDropdownMenuInner as <IValueType>(
323319
props: ButtonWithDropdownMenuProps<IValueType> & {ref?: React.Ref<ButtonWithDropdownMenuRef>},
324320
) => ReturnType<typeof ButtonWithDropdownMenuInner>;
325321
export default ButtonWithDropdownMenu;

src/components/ButtonWithDropdownMenu/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ type ButtonWithDropdownMenuProps<TValueType> = {
159159

160160
/** Whether to display the option icon when only one option is available */
161161
shouldUseOptionIcon?: boolean;
162+
163+
/** Reference to the outer element */
164+
ref?: React.Ref<ButtonWithDropdownMenuRef>;
165+
};
166+
167+
type ButtonWithDropdownMenuRef = {
168+
setIsMenuVisible: (visible: boolean) => void;
162169
};
163170

164171
export type {
@@ -171,4 +178,5 @@ export type {
171178
WorkspaceTaxRatesBulkActionType,
172179
ReportExportType,
173180
OnboardingHelpType,
181+
ButtonWithDropdownMenuRef,
174182
};

src/components/DraggableList/index.native.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {FlatList} from 'react-native-gesture-handler';
44
import useThemeStyles from '@hooks/useThemeStyles';
55
import type DraggableListProps from './types';
66

7-
function DraggableList<T>({...viewProps}: DraggableListProps<T>, ref: React.ForwardedRef<FlatList<T>>) {
7+
function DraggableList<T>({ref, ...viewProps}: DraggableListProps<T> & {ref?: React.ForwardedRef<FlatList<T>>}) {
88
const styles = useThemeStyles();
99
return (
1010
<DraggableFlatList
@@ -20,4 +20,4 @@ function DraggableList<T>({...viewProps}: DraggableListProps<T>, ref: React.Forw
2020

2121
DraggableList.displayName = 'DraggableList';
2222

23-
export default React.forwardRef(DraggableList);
23+
export default DraggableList;

src/components/DraggableList/index.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ const minimumActivationDistance = 5; // pointer must move at least this much bef
1616
* Draggable (vertical) list using dnd-kit. Dragging is restricted to the vertical axis only
1717
*
1818
*/
19-
function DraggableList<T>(
20-
{
21-
data = [],
22-
renderItem,
23-
keyExtractor,
24-
onDragEnd: onDragEndCallback,
25-
// eslint-disable-next-line @typescript-eslint/naming-convention
26-
ListFooterComponent,
27-
}: DraggableListProps<T>,
28-
ref: React.ForwardedRef<RNScrollView>,
29-
) {
19+
function DraggableList<T>({
20+
data = [],
21+
renderItem,
22+
keyExtractor,
23+
onDragEnd: onDragEndCallback,
24+
// eslint-disable-next-line @typescript-eslint/naming-convention
25+
ListFooterComponent,
26+
ref,
27+
}: DraggableListProps<T> & {ref?: React.ForwardedRef<RNScrollView>}) {
3028
const styles = useThemeStyles();
3129

3230
const items = data.map((item, index) => {
@@ -103,4 +101,4 @@ function DraggableList<T>(
103101

104102
DraggableList.displayName = 'DraggableList';
105103

106-
export default React.forwardRef(DraggableList);
104+
export default DraggableList;

src/components/FloatingActionButton.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ForwardedRef} from 'react';
2-
import React, {forwardRef, useEffect, useRef} from 'react';
2+
import React, {useEffect, useRef} from 'react';
33
// eslint-disable-next-line no-restricted-imports
44
import type {GestureResponderEvent, Role, Text, View} from 'react-native';
55
import Animated, {Easing, interpolateColor, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
@@ -42,9 +42,12 @@ type FloatingActionButtonProps = {
4242

4343
/* If the tooltip is allowed to be shown */
4444
isTooltipAllowed: boolean;
45+
46+
/** Reference to the outer element */
47+
ref?: ForwardedRef<HTMLDivElement | View | Text>;
4548
};
4649

47-
function FloatingActionButton({onPress, onLongPress, isActive, accessibilityLabel, role, isTooltipAllowed}: FloatingActionButtonProps, ref: ForwardedRef<HTMLDivElement | View | Text>) {
50+
function FloatingActionButton({onPress, onLongPress, isActive, accessibilityLabel, role, isTooltipAllowed, ref}: FloatingActionButtonProps) {
4851
const {success, buttonDefaultBG, textLight} = useTheme();
4952
const styles = useThemeStyles();
5053
const borderRadius = styles.floatingActionButton.borderRadius;
@@ -157,4 +160,4 @@ function FloatingActionButton({onPress, onLongPress, isActive, accessibilityLabe
157160

158161
FloatingActionButton.displayName = 'FloatingActionButton';
159162

160-
export default forwardRef(FloatingActionButton);
163+
export default FloatingActionButton;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import type {ViewProps} from 'react-native';
1+
import type {ForwardedRef} from 'react';
2+
import type {View, ViewProps} from 'react-native';
23

34
type FocusTrapContainerElementProps = ViewProps & {
45
/** Callback to register focus trap container element */
56
onContainerElementChanged?: (element: HTMLElement | null) => void;
7+
8+
/** Reference to the outer element */
9+
ref?: ForwardedRef<View>;
610
};
711

812
export default FocusTrapContainerElementProps;

src/components/FocusTrap/FocusTrapContainerElement/index.web.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/**
22
* A wrapper View component allowing us to register a container element for a FocusTrap
33
*/
4-
import type {ForwardedRef} from 'react';
54
import React from 'react';
65
import {View} from 'react-native';
76
import type FocusTrapContainerElementProps from './FocusTrapContainerElementProps';
87

9-
function FocusTrapContainerElement({onContainerElementChanged, ...props}: FocusTrapContainerElementProps, ref?: ForwardedRef<View>) {
8+
function FocusTrapContainerElement({onContainerElementChanged, ref, ...props}: FocusTrapContainerElementProps) {
109
return (
1110
<View
1211
ref={(node) => {
@@ -26,4 +25,4 @@ function FocusTrapContainerElement({onContainerElementChanged, ...props}: FocusT
2625

2726
FocusTrapContainerElement.displayName = 'FocusTrapContainerElement';
2827

29-
export default React.forwardRef(FocusTrapContainerElement);
28+
export default FocusTrapContainerElement;

src/components/Form/InputWrapper.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ComponentPropsWithoutRef, ComponentType, ForwardedRef} from 'react';
2-
import React, {forwardRef, useContext} from 'react';
2+
import React, {useContext} from 'react';
33
import type {AnimatedTextInputRef} from '@components/RNTextInput';
44
import RoomNameInput from '@components/RoomNameInput';
55
import type RoomNameInputProps from '@components/RoomNameInput/types';
@@ -69,9 +69,12 @@ type InputWrapperProps<TInput extends ValidInputs, TValue extends ValueTypeKey =
6969
* Currently, meaningful only for text inputs.
7070
*/
7171
shouldSubmitForm?: boolean;
72+
73+
/** Reference to the outer element */
74+
ref?: ForwardedRef<AnimatedTextInputRef>;
7275
};
7376

74-
function InputWrapper<TInput extends ValidInputs, TValue extends ValueTypeKey>(props: InputWrapperProps<TInput, TValue>, ref: ForwardedRef<AnimatedTextInputRef>) {
77+
function InputWrapper<TInput extends ValidInputs, TValue extends ValueTypeKey>({ref, ...props}: InputWrapperProps<TInput, TValue>) {
7578
const {InputComponent, inputID, valueType = 'string', shouldSubmitForm: propShouldSubmitForm, ...rest} = props as InputComponentBaseProps;
7679
const {registerInput} = useContext(FormContext);
7780

@@ -91,4 +94,4 @@ function InputWrapper<TInput extends ValidInputs, TValue extends ValueTypeKey>(p
9194

9295
InputWrapper.displayName = 'InputWrapper';
9396

94-
export default forwardRef(InputWrapper);
97+
export default InputWrapper;

0 commit comments

Comments
 (0)