Skip to content

Commit

Permalink
Add new TextFieldTableViewCell that uses a dynamic font.
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
  • Loading branch information
Ivansss committed Oct 21, 2024
1 parent ab0ee8e commit 7de5a58
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 97 deletions.
12 changes: 4 additions & 8 deletions NextcloudTalk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@
2CC1FF4828183958009F7288 /* NCDeckCardParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CC1FF4728183958009F7288 /* NCDeckCardParameter.m */; };
2CC1FF492818395E009F7288 /* NCDeckCardParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CC1FF4728183958009F7288 /* NCDeckCardParameter.m */; };
2CC1FF4A2818395F009F7288 /* NCDeckCardParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CC1FF4728183958009F7288 /* NCDeckCardParameter.m */; };
2CC3166E2CC698E1007CBE16 /* TextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC3166D2CC698E1007CBE16 /* TextFieldTableViewCell.swift */; };
2CC32E8D27F4540E00BB8C39 /* ReactionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC32E8C27F4540E00BB8C39 /* ReactionsView.swift */; };
2CC32E9227F45AE000BB8C39 /* ReactionsViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC32E9027F45AE000BB8C39 /* ReactionsViewCell.swift */; };
2CC32E9327F45AE000BB8C39 /* ReactionsViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CC32E9127F45AE000BB8C39 /* ReactionsViewCell.xib */; };
Expand All @@ -590,7 +591,6 @@
2CEDA88C26F492610044552B /* NSMutableAttributedString+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CEDA88B26F492610044552B /* NSMutableAttributedString+Extensions.swift */; };
2CF8AD3F2A0010FB00A4D3E6 /* MessageTranslationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CF8AD3D2A0010FB00A4D3E6 /* MessageTranslationViewController.swift */; };
2CF8AD402A0010FB00A4D3E6 /* MessageTranslationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CF8AD3E2A0010FB00A4D3E6 /* MessageTranslationViewController.xib */; };
2CF9CBFF26025F65002246EF /* TextInputTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2CF9CBFB26025F64002246EF /* TextInputTableViewCell.xib */; };
3FCA62550CD1442D28E8A7C6 /* libPods-NotificationServiceExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B81BB7A4920C391CC2CACFD /* libPods-NotificationServiceExtension.a */; };
4890175925A0D7FC2EC76CC0 /* libPods-NextcloudTalkTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7005E22D6C2896927FC3AEEC /* libPods-NextcloudTalkTests.a */; };
807E30762A83A90F00089D28 /* UserStatusOptionsSwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807E30752A83A90F00089D28 /* UserStatusOptionsSwiftUI.swift */; };
Expand All @@ -608,7 +608,6 @@
DA75580F278EEA1000A48A1B /* SettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA75580E278EEA1000A48A1B /* SettingsTableViewController.swift */; };
DA755811278EF3EF00A48A1B /* UserSettingsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA755810278EF3EF00A48A1B /* UserSettingsTableViewCell.swift */; };
DA8801A227A2DA00009EF248 /* UserProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA8801A127A2DA00009EF248 /* UserProfileTableViewController.swift */; };
DA8801A427AC52AC009EF248 /* TextInputTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA8801A327AC52AC009EF248 /* TextInputTableViewCell.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1164,6 +1163,7 @@
2CC1FF4328147F10009F7288 /* RoomSharedItemsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RoomSharedItemsTableViewController.xib; sourceTree = "<group>"; };
2CC1FF4628183958009F7288 /* NCDeckCardParameter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCDeckCardParameter.h; sourceTree = "<group>"; };
2CC1FF4728183958009F7288 /* NCDeckCardParameter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCDeckCardParameter.m; sourceTree = "<group>"; };
2CC3166D2CC698E1007CBE16 /* TextFieldTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTableViewCell.swift; sourceTree = "<group>"; };
2CC32E8C27F4540E00BB8C39 /* ReactionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsView.swift; sourceTree = "<group>"; };
2CC32E9027F45AE000BB8C39 /* ReactionsViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactionsViewCell.swift; sourceTree = "<group>"; };
2CC32E9127F45AE000BB8C39 /* ReactionsViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ReactionsViewCell.xib; sourceTree = "<group>"; };
Expand All @@ -1183,7 +1183,6 @@
2CEDA88B26F492610044552B /* NSMutableAttributedString+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+Extensions.swift"; sourceTree = "<group>"; };
2CF8AD3D2A0010FB00A4D3E6 /* MessageTranslationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTranslationViewController.swift; sourceTree = "<group>"; };
2CF8AD3E2A0010FB00A4D3E6 /* MessageTranslationViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageTranslationViewController.xib; sourceTree = "<group>"; };
2CF9CBFB26025F64002246EF /* TextInputTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TextInputTableViewCell.xib; sourceTree = "<group>"; };
342600BABD1AD1FCA48B5E59 /* Pods-NextcloudTalkTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NextcloudTalkTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-NextcloudTalkTests/Pods-NextcloudTalkTests.debug.xcconfig"; sourceTree = "<group>"; };
4202C63030F0FFBB1C16D75E /* Pods-NextcloudTalk.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NextcloudTalk.debug.xcconfig"; path = "Pods/Target Support Files/Pods-NextcloudTalk/Pods-NextcloudTalk.debug.xcconfig"; sourceTree = "<group>"; };
4D4C7BF2F97F47B0D9094618 /* Pods-NextcloudTalk.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NextcloudTalk.release.xcconfig"; path = "Pods/Target Support Files/Pods-NextcloudTalk/Pods-NextcloudTalk.release.xcconfig"; sourceTree = "<group>"; };
Expand All @@ -1210,7 +1209,6 @@
DA75580E278EEA1000A48A1B /* SettingsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableViewController.swift; sourceTree = "<group>"; };
DA755810278EF3EF00A48A1B /* UserSettingsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsTableViewCell.swift; sourceTree = "<group>"; };
DA8801A127A2DA00009EF248 /* UserProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserProfileTableViewController.swift; sourceTree = "<group>"; };
DA8801A327AC52AC009EF248 /* TextInputTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextInputTableViewCell.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1653,6 +1651,7 @@
2C36A049261487BC0026F04A /* DetailedOptionsSelectorTableViewController.m */,
1F61C76A285F65E1004D74D8 /* SimpleTableViewController.swift */,
1FB6678E28CE381300D29F8D /* SubtitleTableViewCell.swift */,
2CC3166D2CC698E1007CBE16 /* TextFieldTableViewCell.swift */,
1F468E7728DCC7310099597B /* EmojiTextField.swift */,
1F371A362A7B921A006CBFB3 /* DatePickerTextField.swift */,
2C16A82B28E7284D00EDE523 /* NCButton.swift */,
Expand Down Expand Up @@ -1847,8 +1846,6 @@
DA66582C27B6A73800B46B11 /* UserProfileTableViewController+DelegateMethods.swift */,
DA66582E27B6B19C00B46B11 /* UserProfileTableViewController+Actions.swift */,
DA66583027B6B24E00B46B11 /* UserProfileTableViewController+Utils.swift */,
DA8801A327AC52AC009EF248 /* TextInputTableViewCell.swift */,
2CF9CBFB26025F64002246EF /* TextInputTableViewCell.xib */,
2C4446EA265D25BA00DF1DBC /* NCKeyChainController.h */,
2C4446EB265D25BA00DF1DBC /* NCKeyChainController.m */,
2C444701265D641300DF1DBC /* NCUserDefaults.h */,
Expand Down Expand Up @@ -2522,7 +2519,6 @@
2C78EFA61F86FF4A008AFA74 /* CallParticipantViewCell.xib in Resources */,
2C98F77D216231D3001A6A73 /* RoomTableViewCell.xib in Resources */,
1F7625E72901B0E800834869 /* CallsFromOldAccountViewController.xib in Resources */,
2CF9CBFF26025F65002246EF /* TextInputTableViewCell.xib in Resources */,
1F24B5A428E0649200654457 /* ReferenceGithubView.xib in Resources */,
2C0424982CA335C4004772F6 /* AudioPlayerView.xib in Resources */,
2CC1FF4528147F11009F7288 /* RoomSharedItemsTableViewController.xib in Resources */,
Expand Down Expand Up @@ -2984,6 +2980,7 @@
2CA1CCD01F1E1779002FE6A2 /* SearchTableViewController.m in Sources */,
1F1C0D8929AFB89900D17C6D /* VLCKitVideoViewController.swift in Sources */,
2C9B0B98217F6DBA00A4752C /* NCNotificationController.m in Sources */,
2CC3166E2CC698E1007CBE16 /* TextFieldTableViewCell.swift in Sources */,
2C36A04A261487BC0026F04A /* DetailedOptionsSelectorTableViewController.m in Sources */,
2CA52ACB2670D02800619610 /* VoiceMessageRecordingView.m in Sources */,
2C7381562106136000CDB8DB /* NCChatTitleView.m in Sources */,
Expand Down Expand Up @@ -3084,7 +3081,6 @@
2C4446EC265D25BA00DF1DBC /* NCKeyChainController.m in Sources */,
1FD6F83C2B825069004048AB /* NCRoomsManagerExtensions.swift in Sources */,
1FF4DA802C023FF300C1B952 /* NCChatFileStatus.swift in Sources */,
DA8801A427AC52AC009EF248 /* TextInputTableViewCell.swift in Sources */,
2C2A788E2359CC8800EEB797 /* NCAppBranding.m in Sources */,
1F3C41A329EDF05700F58435 /* AvatarEditView.swift in Sources */,
2CA15541208E350300CE8EF0 /* NCChatMessage.m in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions NextcloudTalk/PollCreationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import UIKit
}

override func viewDidAppear(_ animated: Bool) {
if let questionCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: PollCreationSection.kPollCreationSectionQuestion.rawValue)) as? TextInputTableViewCell {
if let questionCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: PollCreationSection.kPollCreationSectionQuestion.rawValue)) as? TextFieldTableViewCell {
questionCell.textField.becomeFirstResponder()
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ import UIKit
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.keyboardDismissMode = UIScrollView.KeyboardDismissMode.onDrag
self.tableView.register(UINib(nibName: kTextInputTableViewCellNibName, bundle: nil), forCellReuseIdentifier: kTextInputCellIdentifier)
self.tableView.register(TextFieldTableViewCell.self, forCellReuseIdentifier: textFieldCellIdentifier)
}

// MARK: - Table view data source
Expand Down Expand Up @@ -150,7 +150,7 @@ import UIKit
tableView.beginUpdates()
tableView.insertRows(at: [indexPath], with: .automatic)
tableView.endUpdates()
if let optionCell = self.tableView.cellForRow(at: indexPath) as? TextInputTableViewCell {
if let optionCell = self.tableView.cellForRow(at: indexPath) as? TextFieldTableViewCell {
optionCell.textField.becomeFirstResponder()
}
} else {
Expand Down Expand Up @@ -192,8 +192,8 @@ import UIKit
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textInputCell = tableView.dequeueReusableCell(withIdentifier: kTextInputCellIdentifier) as? TextInputTableViewCell ??
TextInputTableViewCell(style: .default, reuseIdentifier: kTextInputCellIdentifier)
let textInputCell = tableView.dequeueReusableCell(withIdentifier: textFieldCellIdentifier) as? TextFieldTableViewCell ??
TextFieldTableViewCell(style: .default, reuseIdentifier: textFieldCellIdentifier)
textInputCell.textField.delegate = self
textInputCell.textField.autocapitalizationType = .sentences
let actionCell = tableView.dequeueReusableCell(withIdentifier: "PollSettingCellIdentifier") ?? UITableViewCell(style: .default, reuseIdentifier: "PollSettingCellIdentifier")
Expand Down
6 changes: 3 additions & 3 deletions NextcloudTalk/RoomAvatarInfoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ enum RoomAvatarInfoSection: Int {
self.navigationItem.compactAppearance = appearance
self.navigationItem.scrollEdgeAppearance = appearance

self.tableView.register(UINib(nibName: kTextInputTableViewCellNibName, bundle: nil), forCellReuseIdentifier: kTextInputCellIdentifier)
self.tableView.register(TextFieldTableViewCell.self, forCellReuseIdentifier: textFieldCellIdentifier)
self.tableView.register(UINib(nibName: RoomDescriptionTableViewCell.nibName, bundle: nil), forCellReuseIdentifier: RoomDescriptionTableViewCell.identifier)
self.tableView.tableHeaderView = self.headerView

Expand Down Expand Up @@ -126,8 +126,8 @@ enum RoomAvatarInfoSection: Int {
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let textInputCell = tableView.dequeueReusableCell(withIdentifier: kTextInputCellIdentifier) as? TextInputTableViewCell ??
TextInputTableViewCell(style: .default, reuseIdentifier: kTextInputCellIdentifier)
let textInputCell = tableView.dequeueReusableCell(withIdentifier: textFieldCellIdentifier) as? TextFieldTableViewCell ??
TextFieldTableViewCell(style: .default, reuseIdentifier: textFieldCellIdentifier)

if indexPath.section == RoomAvatarInfoSection.kRoomNameSection.rawValue {
textInputCell.textField.delegate = self
Expand Down
6 changes: 3 additions & 3 deletions NextcloudTalk/RoomCreationTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum RoomVisibilityOption: Int {
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.cancelButtonPressed))
self.navigationItem.leftBarButtonItem?.tintColor = NCAppBranding.themeTextColor()

self.tableView.register(UINib(nibName: kTextInputTableViewCellNibName, bundle: nil), forCellReuseIdentifier: kTextInputCellIdentifier)
self.tableView.register(TextFieldTableViewCell.self, forCellReuseIdentifier: textFieldCellIdentifier)
self.tableView.register(UINib(nibName: RoomDescriptionTableViewCell.nibName, bundle: nil), forCellReuseIdentifier: RoomDescriptionTableViewCell.identifier)
self.tableView.register(UINib(nibName: kContactsTableCellNibName, bundle: nil), forCellReuseIdentifier: kContactCellIdentifier)
self.tableView.tableHeaderView = self.headerView
Expand Down Expand Up @@ -426,8 +426,8 @@ enum RoomVisibilityOption: Int {
let roomCreationSection = sections[indexPath.section]

if roomCreationSection == RoomCreationSection.kRoomNameSection.rawValue {
let textInputCell = tableView.dequeueReusableCell(withIdentifier: kTextInputCellIdentifier) as? TextInputTableViewCell ??
TextInputTableViewCell(style: .default, reuseIdentifier: kTextInputCellIdentifier)
let textInputCell = tableView.dequeueReusableCell(withIdentifier: textFieldCellIdentifier) as? TextFieldTableViewCell ??
TextFieldTableViewCell(style: .default, reuseIdentifier: textFieldCellIdentifier)
textInputCell.textField.autocapitalizationType = .sentences
textInputCell.textField.tag = kRoomNameTextFieldTag
textInputCell.textField.delegate = self
Expand Down
48 changes: 48 additions & 0 deletions NextcloudTalk/TextFieldTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: GPL-3.0-or-later
//

import UIKit

let textFieldCellIdentifier = "textFieldCellIdentifier"

class TextFieldTableViewCell: UITableViewCell {

let textField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.font = UIFont.preferredFont(forTextStyle: .body)
textField.adjustsFontForContentSizeCategory = true
textField.clearButtonMode = .whileEditing
textField.returnKeyType = .done
return textField
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

contentView.addSubview(textField)

NSLayoutConstraint.activate([
textField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10),
textField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -10),
textField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
textField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16)
])
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func prepareForReuse() {
super.prepareForReuse()

textField.text = ""
textField.placeholder = nil
textField.keyboardType = .default
textField.autocorrectionType = .no
textField.autocapitalizationType = .none
}
}
30 changes: 0 additions & 30 deletions NextcloudTalk/TextInputTableViewCell.swift

This file was deleted.

Loading

0 comments on commit 7de5a58

Please sign in to comment.