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

Add option to clear layout cache #910

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

- Update types to match `react-native@0.72` view types.
- https://github.com/Shopify/flash-list/pull/890
- Add option to clear cached layouts on update
- https://github.com/Shopify/flash-list/pull/910

## [1.5.0] - 2023-07-12

Expand Down
6 changes: 3 additions & 3 deletions fixture/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ PODS:
- React-Core
- SDWebImage (~> 5.11.1)
- SDWebImageWebPCoder (~> 0.8.4)
- RNFlashList (1.4.3):
- RNFlashList (1.5.0):
- React-Core
- RNFlashList/Tests (1.4.3):
- RNFlashList/Tests (1.5.0):
- React-Core
- RNGestureHandler (2.5.0):
- React-Core
Expand Down Expand Up @@ -630,7 +630,7 @@ SPEC CHECKSUMS:
ReactCommon: 149e2c0acab9bac61378da0db5b2880a1b5ff59b
ReactNativePerformanceListsProfiler: b9f7cfe8d08631fbce8e4729d388a5a3f7f562c2
RNFastImage: 1f2cab428712a4baaf78d6169eaec7f622556dd7
RNFlashList: ade81b4e928ebd585dd492014d40fb8d0e848aab
RNFlashList: 25b0e092b4470c84db0386d4f5316dc34123bb6d
RNGestureHandler: bad495418bcbd3ab47017a38d93d290ebd406f50
RNReanimated: 3d1432ce7b6b7fc31f375dcabe5b4585e0634a43
RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19
Expand Down
7 changes: 7 additions & 0 deletions src/FlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,13 @@ class FlashList<T> extends React.PureComponent<
return this.distanceFromWindow;
}

/**
* FlashList will skip using layout cache on next update. Can be useful when you know the layout will change drastically for example, orientation change when used as a carousel.
*/
public clearLayoutCacheOnUpdate() {
this.state.layoutProvider.markExpired();
}

/**
* Tells the list an interaction has occurred, which should trigger viewability calculations, e.g. if waitForInteractions is true and the user has not scrolled.
* This is typically called by taps on items or by navigation actions.
Expand Down
7 changes: 7 additions & 0 deletions src/GridLayoutProviderWithProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export default class GridLayoutProviderWithProps<T> extends GridLayoutProvider {
return this._hasExpired;
}

/**
* Calling this method will mark the layout provider as expired. As a result, a new one will be created by FlashList and old cached layouts will be discarded.
*/
public markExpired() {
this._hasExpired = true;
}

/**
* Calling this method will help the layout provider track average item sizes on its own
* Overriding layout manager can help achieve the same thing without relying on this method being called however, it will make implementation very complex for a simple use case
Expand Down
Loading