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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions packages/share_plus/share_plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ if (result.status == ShareResultStatus.dismissed) {
}
```

On iOS or macOS, if you want to exclude certain options from appearing in your share sheet,
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.


```dart
ShareParams(
// rest of params
excludedActivityTypes: [CupertinoActivityType.postToFacebook],
)
```

On web, this uses the [Web Share API](https://web.dev/web-share/)
if it's available. Otherwise it falls back to downloading the shared files.
See [Can I Use - Web Share API](https://caniuse.com/web-share) to understand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';

class ExcludedActivityTypePage extends StatefulWidget {
final List<CupertinoActivityType>? excludedActivityType;

const ExcludedActivityTypePage({
super.key,
this.excludedActivityType,
});

@override
State<StatefulWidget> createState() => _ExcludedActivityTypePageState();
}

class _ExcludedActivityTypePageState extends State<ExcludedActivityTypePage> {
final List<String> options = [];
final List<String> selected = [];

@override
void initState() {
for (final type in CupertinoActivityType.values) {
options.add(type.value);
}
if (widget.excludedActivityType != null &&
widget.excludedActivityType!.isNotEmpty) {
for (final type in widget.excludedActivityType!) {
selected.add(type.value);
}
}
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Excluded Activity Type'),
actions: [
IconButton(
icon: const Icon(Icons.check),
onPressed: () {
final List<CupertinoActivityType> tempSelected = [];
for (final String type in selected) {
tempSelected.add(
CupertinoActivityType.values
.firstWhere((e) => e.value == type),
);
}
Navigator.pop(context, tempSelected);
},
),
],
),
body: ListView(
children: options.map((option) {
return CheckboxListTile(
value: selected.contains(option),
title: Text(option),
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool? checked) {
setState(() {
if (checked == true) {
selected.add(option);
} else {
selected.remove(option);
}
});
},
);
}).toList(),
),
);
}
}
Loading
Loading