From 87077ab202222b9daed0e6a3c3b8cb1f3748a62c Mon Sep 17 00:00:00 2001 From: Isaac Rowntree Date: Fri, 20 Nov 2026 14:17:41 +1100 Subject: [PATCH] fix(button): type touchableRef as a ref to the touchable's instance Co-Authored-By: Claude Opus 5.5 --- src/components/Button/Button.tsx | 2 +- src/components/__tests__/Button.test.tsx | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx index 2e4d2cf519..c40a8ea43d 100644 --- a/src/components/Button/Button.tsx +++ b/src/components/Button/Button.tsx @@ -152,7 +152,7 @@ export type Props = $Omit, 'mode'> & { /** * Reference for the touchable */ - touchableRef?: React.RefObject; + touchableRef?: React.Ref>; /** * testID to be used on tests. */ diff --git a/src/components/__tests__/Button.test.tsx b/src/components/__tests__/Button.test.tsx index 8917eaca92..74f61f2224 100644 --- a/src/components/__tests__/Button.test.tsx +++ b/src/components/__tests__/Button.test.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Animated, StyleSheet } from 'react-native'; +import { Animated, StyleSheet, View } from 'react-native'; import { act, fireEvent, render } from '@testing-library/react-native'; import color from 'color'; @@ -218,6 +218,25 @@ it('should execute onPressOut', () => { expect(onPressOutMock).toHaveBeenCalledTimes(1); }); +it('passes the touchable to a callback touchableRef', () => { + const touchableRef = jest.fn< + void, + [React.ComponentRef | null] + >(); + + const { unmount } = render( + + ); + + expect(touchableRef).toHaveBeenLastCalledWith( + expect.objectContaining({ measure: expect.any(Function) }) + ); + unmount(); + expect(touchableRef).toHaveBeenLastCalledWith(null); +}); + describe('button text styles', () => { it('applies uppercase styles if uppercase prop is truthy', () => { const { getByTestId } = render(