Skip to content

Commit

Permalink
action_sheet [nfc]: Pull out base class for message action sheet buttons
Browse files Browse the repository at this point in the history
We're about to add another button, for quote-and-reply zulip#116.
  • Loading branch information
chrisbobbe committed Jun 22, 2023
1 parent 7bd4722 commit 220d58e
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,59 @@ void showMessageActionSheet({required BuildContext context, required Message mes
context: context,
builder: (BuildContext innerContext) {
return Column(children: [
MenuItemButton(
leadingIcon: Icon(Icons.adaptive.share),
onPressed: () async {
// Close the message action sheet; we're about to show the share
// sheet. (We could do this after the sharing Future settles, but
// on iOS I get impatient with how slowly our action sheet
// dismisses in that case.)
// TODO(#24): Fix iOS bug where this call causes the keyboard to
// reopen (if it was open at the time of this
// `showMessageActionSheet` call) and cover a large part of the
// share sheet.
Navigator.of(innerContext).pop();

// TODO: to support iPads, we're asked to give a
// `sharePositionOrigin` param, or risk crashing / hanging:
// https://pub.dev/packages/share_plus#ipad
// Perhaps a wart in the API; discussion:
// https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
// TODO: Share raw Markdown, not HTML
await Share.shareWithResult(message.content);
},
child: const Text('Share')),
ShareButton(message: message),
]);
});
}

abstract class MessageActionSheetMenuItemButton extends StatelessWidget {
const MessageActionSheetMenuItemButton({
super.key,
required this.message,
});

IconData get icon;
String get label;
void Function(BuildContext) get onPressed;

final Message message;

@override
Widget build(BuildContext context) {
return MenuItemButton(
leadingIcon: Icon(icon),
onPressed: () => onPressed(context),
child: Text(label));
}
}

class ShareButton extends MessageActionSheetMenuItemButton {
const ShareButton({
super.key,
required super.message,
});

@override get icon => Icons.adaptive.share;

@override get label => 'Share';

@override get onPressed => (BuildContext context) async {
// Close the message action sheet; we're about to show the share
// sheet. (We could do this after the sharing Future settles, but
// on iOS I get impatient with how slowly our action sheet
// dismisses in that case.)
// TODO(#24): Fix iOS bug where this call causes the keyboard to
// reopen (if it was open at the time of this
// `showMessageActionSheet` call) and cover a large part of the
// share sheet.
Navigator.of(context).pop();

// TODO: to support iPads, we're asked to give a
// `sharePositionOrigin` param, or risk crashing / hanging:
// https://pub.dev/packages/share_plus#ipad
// Perhaps a wart in the API; discussion:
// https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
// TODO: Share raw Markdown, not HTML
await Share.shareWithResult(message.content);
};
}

0 comments on commit 220d58e

Please sign in to comment.