Skip to content

Commit

Permalink
feat: Get focus when touch field
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Jun 19, 2023
1 parent c86fe14 commit 1ebd518
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
12 changes: 10 additions & 2 deletions Mail/Views/New Message/V2/ComposeMessageHeaderViewV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ComposeMessageHeaderViewV2: View {
@Binding var autocompletionType: ComposeViewFieldType?

var body: some View {
VStack {
VStack(spacing: UIConstants.composeViewVerticalSpacing) {
ComposeMessageCellStaticTextV2(
autocompletionType: $autocompletionType,
type: .from,
Expand All @@ -43,6 +43,7 @@ struct ComposeMessageHeaderViewV2: View {
recipients: $draft.to,
showRecipientsFields: $showRecipientsFields,
autocompletionType: $autocompletionType,
focusedField: _focusedField,
type: .to
)

Expand All @@ -51,18 +52,25 @@ struct ComposeMessageHeaderViewV2: View {
recipients: $draft.cc,
showRecipientsFields: $showRecipientsFields,
autocompletionType: $autocompletionType,
focusedField: _focusedField,
type: .cc
)

ComposeMessageCellRecipientsV2(
recipients: $draft.bcc,
showRecipientsFields: $showRecipientsFields,
autocompletionType: $autocompletionType,
focusedField: _focusedField,
type: .bcc
)
}

ComposeMessageCellTextFieldV2(text: $draft.subject, autocompletionType: $autocompletionType, type: .subject)
ComposeMessageCellTextFieldV2(
text: $draft.subject,
autocompletionType: $autocompletionType,
focusedField: _focusedField,
type: .subject
)
}
.padding(.horizontal, 16)
.onAppear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ struct ComposeMessageCellRecipientsV2: View {
@Binding var showRecipientsFields: Bool
@Binding var autocompletionType: ComposeViewFieldType?

@FocusState var focusedField: ComposeViewFieldType?

let type: ComposeViewFieldType

var body: some View {
VStack {
VStack(spacing: UIConstants.composeViewVerticalSpacing) {
if autocompletionType == nil || autocompletionType == type {
HStack {
Text(type.title)
.textStyle(.bodySecondary)

RecipientFieldV2(currentText: $currentText, recipients: $recipients, type: type) {
RecipientFieldV2(currentText: $currentText, recipients: $recipients, focusedField: _focusedField, type: type) {
if let bestMatch = autocompletion.first {
addNewRecipient(bestMatch)
}
Expand All @@ -64,6 +66,9 @@ struct ComposeMessageCellRecipientsV2: View {
)
}
}
.onTapGesture {
focusedField = type
}
.onChange(of: currentText) { newValue in
withAnimation {
if newValue.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import SwiftUI

struct ComposeMessageCellStaticTextV2: View {
Expand All @@ -26,7 +27,7 @@ struct ComposeMessageCellStaticTextV2: View {

var body: some View {
if autocompletionType == nil {
VStack {
VStack(spacing: UIConstants.composeViewVerticalSpacing) {
HStack {
Text(type.title)
.textStyle(.bodySecondary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,33 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import SwiftUI

struct ComposeMessageCellTextFieldV2: View {
@Binding var text: String
@Binding var autocompletionType: ComposeViewFieldType?

@FocusState var focusedField: ComposeViewFieldType?

let type: ComposeViewFieldType

var body: some View {
if autocompletionType == nil {
VStack {
VStack(spacing: UIConstants.composeViewVerticalSpacing) {
HStack {
Text(type.title)
.textStyle(.bodySecondary)

TextField("", text: $text)
.focused($focusedField, equals: .subject)
}
.frame(maxWidth: .infinity, alignment: .leading)
IKDivider()
}
.onTapGesture {
focusedField = type
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions MailCore/UI/UIConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public enum UIConstants {
public static let buttonsRadius: CGFloat = 16
public static let buttonsIconSize: CGFloat = 16

public static let composeViewVerticalSpacing: CGFloat = 12

public static let bottomBarVerticalPadding: CGFloat = 8
public static let bottomBarSmallVerticalPadding: CGFloat = 4
public static let bottomBarHorizontalMinimumSpace: CGFloat = 8
Expand Down

0 comments on commit 1ebd518

Please sign in to comment.