Skip to content

Commit

Permalink
add react-native patch
Browse files Browse the repository at this point in the history
fix virtualizedList scrollToEnd for 0 items(facebook/react-native#36067)
  • Loading branch information
creature-water-valley committed Apr 27, 2023
1 parent 4ebd0d0 commit a5e5524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions template/patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ node_modules/
※ 現在は `withPlugins` に渡されている plugin のみが対象です(`withRunOnce`, `withStaticPlugin` は対象外)。

`app.config.js``disabledPlugins`にpluginの`name`を追加すれば除外できます。

## [react-native] FlatListでデータが0件の場合に`scrollToEnd`を呼び出すとエラーが発生する問題に対処するパッチ

FlatListでデータが0件の場合に`scrollToEnd`を呼び出すと以下のエラーが発生します。

> ERROR Invariant Violation: Tried to get frame for out of range index -1, js engine: hermes
この問題に対するissueとPull Requestは以下になります。
* https://github.com/facebook/react-native/issues/36066
* https://github.com/facebook/react-native/pull/36067

Pull Requestは既にクローズされ`main`ブランチにはマージされていますが、このアプリで使用している`react-native`のバージョンにはまだ入っていないため、パッチを当てています。
14 changes: 14 additions & 0 deletions template/patches/react-native+0.71.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/node_modules/react-native/Libraries/Lists/VirtualizedList.js b/node_modules/react-native/Libraries/Lists/VirtualizedList.js
index e948a85..4534330 100644
--- a/node_modules/react-native/Libraries/Lists/VirtualizedList.js
+++ b/node_modules/react-native/Libraries/Lists/VirtualizedList.js
@@ -157,6 +157,9 @@ export default class VirtualizedList extends StateSafePureComponent<
scrollToEnd(params?: ?{animated?: ?boolean, ...}) {
const animated = params ? params.animated : true;
const veryLast = this.props.getItemCount(this.props.data) - 1;
+ if (veryLast < 0) {
+ return;
+ }
const frame = this.__getFrameMetricsApprox(veryLast, this.props);
const offset = Math.max(
0,

0 comments on commit a5e5524

Please sign in to comment.