Skip to content

Commit b32a6c9

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Replace use of private HostInstance types in Fantom tests (#56947)
Summary: Pull Request resolved: #56947 #### Context For the Strict TypeScript API rollout, I'm understanding how we've defined, exposed, and applied component ref/element types for built-in React Native components. These are currently inconsistent and breaking between languages (Flow, manual TS types, and generated Strict TS types) and are a key surface area for migration incompatibilities and user confusion. As a first phase, I want to align all Flow usages towards one pattern — even if this isn't the pattern we end up shipping for TypeScript. #### This diff Replace use of the private `TextInputInstance` type in our Fantom test code. - `TextInput-itest.js` now depends on public APIs only, and aligns with how external Flow callers (`xplat/js`) need to access this type. **Notably**, this preserves `HostInstance` (`<View>`) uses (exported at root) as the remaining exception to the rule — which remains an open design problem I'm looking to address in T270727973 (via RN WG consultation). Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D106128324 fbshipit-source-id: 8961dda1aab0e78a48e3824980842762df42ce38
1 parent 48fe6df commit b32a6c9

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

packages/react-native/Libraries/Components/TextInput/__tests__/TextInput-itest.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1212

13-
import type {TextInputInstance} from '../TextInput.flow';
14-
1513
import * as Fantom from '@react-native/fantom';
1614
import nullthrows from 'nullthrows';
1715
import * as React from 'react';
@@ -45,7 +43,7 @@ describe('<TextInput>', () => {
4543
describe('onChange', () => {
4644
it('is called when the change native event is dispatched', () => {
4745
const root = Fantom.createRoot();
48-
const nodeRef = createRef<TextInputInstance>();
46+
const nodeRef = createRef<React.ElementRef<typeof TextInput>>();
4947
const onChange = jest.fn();
5048

5149
Fantom.runTask(() => {
@@ -76,7 +74,7 @@ describe('<TextInput>', () => {
7674
describe('onChangeText', () => {
7775
it('is called when the change native event is dispatched', () => {
7876
const root = Fantom.createRoot();
79-
const nodeRef = createRef<TextInputInstance>();
77+
const nodeRef = createRef<React.ElementRef<typeof TextInput>>();
8078
const onChangeText = jest.fn();
8179

8280
Fantom.runTask(() => {
@@ -100,7 +98,7 @@ describe('<TextInput>', () => {
10098
describe('onFocus', () => {
10199
it('is called when the focus native event is dispatched', () => {
102100
const root = Fantom.createRoot();
103-
const nodeRef = createRef<TextInputInstance>();
101+
const nodeRef = createRef<React.ElementRef<typeof TextInput>>();
104102

105103
let focusEvent = jest.fn();
106104

@@ -126,7 +124,7 @@ describe('<TextInput>', () => {
126124
describe('onBlur', () => {
127125
it('is called when the blur native event is dispatched', () => {
128126
const root = Fantom.createRoot();
129-
const nodeRef = createRef<TextInputInstance>();
127+
const nodeRef = createRef<React.ElementRef<typeof TextInput>>();
130128

131129
let blurEvent = jest.fn();
132130

@@ -284,7 +282,7 @@ describe('<TextInput>', () => {
284282

285283
describe('ref', () => {
286284
it('is an element node', () => {
287-
const ref = createRef<TextInputInstance>();
285+
const ref = createRef<React.ElementRef<typeof TextInput>>();
288286

289287
const root = Fantom.createRoot();
290288

@@ -296,7 +294,7 @@ describe('<TextInput>', () => {
296294
});
297295

298296
it('provides additional methods: clear, isFocused, getNativeRef, setSelection', () => {
299-
const ref = createRef<TextInputInstance>();
297+
const ref = createRef<React.ElementRef<typeof TextInput>>();
300298

301299
const root = Fantom.createRoot();
302300

@@ -313,7 +311,7 @@ describe('<TextInput>', () => {
313311
describe('focus()', () => {
314312
it('dispatches the focus command', () => {
315313
const root = Fantom.createRoot();
316-
const ref = createRef<TextInputInstance>();
314+
const ref = createRef<React.ElementRef<typeof TextInput>>();
317315

318316
Fantom.runTask(() => {
319317
root.render(<TextInput nativeID="text-input" ref={ref} />);
@@ -411,8 +409,8 @@ describe('<TextInput>', () => {
411409

412410
it('unfocuses any previously focused TextInput when a new one is focused', () => {
413411
const root = Fantom.createRoot();
414-
const ref1 = createRef<TextInputInstance>();
415-
const ref2 = createRef<TextInputInstance>();
412+
const ref1 = createRef<React.ElementRef<typeof TextInput>>();
413+
const ref2 = createRef<React.ElementRef<typeof TextInput>>();
416414

417415
Fantom.runTask(() => {
418416
root.render(
@@ -450,7 +448,7 @@ describe('<TextInput>', () => {
450448
describe('blur()', () => {
451449
it('does NOT dispatch any commands if the input is NOT focused', () => {
452450
const root = Fantom.createRoot();
453-
const ref = createRef<TextInputInstance>();
451+
const ref = createRef<React.ElementRef<typeof TextInput>>();
454452

455453
Fantom.runTask(() => {
456454
root.render(<TextInput nativeID="text-input" ref={ref} />);
@@ -469,7 +467,7 @@ describe('<TextInput>', () => {
469467

470468
it('does dispatches the blur command if the input is focused', () => {
471469
const root = Fantom.createRoot();
472-
const ref = createRef<TextInputInstance>();
470+
const ref = createRef<React.ElementRef<typeof TextInput>>();
473471

474472
Fantom.runTask(() => {
475473
root.render(<TextInput nativeID="text-input" ref={ref} />);
@@ -496,7 +494,7 @@ describe('<TextInput>', () => {
496494
describe('clear()', () => {
497495
it('dispatches the clear command', () => {
498496
const root = Fantom.createRoot();
499-
const ref = createRef<TextInputInstance>();
497+
const ref = createRef<React.ElementRef<typeof TextInput>>();
500498

501499
Fantom.runTask(() => {
502500
root.render(
@@ -521,7 +519,7 @@ describe('<TextInput>', () => {
521519
describe('isFocused()', () => {
522520
it('returns true if the input is focused', () => {
523521
const root = Fantom.createRoot();
524-
const ref = createRef<TextInputInstance>();
522+
const ref = createRef<React.ElementRef<typeof TextInput>>();
525523

526524
Fantom.runTask(() => {
527525
root.render(<TextInput nativeID="text-input" ref={ref} />);
@@ -546,7 +544,7 @@ describe('<TextInput>', () => {
546544

547545
it('returns false if the input is unmounted', () => {
548546
const root = Fantom.createRoot();
549-
const ref = createRef<TextInputInstance>();
547+
const ref = createRef<React.ElementRef<typeof TextInput>>();
550548

551549
Fantom.runTask(() => {
552550
root.render(<TextInput nativeID="text-input" ref={ref} />);
@@ -582,7 +580,7 @@ describe('<TextInput>', () => {
582580
expect(TextInput.State.currentlyFocusedInput()).toBe(null);
583581

584582
const root = Fantom.createRoot();
585-
const ref = createRef<TextInputInstance>();
583+
const ref = createRef<React.ElementRef<typeof TextInput>>();
586584

587585
Fantom.runTask(() => {
588586
root.render(<TextInput nativeID="text-input" ref={ref} />);
@@ -606,7 +604,7 @@ describe('<TextInput>', () => {
606604
describe('setSelection', () => {
607605
it('dispatches the setTextAndSelection command', () => {
608606
const root = Fantom.createRoot();
609-
const ref = createRef<TextInputInstance>();
607+
const ref = createRef<React.ElementRef<typeof TextInput>>();
610608

611609
Fantom.runTask(() => {
612610
root.render(

0 commit comments

Comments
 (0)