-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add the initial avatar action menu [...] #570
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3881fb6
Add ellipsis icon
pinarol 42a5de3
Introduce AvatarAction enum
pinarol 2807352
Add the ellipsis view and action menu
pinarol bcc9356
Add actions for horizontal and vertical grid
pinarol d0dc3ec
Handle action
pinarol 18f7924
Update strings in base locale
pinarol fc1a8cb
Update strings in base locale
pinarol 0687201
Update loc key
pinarol 1513894
Remove unnecessary `@ViewBuilder`s
pinarol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Sources/GravatarUI/Resources/Media.xcassets/more-horizontal.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "more-horizontal.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ravatarUI/Resources/Media.xcassets/more-horizontal.imageset/more-horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Sources/GravatarUI/SwiftUI/AvatarPicker/AvatarAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
enum AvatarAction: String, CaseIterable, Identifiable { | ||
case share | ||
case delete | ||
|
||
var id: String { rawValue } | ||
|
||
var icon: Image { | ||
switch self { | ||
case .delete: | ||
Image(systemName: "trash") | ||
case .share: | ||
Image(systemName: "square.and.arrow.up") | ||
} | ||
} | ||
|
||
var localizedTitle: String { | ||
switch self { | ||
case .delete: | ||
SDKLocalizedString( | ||
"AvatarPicker.AvatarAction.delete", | ||
value: "Delete", | ||
comment: "An option in the avatar menu that deletes the avatar" | ||
) | ||
case .share: | ||
SDKLocalizedString( | ||
"AvatarPicker.AvatarAction.share", | ||
value: "Share", | ||
comment: "An option in the avatar menu that shares the avatar" | ||
) | ||
} | ||
} | ||
|
||
var role: ButtonRole? { | ||
switch self { | ||
case .delete: | ||
.destructive | ||
case .share: | ||
nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ struct AvatarPickerAvatarView: View { | |
let shouldSelect: () -> Bool | ||
let onAvatarTap: (AvatarImageModel) -> Void | ||
let onFailedUploadTapped: (FailedUploadInfo) -> Void | ||
let onActionTap: (AvatarAction) -> Void | ||
|
||
var body: some View { | ||
AvatarView( | ||
|
@@ -54,12 +55,46 @@ struct AvatarPickerAvatarView: View { | |
} | ||
.cornerRadius(AvatarGridConstants.avatarCornerRadius) | ||
case .loaded: | ||
EmptyView() | ||
VStack { | ||
Spacer() | ||
HStack { | ||
Spacer() | ||
actionsMenu() | ||
} | ||
} | ||
} | ||
}.onTapGesture { | ||
onAvatarTap(avatar) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func ellipsisView() -> some View { | ||
Image("more-horizontal", bundle: Bundle.module).renderingMode(.template) | ||
.tint(.white) | ||
.background(Color(uiColor: UIColor.gravatarBlack.withAlphaComponent(0.4))) | ||
.cornerRadius(2) | ||
.padding(CGFloat.DS.Padding.half) | ||
} | ||
|
||
@ViewBuilder | ||
func actionsMenu() -> some View { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Removing. |
||
Menu { | ||
ForEach(AvatarAction.allCases) { action in | ||
Button(role: action.role) { | ||
onActionTap(action) | ||
} label: { | ||
Label { | ||
Text(action.localizedTitle) | ||
} icon: { | ||
action.icon | ||
} | ||
} | ||
} | ||
} label: { | ||
ellipsisView() | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
|
@@ -68,5 +103,6 @@ struct AvatarPickerAvatarView: View { | |
false | ||
} onAvatarTap: { _ in | ||
} onFailedUploadTapped: { _ in | ||
} onActionTap: { _ in | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As an alternative: We can set the rendering mode directly in the asset catalog.
That's good if the icon is always meant to be used this way.
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.
Right but asset catalogs are more fragile. It is easy to lose that setting if we change the icon. Setting it programmatically is safer.