Skip to content

Commit ca70e8e

Browse files
RSNarafacebook-github-bot
authored andcommitted
Improve ScrollView docs and types
Summary: I was reading through the ScrollView code and realized that the documentation was incomplete, and some of the flow types were wrong. Reviewed By: yungsters Differential Revision: D13583133 fbshipit-source-id: 11c495681e9671e078e4d2c9df76c25b04558696
1 parent adc1a95 commit ca70e8e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,11 @@ class ScrollView extends React.Component<Props, State> {
599599
*
600600
* 3. Mixin methods access other mixin methods via dynamic dispatch using
601601
* this. Since mixin methods are bound to the component instance, we need
602-
* to copy all mixin methods to the component instance.
602+
* to copy all mixin methods to the component instance. This is also
603+
* necessary because getScrollResponder() is a public method that returns
604+
* an object that can be used to execute all scrollResponder methods.
605+
* Since the object returned from that method is the ScrollView instance,
606+
* we need to bind all mixin methods to the ScrollView instance.
603607
*/
604608
for (const key in ScrollResponder.Mixin) {
605609
if (
@@ -672,8 +676,14 @@ class ScrollView extends React.Component<Props, State> {
672676
* implement this method so that they can be composed while providing access
673677
* to the underlying scroll responder's methods.
674678
*/
675-
getScrollResponder(): ScrollView {
676-
return this;
679+
getScrollResponder(): {
680+
...typeof ScrollView,
681+
...typeof ScrollResponder.Mixin,
682+
} {
683+
return ((this: any): {
684+
...typeof ScrollView,
685+
...typeof ScrollResponder.Mixin,
686+
});
677687
}
678688

679689
getScrollableNode(): any {

0 commit comments

Comments
 (0)