Commit 5162816
fix: fix getNativeScrollRef return type for FlatList (#54735)
Summary:
### The Problem
When trying to measure the location of a View within a FlatList (ie. for scrolling to the view), the current recommended method is to use measureLayout on the nested view to determine its location inside the containing FlatList:
```
const MyComponent = () => {
const flatListRef = useRef<FlatList>(null);
const nestedViewRef = useRef<View>(null);
const scrollToNestedView = () => {
if (!flatListRef.current || !nestedViewRef.current) {
return;
}
nestedViewRef.current.measureLayout(
flatListRef.current.getNativeScrollRef(),
(x, y) => { flatListRef.current.scrollTo({ y, animated: true }); },
);
}
return (
<FlatList ref={flatListRef}>
<View ref={nestedViewRef}>
{ /* content */ }
</View>
</FlatList>
);
}
```
However the types for `FlatList` `getNativeScrollRef` don't allow this.
### The solution
This solution is basically identical to that in #52203. The return value for `getNativeScrollRef` should be `HostInstance | null`
## Changelog:[GENERAL] [FIXED] - Change FlatList.getNativeScrollRef return type definition to allow accessing the underlying HostInstance.
Pull Request resolved: #54735
Test Plan: None needed. This is only a type update exposing existing functionality.
Reviewed By: zeyap
Differential Revision: D104393366
Pulled By: huntie
fbshipit-source-id: 700f708d9a39b16af3e0ed90a7480513611016271 parent e2e6553 commit 5162816
2 files changed
Lines changed: 58 additions & 43 deletions
Lines changed: 54 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| |||
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
843 | 862 | | |
844 | 863 | | |
845 | 864 | | |
| |||
850 | 869 | | |
851 | 870 | | |
852 | 871 | | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
| 872 | + | |
| 873 | + | |
861 | 874 | | |
862 | 875 | | |
863 | | - | |
864 | | - | |
| 876 | + | |
865 | 877 | | |
866 | 878 | | |
867 | 879 | | |
| |||
870 | 882 | | |
871 | 883 | | |
872 | 884 | | |
873 | | - | |
874 | | - | |
| 885 | + | |
875 | 886 | | |
876 | 887 | | |
877 | 888 | | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | | - | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | | - | |
888 | | - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
889 | 906 | | |
890 | | - | |
891 | | - | |
| 907 | + | |
892 | 908 | | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
898 | 912 | | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
899 | 918 | | |
900 | 919 | | |
901 | 920 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
229 | 228 | | |
230 | 229 | | |
231 | 230 | | |
232 | | - | |
| 231 | + | |
| 232 | + | |
233 | 233 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 234 | + | |
239 | 235 | | |
240 | 236 | | |
241 | 237 | | |
| |||
0 commit comments