Skip to content

feat(share_plus): Added excludedActivityTypes support for the iOS platform. #3376

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

Merged

Conversation

StanleyCocos
Copy link
Contributor

@StanleyCocos StanleyCocos commented Dec 3, 2024

The iOS platform is missing the exclusion feature. This PR adds the platform exclusion functionality for iOS.

fix: #3377

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@miquelbeltran
Copy link
Member

miquelbeltran commented Dec 3, 2024

Thanks for this contribution as well! We have to keep this one on hold because I plan to refactor the share() method parameters, as also discussed in #3307 (comment)

Your input on this topic would be appreciated as well.

@StanleyCocos
Copy link
Contributor Author

@miquelbeltran
Thank you for your reply.
I understand your plan now. If needed, I can still improve this PR after your plan.

@miquelbeltran
Copy link
Member

FYI, started working on the shareplus refactor, that should simplify adding this and other optional parameters: #3404

@StanleyCocos
Copy link
Contributor Author

Hi, that's great! I've been studying the code in your branch. It's really well-organized and tidy. Next, I need to add the parameter excludedActivityType for this pull request (PR) to ShareParams. After that, I'll wait for you to finish merging xx into the main branch. Once that's done, I'll synchronize my changes accordingly.

ozyl added a commit to ozyl/plus_plugins that referenced this pull request Feb 27, 2025
# Conflicts:
#	packages/share_plus/share_plus/ios/share_plus/Sources/share_plus/FPPSharePlusPlugin.m
#	packages/share_plus/share_plus/lib/share_plus.dart
#	packages/share_plus/share_plus/lib/src/share_plus_linux.dart
#	packages/share_plus/share_plus/lib/src/share_plus_web.dart
#	packages/share_plus/share_plus/lib/src/share_plus_windows.dart
#	packages/share_plus/share_plus_platform_interface/lib/method_channel/method_channel_share.dart
#	packages/share_plus/share_plus_platform_interface/lib/platform_interface/share_plus_platform.dart
#	packages/share_plus/share_plus_platform_interface/test/share_plus_platform_interface_test.dart
@StanleyCocos
Copy link
Contributor Author

@miquelbeltran
I’ve updated my request based on #3404. If you have time, please take a look. Thank you.

@miquelbeltran miquelbeltran self-assigned this Apr 21, 2025
@miquelbeltran
Copy link
Member

Thanks! I haven't looked too deep into it yet, but can you describe how it works in this PR, so I can understand the change better.

And as well, add a bit of documentation about this feature on the README.md so users are aware of it.

@StanleyCocos
Copy link
Contributor Author

Let me briefly describe the changes in this PR:

  • In share_plus_platform_interface, I declared a CupertinoActivityType enum and added it as a parameter to ShareParams. Before passing it to the iOS layer, it is transmitted as a string to make it easier for users to exclude unwanted share options on iOS and macOS.

  • On the iOS native side, the string passed from the Flutter layer is received and converted back into an enum, which is then applied to the share configuration.

  • In the example, I added a multi-selection page for easier testing. Due to structural issues, I also introduced a new MyApp class that returns a MaterialApp (this caused a number of structural and formatting changes).

Copy link
Member

@miquelbeltran miquelbeltran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments, I like the overall idea. I will also have to test this somehow.

Comment on lines 100 to 104
files: [XFile(fd.path)],
subject: 'some subject to share',
text: 'some text to share',
sharePositionOrigin: const Rect.fromLTWH(1.0, 2.0, 3.0, 4.0),
excludedActivityType: null),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing comma missing after null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it’s been updated.

Comment on lines 114 to 115
you can set the excludedActivityTypes array.
For the list of supported excludedActivityTypes, you can refer to Apple’s [documentation](https://developer.apple.com/documentation/uikit/uiactivityviewcontroller/excludedactivitytypes/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
you can set the excludedActivityTypes array.
For the list of supported excludedActivityTypes, you can refer to Apples [documentation](https://developer.apple.com/documentation/uikit/uiactivityviewcontroller/excludedactivitytypes/).
you can set the `excludedActivityTypes` array.
For the list of supported `excludedActivityTypes`, you can refer to Apple's [documentation](https://developer.apple.com/documentation/uikit/uiactivityviewcontroller/excludedactivitytypes/).

Small formatting suggestion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't devs check the CupertinoActivityType enum instead of the Apple docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, it should be based on CupertinoActivityType first.

///
/// * Supported platforms: iOS, macOS
/// Parameter ignored on other platforms.
final List<CupertinoActivityType>? excludedActivityType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's an apple exclusive param, can we name it so it references that? e.g. excludedCupertinoActivities since the type is CupertinoActivityType.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion is excellent — the naming alone makes the purpose clear to developers.

),
uri: Uri.parse('https://pub.dev/packages/share_plus'),
sharePositionOrigin: const Rect.fromLTWH(1.0, 2.0, 3.0, 4.0),
excludedActivityType: [CupertinoActivityType.airDrop]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it’s been updated.

@StanleyCocos StanleyCocos requested a review from miquelbeltran May 6, 2025 02:04
@StanleyCocos
Copy link
Contributor Author

@miquelbeltran
Sorry to bother you. I noticed this request has been pending for quite a while. Do you have any plans to complete the code review soon?

Comment on lines 241 to 243
extension CupertinoActivityTypeValue on CupertinoActivityType {
String get value => toString().split('.').last;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this extension used for? I don't see it used in the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s used at line 73 in method_channel_share. But I think turning it into a separate method might be a better approach now.

Comment on lines 214 to 217
/// An abstract class that you subclass to implement app-specific services
/// for iOS and macOS.
///
/// https://developer.apple.com/documentation/uikit/uiactivity/activitytype
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seem correct to me, as these are enum values not abstract classes. Can this be reworded differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right — I may have overlooked updating the documentation here. It’s now been revised; could you please take another look?

Comment on lines 440 to 449
if (excludedActivityType.count > 0) {
NSMutableArray *excludedActivityTypes = [[NSMutableArray alloc] init];
for (NSString *type in excludedActivityType) {
UIActivityType activityType = activityTypeForString(type);
if (activityType != nil) {
[excludedActivityTypes addObject:activityType];
}
}
activityViewController.excludedActivityTypes = excludedActivityTypes;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable names are a bit confusing here. excludedActivityType is the input parameter, which is an array (so it shouldn't be singular but plural), and I guess it contains the activity types as strings?

Then excludedActivityTypes is the actual array with activity type "types".

I'd suggest refactoring this a bit. Maybe extract the conversion of array of Strings to array of Activity Types into a function.

And then move it up on the logic, e.g. right after NSArray *excludedActivityType = arguments[@"excludedActivityType"]; in line 310. So all further calls to the share methods, e.g. self shareUri already pass an array of activity types and not an array of Strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion — I’ve made the adjustments. Much appreciated!

Copy link
Member

@miquelbeltran miquelbeltran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting one more change, and I think this would be completed. Thanks for keeping up with the PR!

Comment on lines 70 to 76
if (params.excludedCupertinoActivities != null &&
params.excludedCupertinoActivities!.isNotEmpty) {
final activityTypes =
params.excludedCupertinoActivities!.map((e) => e.value).toList();
map['excludedActivityType'] = activityTypes;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'll have to request another change. We renamed the variable excludedCupertinoActivities as it previously was excludedActivityType. However, I think it would be good if the map key would also be the same, to avoid confusion with that. I missed that when I first reviewed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion.

Slightly adjusted, but I still have some other thoughts.

I have a slightly different idea about this part. I think using excludedCupertinoActivities as the key name in the map may not be entirely appropriate, because accessing a key with “Cupertino” in its name on the iOS side feels a bit odd.

Also, I think if Android were to support a similar feature, we should still use this same key name to pass it down (even though Android doesn’t support it directly, it can potentially be handled by excluding package names).
If we do implement it for Android, I think we could introduce a new List parameter for excluded package names.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I don't see why would it feel weird to access a map value with the key Cupertino in it, as it is just the parsing of the parameters map, once read the value the variables don't need to be explicitly Cupertino.

I think if Android were to support a similar feature, we should still use this same key name to pass it down

I would disagree with that, I think keeping the params keys separated and explicit per platform (e.g. the Android one would be excludedAndroidPackages) will avoid confusion for devs not familiar with the codebase.

From the public API perspective, we should allow users to call to share() with both the Cupertino and the Android params in it, and internally it's simpler if we don't have a switch-case per platform but rather just copy each param into the corresponding params map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it’s just a minor naming style issue. I’ve already made the adjustment.
Thank you

@miquelbeltran
Copy link
Member

Tested on iOS 18.5 simulator using the example app ✅

@miquelbeltran
Copy link
Member

Thanks for the changes, I think it's good to go now!

@miquelbeltran miquelbeltran merged commit f9fdadb into fluttercommunity:main Jun 24, 2025
21 of 23 checks passed
@StanleyCocos StanleyCocos deleted the feat/add_activity_type branch June 26, 2025 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request]: (share_plus) Add platform exclusion functionality for iOS.
2 participants