Skip to content

Commit 6f7fe7e

Browse files
authored
⚡️ Use viewAsset in the preview button (#508)
Resolves #507 (reply in thread).
1 parent 52039a3 commit 6f7fe7e

File tree

6 files changed

+74
-103
lines changed

6 files changed

+74
-103
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ that can be found in the LICENSE file. -->
66

77
See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.
88

9+
## 8.7.2
10+
11+
### Improvements
12+
13+
- Use `viewAsset` in the preview button.
14+
915
## 8.7.1
1016

1117
### Improvements

example/ios/Podfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ def install_plugin_pods(application_path = nil, relative_symlink_dir, platform)
4646
plugin_pods.each do |plugin_hash|
4747
plugin_name = plugin_hash['name']
4848
plugin_path = plugin_hash['path']
49+
# iOS and macOS code can be shared in "darwin" directory, otherwise
50+
# respectively in "ios" or "macos" directories.
51+
shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false)
52+
platform_directory = shared_darwin_source ? 'darwin' : platform
4953
if (plugin_name && plugin_path)
50-
specPath = "#{plugin_path}/#{platform}/#{plugin_name}.podspec"
54+
specPath = "#{plugin_path}/#{platform_directory}/#{plugin_name}.podspec"
5155
pod plugin_name, :path => specPath
5256
end
5357
end

example/macos/Podfile

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,74 +9,63 @@ project 'Runner', {
99
'Release' => :release,
1010
}
1111

12-
def parse_KV_file(file, separator='=')
13-
file_abs_path = File.expand_path(file)
14-
if !File.exists? file_abs_path
15-
return [];
12+
def flutter_root
13+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
14+
unless File.exist?(generated_xcode_build_settings_path)
15+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
1616
end
17-
pods_ary = []
18-
skip_line_start_symbols = ["#", "/"]
19-
File.foreach(file_abs_path) { |line|
20-
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
21-
plugin = line.split(pattern=separator)
22-
if plugin.length == 2
23-
podname = plugin[0].strip()
24-
path = plugin[1].strip()
25-
podpath = File.expand_path("#{path}", file_abs_path)
26-
pods_ary.push({:name => podname, :path => podpath});
27-
else
28-
puts "Invalid plugin specification: #{line}"
29-
end
30-
}
31-
return pods_ary
32-
end
3317

34-
def pubspec_supports_macos(file)
35-
file_abs_path = File.expand_path(file)
36-
if !File.exists? file_abs_path
37-
return false;
18+
File.foreach(generated_xcode_build_settings_path) do |line|
19+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
20+
return matches[1].strip if matches
3821
end
39-
File.foreach(file_abs_path) { |line|
40-
return true if line =~ /^\s*macos:/
41-
}
42-
return false
22+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
4323
end
4424

45-
target 'Runner' do
46-
use_frameworks!
47-
use_modular_headers!
25+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
26+
27+
flutter_macos_podfile_setup
28+
29+
def install_plugin_pods(application_path = nil, relative_symlink_dir, platform)
30+
# defined_in_file is set by CocoaPods and is a Pathname to the Podfile.
31+
application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
32+
raise 'Could not find application path' unless application_path
4833

4934
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
5035
# referring to absolute paths on developers' machines.
51-
ephemeral_dir = File.join('Flutter', 'ephemeral')
52-
symlink_dir = File.join(ephemeral_dir, '.symlinks')
53-
symlink_plugins_dir = File.join(symlink_dir, 'plugins')
54-
system("rm -rf #{symlink_dir}")
55-
system("mkdir -p #{symlink_plugins_dir}")
5636

57-
# Flutter Pods
58-
generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig'))
59-
if generated_xcconfig.empty?
60-
puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
61-
end
62-
generated_xcconfig.map { |p|
63-
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
64-
symlink = File.join(symlink_dir, 'flutter')
65-
File.symlink(File.dirname(p[:path]), symlink)
66-
pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path]))
67-
end
68-
}
37+
symlink_dir = File.expand_path(relative_symlink_dir, application_path)
38+
system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils.
39+
40+
symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
41+
system('mkdir', '-p', symlink_plugins_dir)
6942

70-
# Plugin Pods
71-
plugin_pods = parse_KV_file('../.flutter-plugins')
72-
plugin_pods.map { |p|
73-
symlink = File.join(symlink_plugins_dir, p[:name])
74-
File.symlink(p[:path], symlink)
75-
if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml'))
76-
pod p[:name], :path => File.join(symlink, 'macos')
43+
plugins_file = File.join(application_path, '..', '.flutter-plugins-dependencies')
44+
plugin_pods = flutter_parse_plugins_file(plugins_file, platform)
45+
plugin_pods.each do |plugin_hash|
46+
plugin_name = plugin_hash['name']
47+
plugin_path = plugin_hash['path']
48+
# iOS and macOS code can be shared in "darwin" directory, otherwise
49+
# respectively in "ios" or "macos" directories.
50+
shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false)
51+
platform_directory = shared_darwin_source ? 'darwin' : platform
52+
if (plugin_name && plugin_path)
53+
specPath = "#{plugin_path}/#{platform_directory}/#{plugin_name}.podspec"
54+
pod plugin_name, :path => specPath
7755
end
78-
}
56+
end
7957
end
8058

81-
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
82-
install! 'cocoapods', :disable_input_output_paths => true
59+
target 'Runner' do
60+
use_frameworks!
61+
use_modular_headers!
62+
63+
flutter_install_macos_engine_pod(File.dirname(File.realpath(__FILE__)))
64+
install_plugin_pods(File.dirname(File.realpath(__FILE__)), '.symlinks', 'macos')
65+
end
66+
67+
post_install do |installer|
68+
installer.pods_project.targets.each do |target|
69+
flutter_additional_macos_build_settings(target)
70+
end
71+
end

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker_demo
22
description: The demo project for the wechat_assets_picker package.
3-
version: 8.7.1+45
3+
version: 8.7.2+46
44
publish_to: none
55

66
environment:

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -875,19 +875,16 @@ class DefaultAssetPickerBuilderDelegate
875875
) async {
876876
final DefaultAssetPickerProvider provider =
877877
context.read<DefaultAssetPickerProvider>();
878-
bool selectedAllAndNotSelected() =>
879-
!provider.selectedAssets.contains(currentAsset) &&
880-
provider.selectedMaximumAssets;
881-
bool selectedPhotosAndIsVideo() =>
882-
isWeChatMoment &&
883-
currentAsset.type == AssetType.video &&
884-
provider.selectedAssets.isNotEmpty;
885-
// When we reached the maximum select count and the asset
886-
// is not selected, do nothing.
887-
// When the special type is WeChat Moment, pictures and videos cannot
888-
// be selected at the same time. Video select should be banned if any
889-
// pictures are selected.
890-
if (selectedAllAndNotSelected() || selectedPhotosAndIsVideo()) {
878+
// - When we reached the maximum select count and the asset is not selected,
879+
// do nothing.
880+
// - When the special type is WeChat Moment, pictures and videos cannot
881+
// be selected at the same time. Video select should be banned if any
882+
// pictures are selected.
883+
if ((!provider.selectedAssets.contains(currentAsset) &&
884+
provider.selectedMaximumAssets) ||
885+
(isWeChatMoment &&
886+
currentAsset.type == AssetType.video &&
887+
provider.selectedAssets.isNotEmpty)) {
891888
return;
892889
}
893890
final List<AssetEntity> current;
@@ -1924,33 +1921,6 @@ class DefaultAssetPickerBuilderDelegate
19241921

19251922
@override
19261923
Widget previewButton(BuildContext context) {
1927-
Future<void> onTap() async {
1928-
final DefaultAssetPickerProvider p =
1929-
context.read<DefaultAssetPickerProvider>();
1930-
final List<AssetEntity> selectedAssets = p.selectedAssets;
1931-
final List<AssetEntity> selected;
1932-
if (isWeChatMoment) {
1933-
selected = selectedAssets
1934-
.where((AssetEntity e) => e.type == AssetType.image)
1935-
.toList();
1936-
} else {
1937-
selected = selectedAssets;
1938-
}
1939-
final List<AssetEntity>? result = await AssetPickerViewer.pushToViewer(
1940-
context,
1941-
previewAssets: selected,
1942-
previewThumbnailSize: previewThumbnailSize,
1943-
selectPredicate: selectPredicate,
1944-
selectedAssets: selected,
1945-
selectorProvider: provider,
1946-
themeData: theme,
1947-
maxAssets: p.maxAssets,
1948-
);
1949-
if (result != null) {
1950-
Navigator.of(context).maybePop(result);
1951-
}
1952-
}
1953-
19541924
return Consumer<DefaultAssetPickerProvider>(
19551925
builder: (_, DefaultAssetPickerProvider p, Widget? child) {
19561926
return ValueListenableBuilder<bool>(
@@ -1965,8 +1935,10 @@ class DefaultAssetPickerBuilderDelegate
19651935
);
19661936
},
19671937
child: Consumer<DefaultAssetPickerProvider>(
1968-
builder: (_, DefaultAssetPickerProvider p, __) => GestureDetector(
1969-
onTap: p.isSelectedNotEmpty ? onTap : null,
1938+
builder: (context, DefaultAssetPickerProvider p, __) => GestureDetector(
1939+
onTap: p.isSelectedNotEmpty
1940+
? () => viewAsset(context, 0, p.selectedAssets.first)
1941+
: null,
19701942
child: Selector<DefaultAssetPickerProvider, String>(
19711943
selector: (_, DefaultAssetPickerProvider p) =>
19721944
p.selectedDescriptions,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: wechat_assets_picker
2-
version: 8.7.1
2+
version: 8.7.2
33
description: |
44
An image picker (also with videos and audio)
55
for Flutter projects based on WeChat's UI,

0 commit comments

Comments
 (0)