-
Notifications
You must be signed in to change notification settings - Fork 214
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
base: main
Are you sure you want to change the base?
Conversation
7dcb6d1
to
d6bf4c8
Compare
Thanks for working on this @shivanshsharma13. |
23e9cb0
to
b1ac761
Compare
There was a problem hiding this 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.
assets/l10n/app_en.arb
Outdated
"lightboxShareImageTooltip": "Share Image", | ||
"@lightboxShareImageTooltip": { | ||
"description": "Tooltip in lightbox for the Share Image action." | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dedent
"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." | |
}, |
lib/widgets/lightbox.dart
Outdated
_ShareButton(url: widget.src), | ||
// TODO(#43): Share image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Remove todo comment
assets/l10n/app_en.arb
Outdated
@@ -338,6 +338,10 @@ | |||
"@errorDialogTitle": { | |||
"description": "Generic title for error dialog." | |||
}, | |||
"errorShareFailed": "Error Sharing the Image", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"errorShareFailed": "Error Sharing the Image", | |
"errorShareFailed": "Failed to share the image", |
assets/l10n/app_en.arb
Outdated
@@ -346,6 +350,10 @@ | |||
"@lightboxCopyLinkTooltip": { | |||
"description": "Tooltip in lightbox for the copy link action." | |||
}, | |||
"lightboxShareImageTooltip": "Share Image", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"lightboxShareImageTooltip": "Share Image", | |
"lightboxShareImageTooltip": "Share image", |
lib/widgets/lightbox.dart
Outdated
return XFile.fromData(bytes, | ||
name: url.pathSegments.last, | ||
mimeType: response.headers['content-type']); |
There was a problem hiding this comment.
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.
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']); |
lib/widgets/lightbox.dart
Outdated
...userAgentHeader() | ||
}; | ||
final xFile = await _downloadImage(url, headers); | ||
await Share.shareXFiles([xFile]); |
There was a problem hiding this comment.
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
.
lib/widgets/lightbox.dart
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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.
lib/widgets/lightbox.dart
Outdated
...userAgentHeader() | ||
}; | ||
final xFile = await _downloadImage(url, headers); | ||
await Share.shareXFiles([xFile]); |
There was a problem hiding this comment.
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
.
lib/widgets/lightbox.dart
Outdated
...authHeader(email: store.account.email, apiKey: store.account.apiKey), | ||
...userAgentHeader() | ||
}; | ||
final xFile = await _downloadImage(url, headers); |
There was a problem hiding this comment.
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.
56935f6
to
9ac3d16
Compare
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.🙂 |
d5c283a
to
a99f96c
Compare
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
a99f96c
to
a8397e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final response = await http.get(url, headers: headers); | ||
final bytes = response.bodyBytes; | ||
return XFile.fromData(bytes, | ||
name: url.pathSegments.last, |
There was a problem hiding this comment.
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.
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