diff --git a/CHANGELOG.md b/CHANGELOG.md index aa5cc93..0001790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.1.2 + +- fix: the endless loop can still happen if you switch between tabs quickly and time it perfectly while still loading gifs. + +[All Code Changes](https://github.com/Flyclops/tenor_flutter/compare/0.1.1...0.1.2) + ## 0.1.1 - fix: if you switch tabs very quickly before the initial gif fetch then you will get stuck in an endless loop and crash the app. diff --git a/lib/src/components/tab_view.dart b/lib/src/components/tab_view.dart index a6a453e..004324f 100644 --- a/lib/src/components/tab_view.dart +++ b/lib/src/components/tab_view.dart @@ -270,13 +270,8 @@ class _TenorTabViewState extends State // Wait for a frame so that we can ensure that `scrollController` is attached WidgetsBinding.instance.addPostFrameCallback((_) async { - while (_scrollController.position.extentAfter == 0) { - // Stop trying to load more and exit the loop if: - // 1 - the selected tab has changed - // 2 - there are no more gifs to load - if (_tabProvider.selectedTab != tab || !_hasMoreGifs) return; - - await _loadMore(); + if (_scrollController.position.extentAfter == 0) { + _loadMore(fillScrollableArea: true); } }); } @@ -306,7 +301,7 @@ class _TenorTabViewState extends State } } - Future _loadMore() async { + Future _loadMore({bool fillScrollableArea = false}) async { // 1 - prevent non active tabs from loading more // 2 - if it's loading don't load more // 3 - if there are no more gifs to load, don't load more @@ -367,6 +362,10 @@ class _TenorTabViewState extends State _isLoading = false; rethrow; } + + if (fillScrollableArea && _scrollController.position.extentAfter == 0) { + Future.microtask(() => _loadMore(fillScrollableArea: true)); + } } // Return selected gif diff --git a/pubspec.yaml b/pubspec.yaml index 03e4c08..ab110d6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: tenor_flutter -version: 0.1.1 +version: 0.1.2 description: An opinionated yet customizable Flutter package for searching and selecting from a list of GIFs/Stickers from the Tenor GIF search API. homepage: https://github.com/flyclops repository: https://github.com/flyclops/tenor_flutter