Skip to content

Commit

Permalink
Implement getNativeScrollRef (#776)
Browse files Browse the repository at this point in the history
* Implement `getNativeScrollRef`

* Update type

* Update types again

---------

Co-authored-by: ananyachandra14 <[email protected]>
  • Loading branch information
j-piasecki and ananyachandra14 authored Jun 17, 2024
1 parent f2bdac4 commit f802191
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { ComponentCompat } from "../utils/ComponentCompat";
import ScrollComponent from "../platform/reactnative/scrollcomponent/ScrollComponent";
import ViewRenderer from "../platform/reactnative/viewrenderer/ViewRenderer";
import { DefaultJSItemAnimator as DefaultItemAnimator } from "../platform/reactnative/itemanimators/defaultjsanimator/DefaultJSItemAnimator";
import { Platform } from "react-native";
import { Platform, ScrollView } from "react-native";
const IS_WEB = !Platform || Platform.OS === "web";
//#endif

Expand All @@ -54,6 +54,7 @@ const IS_WEB = !Platform || Platform.OS === "web";
//import ViewRenderer from "../platform/web/viewrenderer/ViewRenderer";
//import { DefaultWebItemAnimator as DefaultItemAnimator } from "../platform/web/itemanimators/DefaultWebItemAnimator";
//const IS_WEB = true;
//type ScrollView = unknown;
//#endif

/***
Expand Down Expand Up @@ -394,6 +395,13 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
return null;
}

public getNativeScrollRef(): ScrollView | null {
if (this._scrollComponent && this._scrollComponent.getNativeScrollRef) {
return this._scrollComponent.getNativeScrollRef();
}
return null;
}

public renderCompat(): JSX.Element {
//TODO:Talha
// const {
Expand Down
6 changes: 6 additions & 0 deletions src/core/scrollcomponent/BaseScrollComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from "react";
import { ScrollView } from "react-native";
import { Dimension } from "../dependencies/LayoutProvider";
import BaseScrollView, { ScrollEvent, ScrollViewDefaultProps } from "./BaseScrollView";

Expand All @@ -25,4 +26,9 @@ export default abstract class BaseScrollComponent extends React.Component<Scroll
public getScrollableNode(): number | null {
return null;
}

//Override and return ref to your custom scrollview. Useful if you need to use Animated Events on the new architecture.
public getNativeScrollRef(): ScrollView | null {
return null;
}
}
4 changes: 4 additions & 0 deletions src/platform/reactnative/scrollcomponent/ScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export default class ScrollComponent extends BaseScrollComponent {
return null;
}

public getNativeScrollRef(): ScrollView | null {
return this._scrollViewRef;
}

public render(): JSX.Element {
const Scroller = TSCast.cast<ScrollView>(this.props.externalScrollView); //TSI
const renderContentContainer = this.props.renderContentContainer ? this.props.renderContentContainer : this._defaultContainer;
Expand Down

0 comments on commit f802191

Please sign in to comment.