Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow providing an external scrollview. #502

Merged
merged 6 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.0.4] - 2022-07-02

- Build fix for Android projects having `kotlinVersion` defined in `build.gradle`.
- Allow providing an external scrollview.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add link to this PR here


## [1.0.3] - 2022-07-01

Expand Down
8 changes: 8 additions & 0 deletions documentation/docs/fundamentals/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ estimatedItemSize?: number;

---

### `renderScrollComponent`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Props are sorted alphabetically. Moving this would be helpful.


Rendered as the main scrollview. Its contract for the scroll event should match the native scroll event contract, i.e. `scrollEvent = { nativeEvent: { contentOffset: { x: offset, y: offset } } }`

```ts
return <FlashList renderScrollComponent={Animated.ScrollView} />;
```

### `CellRendererComponent`

Each cell is rendered using this element. Can be a React Component Class, or a render function. The root component should always be a `CellContainer` which is also the default component used. Ensure that the original `props` are passed to the returned `CellContainer`. The `props` contain the following properties:
Expand Down
2 changes: 2 additions & 0 deletions src/FlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class FlashList<T> extends React.PureComponent<
initialScrollIndex,
style,
contentContainerStyle,
renderScrollComponent,
...restProps
} = this.props;

Expand Down Expand Up @@ -350,6 +351,7 @@ class FlashList<T> extends React.PureComponent<
windowCorrectionConfig={this.getUpdatedWindowCorrectionConfig()}
itemAnimator={this.itemAnimator}
suppressBoundedSizeException
externalScrollView={renderScrollComponent as any}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typecast to BaseScrollView instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to cast it to RecyclerListViewProps["externalScrollView"] instead

    externalScrollView?: {
        new (props: ScrollViewDefaultProps): BaseScrollView;
    };

/>
</StickyHeaderContainer>
);
Expand Down
10 changes: 10 additions & 0 deletions src/FlashListProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type React from "react";
import {
StyleProp,
ScrollViewProps,
Expand All @@ -6,6 +7,7 @@ import {
ViewStyle,
ColorValue,
} from "react-native";
import type { ScrollViewDefaultProps } from "recyclerlistview/dist/reactnative/core/scrollcomponent/BaseScrollView";

import { BlankAreaEventHandler } from "./native/auto-layout/AutoLayoutView";
import ViewToken from "./viewability/ViewToken";
Expand Down Expand Up @@ -122,6 +124,14 @@ export interface FlashListProps<TItem> extends ScrollViewProps {
*/
ListHeaderComponentStyle?: StyleProp<ViewStyle> | undefined;

/**
* Rendered as the main scrollview. Its contract for the scroll event should match the native scroll event contract, i.e.
* `scrollEvent = { nativeEvent: { contentOffset: { x: offset, y: offset } } }`
*/
renderScrollComponent?:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use default scroll view props from RN. That should be fine. All this complexity in RLV is due to its web only implementation. FlashList doesn't depend on it so using ScrollView props should be fine.

| React.ComponentType<ScrollViewDefaultProps>
| React.FC<ScrollViewDefaultProps>;

/**
* You can use `contentContainerStyle` to apply padding that will be applied to the whole content itself.
* For example, you can apply this padding, so that all of your items have leading and trailing space.
Expand Down