Skip to content
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

lightbox: Add "share" button in bottom app bar #1145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shivanshsharma13
Copy link

@shivanshsharma13 shivanshsharma13 commented Dec 12, 2024

Add a share button to the lightbox that allows users to share image URLs. The button appears in the bottom app bar with a share icon and tooltip. Test coverage includes verifying the share button's UI elements (icon and tooltip)

Screen recording of the change

share_button.mp4

Fixes: #43

@shivanshsharma13 shivanshsharma13 force-pushed the share_lightbox branch 2 times, most recently from 7dcb6d1 to d6bf4c8 Compare December 12, 2024 19:39
@rajveermalviya rajveermalviya added the maintainer review PR ready for review by Zulip maintainers label Dec 12, 2024
@rajveermalviya rajveermalviya self-assigned this Dec 12, 2024
@rajveermalviya
Copy link
Collaborator

Thanks for working on this @shivanshsharma13.
CI is failing currently because l10n generated code doesn't match, can you please fix that.

@shivanshsharma13 shivanshsharma13 force-pushed the share_lightbox branch 3 times, most recently from 23e9cb0 to b1ac761 Compare December 13, 2024 08:24
Copy link
Collaborator

@rajveermalviya rajveermalviya left a comment

Choose a reason for hiding this comment

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

Thanks, excited to have this feature! Added some initial comments.

Also I see that there's currently a conflict, could you please rebase to main and resolve the conflicts. If you've any questions regarding that, you can refer to https://zulip.readthedocs.io/en/latest/git/index.html or ask in #git help channel in CZO.

Comment on lines 353 to 356
"lightboxShareImageTooltip": "Share Image",
"@lightboxShareImageTooltip": {
"description": "Tooltip in lightbox for the Share Image action."
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: dedent

Suggested change
"lightboxShareImageTooltip": "Share Image",
"@lightboxShareImageTooltip": {
"description": "Tooltip in lightbox for the Share Image action."
},
"lightboxShareImageTooltip": "Share Image",
"@lightboxShareImageTooltip": {
"description": "Tooltip in lightbox for the Share Image action."
},

Comment on lines 303 to 304
_ShareButton(url: widget.src),
// TODO(#43): Share image
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Remove todo comment

@@ -338,6 +338,10 @@
"@errorDialogTitle": {
"description": "Generic title for error dialog."
},
"errorShareFailed": "Error Sharing the Image",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"errorShareFailed": "Error Sharing the Image",
"errorShareFailed": "Failed to share the image",

@@ -346,6 +350,10 @@
"@lightboxCopyLinkTooltip": {
"description": "Tooltip in lightbox for the copy link action."
},
"lightboxShareImageTooltip": "Share Image",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"lightboxShareImageTooltip": "Share Image",
"lightboxShareImageTooltip": "Share image",

Comment on lines 97 to 98
return XFile.fromData(bytes,
name: url.pathSegments.last,
mimeType: response.headers['content-type']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: 2-space indentation, here and more case below.

Suggested change
return XFile.fromData(bytes,
name: url.pathSegments.last,
mimeType: response.headers['content-type']);
return XFile.fromData(bytes,
name: url.pathSegments.last,
mimeType: response.headers['content-type']);

...userAgentHeader()
};
final xFile = await _downloadImage(url, headers);
await Share.shareXFiles([xFile]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function should be wrapped and called using ZulipBinding to make it possible to write tests against.
Could be ZulipBinding.shareXFiles.

@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as httpClient;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import 'package:http/http.dart' as httpClient;
import 'package:http/http.dart' as http;

@@ -275,6 +275,29 @@ void main() {
debugNetworkImageHttpClientProvider = null;
});

testWidgets('share button shows correct icon and downloads image', (tester) async {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This'll need more tests, namely:

  • Tapping on share button opens the share sheet (check if shareXFiles function was called).
  • Share failed and the error dialog was shown.

...userAgentHeader()
};
final xFile = await _downloadImage(url, headers);
await Share.shareXFiles([xFile]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function returns a ShareResult and it provides some important information we should check for, see ShareButton implementation in lib/widgets/action_sheet.dart.

...authHeader(email: store.account.email, apiKey: store.account.apiKey),
...userAgentHeader()
};
final xFile = await _downloadImage(url, headers);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that it will download the canonical (larger) image again, first time it will be downloaded by RealmContentNetworkImage, and second time when pressing the share button here. Ideally, it'd be better to download the image only once, but I guess the http cache should handle that? Can you verify if cache is being used here.

@shivanshsharma13
Copy link
Author

Hi, thank you for the review! I’m working on the suggested changes and will let you know here once they are ready for another review.🙂

@shivanshsharma13 shivanshsharma13 force-pushed the share_lightbox branch 3 times, most recently from d5c283a to a99f96c Compare December 13, 2024 20:25
Add a share button to the lightbox that allows users to share image
URLs. The button appears in the bottom app bar with a share icon
and tooltip. Test coverage includes verifying the share button's UI
elements (icon and tooltip).

Fixes: zulip#43
Copy link
Collaborator

@rajveermalviya rajveermalviya left a comment

Choose a reason for hiding this comment

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

Tried this on iOS and seems to work well on it too:
Screenshot 2024-12-16 at 22 02 54

final response = await http.get(url, headers: headers);
final bytes = response.bodyBytes;
return XFile.fromData(bytes,
name: url.pathSegments.last,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missed this in last review — trying to get the filename this way seems fragile.

To do this correctly we will need changes in the content parser (lib/model/content.dart) to read the filename in ImageNode, but it may be out of scope for this PR. So, for now how about not populating the name field here, and leaving a TODO comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lightbox: Add "share" button in bottom app bar
2 participants