Commit 55a3c1c
Add *Instance type exports for all built-in components
Summary:
Add a publicly exported `*Instance` type for every built-in component in `index.js.flow`, giving consumers a consistent way to type refs for any React Native component.
Affects the Strict TypeScript API (opt-in generated TS types) only.
#### Motivation + RFC
Draft implementation for the recommended approach in react-native-community/discussions-and-proposals#1003.
Alternative to #56673.
#### New types
| Component | Instance Type | Type Value |
|---|---|---|
| `ActivityIndicator` | `ActivityIndicatorInstance` | `HostInstance` |
| `Button` | `ButtonInstance` | `ButtonRef` (platform-dependent) |
| `DrawerLayoutAndroid` | `DrawerLayoutAndroidInstance` | `DrawerLayoutAndroidMethods` |
| `FlatList` | `FlatListInstance` | `FlatList<>` |
| `Image` | `ImageInstance` | `HostInstance` |
| `ImageBackground` | `ImageBackgroundInstance` | `ImageBackground` (class) |
| `KeyboardAvoidingView` | `KeyboardAvoidingViewInstance` | `KeyboardAvoidingView` (class) |
| `Modal` | `ModalInstance` | `HostInstance` |
| `Pressable` | `PressableInstance` | `HostInstance` |
| `ProgressBarAndroid` | `ProgressBarAndroidInstance` | `HostInstance` |
| `RefreshControl` | `RefreshControlInstance` | `RefreshControl` (class) |
| `SafeAreaView` | `SafeAreaViewInstance` | `HostInstance` |
| `ScrollView` | `ScrollViewInstance` | `extends HostInstance, ScrollViewImperativeMethods` |
| `SectionList` | `SectionListInstance` | `SectionList<>` |
| `StatusBar` | `StatusBarInstance` | `StatusBar` (class) |
| `Switch` | `SwitchInstance` | `HostInstance` |
| `Text` | `TextInstance` | `HostInstance` |
| `TextInput` | `TextInputInstance` | `extends ReactNativeElement` (existing) |
| `TouchableHighlight` | `TouchableHighlightInstance` | `HostInstance` |
| `TouchableNativeFeedback` | `TouchableNativeFeedbackInstance` | `TouchableNativeFeedback` (class) |
| `TouchableOpacity` | `TouchableOpacityInstance` | `HostInstance` |
| `View` | `ViewInstance` | `HostInstance` |
| `VirtualizedList` | `VirtualizedListInstance` | `React.ElementRef<VirtualizedListType>` |
| `VirtualizedSectionList` | `VirtualizedSectionListInstance` | `React.ElementRef<VirtualizedSectionListType>` |
#### Renames
- `PublicScrollViewInstance` → `ScrollViewInstance` (old name kept as deprecated alias; internal usages in `ScrollView.js` and `FlatList.js` updated)
- `PublicModalInstance` → `ModalInstance` (old name kept as deprecated alias)
#### Skipped (no ref support)
`InputAccessoryView`, `experimental_LayoutConformance`, `TouchableWithoutFeedback`, `Touchable` (namespace)
Changelog:
[General][Added] - **Strict TypeScript API**: Add `*Instance` ref types for all built-in components
Differential Revision: D1061443831 parent b32a6c9 commit 55a3c1c
31 files changed
Lines changed: 210 additions & 61 deletions
File tree
- packages/react-native
- Libraries
- Components
- ActivityIndicator
- DrawerAndroid
- Keyboard
- Pressable
- ProgressBarAndroid
- RefreshControl
- SafeAreaView
- ScrollView
- StatusBar
- Switch
- TextInput
- Touchable
- View
- Image
- Lists
- Modal
- Text
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
305 | 307 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| 301 | + | |
| 302 | + | |
301 | 303 | | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
208 | 210 | | |
0 commit comments