-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into refactor-panels
# Conflicts: # Mail/Views/Thread List/ThreadListView.swift # MailCore/UI/UIConstants.swift # Project.swift
- Loading branch information
Showing
19 changed files
with
445 additions
and
119 deletions.
There are no files selected for viewing
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
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,77 @@ | ||
/* | ||
Infomaniak Mail - iOS App | ||
Copyright (C) 2022 Infomaniak Network SA | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import InfomaniakCoreUI | ||
import MailCore | ||
import MailResources | ||
import Popovers | ||
import SwiftUI | ||
|
||
struct RecipientChip: View { | ||
@Environment(\.window) private var window | ||
@AppStorage(UserDefaults.shared.key(.accentColor)) private var accentColor = DefaultPreferences.accentColor | ||
|
||
let recipient: Recipient | ||
let fieldType: ComposeViewFieldType | ||
@FocusState var focusedField: ComposeViewFieldType? | ||
let removeHandler: () -> Void | ||
let switchFocusHandler: () -> Void | ||
|
||
var body: some View { | ||
Templates.Menu { | ||
$0.width = nil | ||
$0.originAnchor = .topLeft | ||
$0.popoverAnchor = .topLeft | ||
} content: { | ||
RecipientCell(recipient: recipient) | ||
.padding(.vertical, 8) | ||
.padding(.horizontal, 16) | ||
.frame(maxWidth: min(304, 0.8 * (window?.screen.bounds.width ?? 304))) | ||
|
||
Templates.MenuButton(text: Text(MailResourcesStrings.Localizable.contactActionCopyEmailAddress), | ||
image: MailResourcesAsset.duplicate.swiftUIImage) { | ||
UIPasteboard.general.string = recipient.email | ||
IKSnackBar.showSnackBar(message: MailResourcesStrings.Localizable.snackbarEmailCopiedToClipboard) | ||
} | ||
|
||
Templates.MenuButton(text: Text(MailResourcesStrings.Localizable.actionDelete), | ||
image: MailResourcesAsset.bin.swiftUIImage) { | ||
removeHandler() | ||
} | ||
} label: { isSelected in | ||
RecipientChipLabelView(recipient: recipient, removeHandler: removeAndFocus, switchFocusHandler: switchFocusHandler) | ||
.fixedSize() | ||
.opacity(isSelected ? 0.8 : 1) | ||
} | ||
} | ||
|
||
private func removeAndFocus() { | ||
focusedField = fieldType | ||
removeHandler() | ||
} | ||
} | ||
|
||
struct RecipientChip_Previews: PreviewProvider { | ||
static var previews: some View { | ||
RecipientChip(recipient: PreviewHelper.sampleRecipient1, fieldType: .to) { | ||
/* Preview */ | ||
} switchFocusHandler: { | ||
/* Preview */ | ||
} | ||
} | ||
} |
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,103 @@ | ||
/* | ||
Infomaniak Mail - iOS App | ||
Copyright (C) 2022 Infomaniak Network SA | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import Foundation | ||
import MailCore | ||
import SwiftUI | ||
import UIKit | ||
|
||
struct RecipientChipLabelView: UIViewRepresentable { | ||
let recipient: Recipient | ||
let removeHandler: () -> Void | ||
let switchFocusHandler: () -> Void | ||
|
||
func makeUIView(context: Context) -> RecipientChipLabel { | ||
let label = RecipientChipLabel(recipient: recipient) | ||
label.removeHandler = removeHandler | ||
label.switchFocusHandler = switchFocusHandler | ||
return label | ||
} | ||
|
||
func updateUIView(_ uiLabel: RecipientChipLabel, context: Context) { | ||
uiLabel.text = recipient.name.isEmpty ? recipient.email : recipient.name | ||
} | ||
} | ||
|
||
class RecipientChipLabel: UILabel, UIKeyInput { | ||
var removeHandler: (() -> Void)? | ||
var switchFocusHandler: (() -> Void)? | ||
|
||
override var intrinsicContentSize: CGSize { | ||
var contentSize = super.intrinsicContentSize | ||
contentSize.height += UIConstants.chipInsets.top + UIConstants.chipInsets.bottom | ||
contentSize.width += UIConstants.chipInsets.left + UIConstants.chipInsets.right | ||
return contentSize | ||
} | ||
|
||
override var canBecomeFirstResponder: Bool { return true } | ||
|
||
var hasText = false | ||
|
||
init(recipient: Recipient) { | ||
super.init(frame: .zero) | ||
|
||
text = recipient.name.isEmpty ? recipient.email : recipient.name | ||
textAlignment = .center | ||
numberOfLines = 1 | ||
|
||
font = .systemFont(ofSize: 16) | ||
updateColors(isFirstResponder: false) | ||
|
||
layer.cornerRadius = intrinsicContentSize.height / 2 | ||
layer.masksToBounds = true | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func drawText(in rect: CGRect) { | ||
super.drawText(in: rect.inset(by: UIConstants.chipInsets)) | ||
} | ||
|
||
override func becomeFirstResponder() -> Bool { | ||
updateColors(isFirstResponder: true) | ||
return super.becomeFirstResponder() | ||
} | ||
|
||
override func resignFirstResponder() -> Bool { | ||
updateColors(isFirstResponder: false) | ||
return super.resignFirstResponder() | ||
} | ||
|
||
func insertText(_ text: String) { | ||
if text == "\t" { | ||
switchFocusHandler?() | ||
} | ||
} | ||
|
||
func deleteBackward() { | ||
removeHandler?() | ||
} | ||
|
||
private func updateColors(isFirstResponder: Bool) { | ||
textColor = isFirstResponder ? UserDefaults.shared.accentColor.secondary.color : .tintColor | ||
backgroundColor = isFirstResponder ? .tintColor : UserDefaults.shared.accentColor.secondary.color | ||
} | ||
} |
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
Oops, something went wrong.