Skip to content

Commit faf5e6f

Browse files
thomasvoclaude
andcommitted
Remove unnecessary type assertion on internalRef
Type useRef as View | null to avoid the MutableRefObject cast. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5efd60f commit faf5e6f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/components/KeyboardAvoidingView/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const KeyboardAvoidingView = forwardRef<
9292
ref,
9393
) => {
9494
const initialFrame = useSharedValue<LayoutRectangle | null>(null);
95-
const internalRef = React.useRef<View>(null);
95+
const internalRef = React.useRef<View | null>(null);
9696
const frame = useDerivedValue(() => initialFrame.value || defaultLayout);
9797

9898
const { translate, padding } = useTranslateAnimation();
@@ -209,11 +209,15 @@ const KeyboardAvoidingView = forwardRef<
209209
}, [behavior, enabled, interpolateToRelativeKeyboardHeight]);
210210
const combinedRef = useCallback(
211211
(node: View | null) => {
212-
(internalRef as React.MutableRefObject<View | null>).current = node;
212+
internalRef.current = node;
213213

214-
if (typeof ref === "function") ref(node);
215-
else if (ref)
214+
if (typeof ref === "function") {
215+
ref(node);
216+
} else if (ref != null && "current" in ref) {
217+
// ForwardedRef includes RefObject whose .current is readonly in TS,
218+
// but React always passes a mutable ref object at runtime.
216219
(ref as React.MutableRefObject<View | null>).current = node;
220+
}
217221
},
218222
[ref],
219223
);

0 commit comments

Comments
 (0)