diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a18f274..f146780b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,9 +16,10 @@ that can be found in the LICENSE file. --> ### Fixes -- Fix previewing selected assets behavior. +- Fix previewing selected assets' behavior. - Use `PermissionRequestOption` as much as possible. - Raise more errors for non-synced paths. +- Fix the experience with `shouldRevertGrid`. ## 9.0.0-dev.2 diff --git a/lib/src/constants/typedefs.dart b/lib/src/constants/typedefs.dart index 1d2c8689..ed8e4aaa 100644 --- a/lib/src/constants/typedefs.dart +++ b/lib/src/constants/typedefs.dart @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; import 'package:photo_manager/photo_manager.dart' show PermissionState; import 'package:provider/provider.dart'; -/// {@nodoc} +/// Mirroring [ChangeNotifierProvider]. typedef CNP = ChangeNotifierProvider; /// {@template wechat_assets_picker.LoadingIndicatorBuilder} diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index cf3c77fa..eb5f3513 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -883,7 +883,8 @@ class DefaultAssetPickerBuilderDelegate provider.selectedAssets.isNotEmpty)) { return; } - final List current; + final revert = effectiveShouldRevertGrid(context); + List current; final List? selected; final int effectiveIndex; if (isWeChatMoment) { @@ -905,7 +906,10 @@ class DefaultAssetPickerBuilderDelegate } else { current = provider.currentAssets; selected = provider.selectedAssets; - effectiveIndex = index; + effectiveIndex = revert ? current.length - index - 1 : index; + } + if (revert && index == null) { + current = current.reversed.toList(growable: false); } final List? result = await AssetPickerViewer.pushToViewer( context, @@ -918,7 +922,7 @@ class DefaultAssetPickerBuilderDelegate selectorProvider: provider, specialPickerType: specialPickerType, maxAssets: provider.maxAssets, - shouldReversePreview: isAppleOS(context), + shouldReversePreview: revert, ); if (result != null) { Navigator.of(context).maybePop(result); diff --git a/lib/src/delegates/asset_picker_viewer_builder_delegate.dart b/lib/src/delegates/asset_picker_viewer_builder_delegate.dart index 86942db6..e73effee 100644 --- a/lib/src/delegates/asset_picker_viewer_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_viewer_builder_delegate.dart @@ -410,7 +410,9 @@ class DefaultAssetPickerViewerBuilderDelegate @override Widget assetPageBuilder(BuildContext context, int index) { - final AssetEntity asset = previewAssets.elementAt(index); + final AssetEntity asset = previewAssets.elementAt( + shouldReversePreview ? previewAssets.length - index - 1 : index, + ); final Widget builder = switch (asset.type) { AssetType.audio => AudioPageBuilder(asset: asset), AssetType.image => ImagePageBuilder( @@ -634,7 +636,10 @@ class DefaultAssetPickerViewerBuilderDelegate stream: pageStreamController.stream, builder: (_, AsyncSnapshot snapshot) { final AssetEntity asset = selectedAssets!.elementAt(index); - final bool isViewing = previewAssets[snapshot.data!] == asset; + final viewingIndex = shouldReversePreview + ? previewAssets.length - snapshot.data! - 1 + : snapshot.data!; + final bool isViewing = previewAssets[viewingIndex] == asset; final Widget item = switch (asset.type) { AssetType.image => _imagePreviewItem(asset), AssetType.video => _videoPreviewItem(asset), @@ -930,7 +935,6 @@ class DefaultAssetPickerViewerBuilderDelegate controller: pageController, itemCount: previewAssets.length, itemBuilder: assetPageBuilder, - reverse: shouldReversePreview, onPageChanged: (int index) { currentIndex = index; pageStreamController.add(index);