-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #831 from Infomaniak/new-recipients-behavior
feat: ComposeView collapse fields
- Loading branch information
Showing
15 changed files
with
275 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
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 SwiftUI | ||
import MailCore | ||
|
||
extension EdgeInsets { | ||
init(uiEdgeInsets insets: UIEdgeInsets) { | ||
self.init(top: insets.top, leading: insets.left, bottom: insets.bottom, trailing: insets.right) | ||
} | ||
} | ||
|
||
struct MoreRecipientsChip: View { | ||
@AppStorage(UserDefaults.shared.key(.accentColor)) private var accentColor = DefaultPreferences.accentColor | ||
|
||
let count: Int | ||
|
||
var body: some View { | ||
Text("+\(count)") | ||
.textStyle(.bodyAccent) | ||
.padding(EdgeInsets(uiEdgeInsets: UIConstants.chipInsets)) | ||
.background( | ||
RoundedRectangle(cornerRadius: 50) | ||
.fill(accentColor.secondary.swiftUIColor) | ||
) | ||
} | ||
} | ||
|
||
struct MoreRecipientsChip_Previews: PreviewProvider { | ||
static var previews: some View { | ||
MoreRecipientsChip(count: 42) | ||
} | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
Mail/Views/New Message/Recipients/FullRecipientsList.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,63 @@ | ||
/* | ||
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 MailCore | ||
import RealmSwift | ||
import SwiftUI | ||
import WrappingHStack | ||
|
||
struct FullRecipientsList: View { | ||
@Binding var recipients: RealmSwift.List<Recipient> | ||
|
||
@FocusState var focusedField: ComposeViewFieldType? | ||
|
||
let type: ComposeViewFieldType | ||
|
||
var body: some View { | ||
WrappingHStack(recipients.indices, spacing: .constant(8), lineSpacing: 8) { i in | ||
RecipientChip(recipient: recipients[i], fieldType: type, focusedField: _focusedField) { | ||
remove(recipientAt: i) | ||
} switchFocusHandler: { | ||
switchFocus() | ||
} | ||
.focused($focusedField, equals: .chip(type.hashValue, recipients[i])) | ||
} | ||
} | ||
|
||
@MainActor private func remove(recipientAt: Int) { | ||
withAnimation { | ||
$recipients.remove(at: recipientAt) | ||
} | ||
} | ||
|
||
private func switchFocus() { | ||
guard case let .chip(hash, recipient) = focusedField else { return } | ||
|
||
if recipient == recipients.last { | ||
focusedField = type | ||
} else if let recipientIndex = recipients.firstIndex(of: recipient) { | ||
focusedField = .chip(hash, recipients[recipientIndex + 1]) | ||
} | ||
} | ||
} | ||
|
||
struct FullRecipientsList_Previews: PreviewProvider { | ||
static var previews: some View { | ||
FullRecipientsList(recipients: .constant(PreviewHelper.sampleRecipientsList), type: .to) | ||
} | ||
} |
Oops, something went wrong.