From bd2d388b510cf7071ba718014dcf7a6584f08e6c Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Mon, 21 Sep 2020 14:06:50 +0300 Subject: [PATCH] Create GroupedTableViewCell --- Riot.xcodeproj/project.pbxproj | 4 ++ .../Common/Cells/GroupedTableViewCell.swift | 47 +++++++++++++++++++ .../Common/Cells/TextFieldTableViewCell.swift | 2 +- .../Common/Cells/TextViewTableViewCell.swift | 2 +- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Riot/Modules/Common/Cells/GroupedTableViewCell.swift diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index b7147ac08..3cb50c179 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -757,6 +757,7 @@ EC2B4EF124A1EEBD005EB739 /* DataProtectionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC2B4EF024A1EEBD005EB739 /* DataProtectionHelper.swift */; }; EC2B4EF224A1EF34005EB739 /* DataProtectionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC2B4EF024A1EEBD005EB739 /* DataProtectionHelper.swift */; }; EC31F00C2515111D00D407DA /* SimpleCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC31F00B2515111D00D407DA /* SimpleCoordinator.swift */; }; + EC31F00E2518BEEB00D407DA /* GroupedTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC31F00D2518BEEB00D407DA /* GroupedTableViewCell.swift */; }; EC3B066924AC6ADE000DF9BF /* CrossSigningService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3B066424AC6ADD000DF9BF /* CrossSigningService.swift */; }; EC3B066A24AC6ADE000DF9BF /* CrossSigningSetupBannerCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = EC3B066624AC6ADD000DF9BF /* CrossSigningSetupBannerCell.xib */; }; EC3B066B24AC6ADE000DF9BF /* CrossSigningBannerPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3B066724AC6ADD000DF9BF /* CrossSigningBannerPreferences.swift */; }; @@ -1959,6 +1960,7 @@ EC1CA8D924D811B400DE9EBF /* NSE-Common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "NSE-Common.xcconfig"; sourceTree = ""; }; EC2B4EF024A1EEBD005EB739 /* DataProtectionHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataProtectionHelper.swift; sourceTree = ""; }; EC31F00B2515111D00D407DA /* SimpleCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleCoordinator.swift; sourceTree = ""; }; + EC31F00D2518BEEB00D407DA /* GroupedTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupedTableViewCell.swift; sourceTree = ""; }; EC3B066424AC6ADD000DF9BF /* CrossSigningService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CrossSigningService.swift; sourceTree = ""; }; EC3B066624AC6ADD000DF9BF /* CrossSigningSetupBannerCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CrossSigningSetupBannerCell.xib; sourceTree = ""; }; EC3B066724AC6ADD000DF9BF /* CrossSigningBannerPreferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CrossSigningBannerPreferences.swift; sourceTree = ""; }; @@ -4326,6 +4328,7 @@ ECF57A59250925AC004BBF9D /* TextFieldTableViewCell.xib */, ECF57A86250A6872004BBF9D /* TextViewTableViewCell.swift */, ECF57A88250A687B004BBF9D /* TextViewTableViewCell.xib */, + EC31F00D2518BEEB00D407DA /* GroupedTableViewCell.swift */, ); path = Cells; sourceTree = ""; @@ -6396,6 +6399,7 @@ 32891D6B2264CBA300C82226 /* SimpleScreenTemplateViewController.swift in Sources */, EC711B7924A63B37008F830C /* SecretsSetupRecoveryKeyViewController.swift in Sources */, 32FD755024D074C700BA7B37 /* CommonConfiguration.swift in Sources */, + EC31F00E2518BEEB00D407DA /* GroupedTableViewCell.swift in Sources */, B1CA3A2721EF6914000D1D89 /* UIViewController.swift in Sources */, 322C110822BBC6F80043FEAC /* WidgetManagerConfig.swift in Sources */, EC1CA86624C1DEC400DE9EBF /* EnterPinCodeViewController.swift in Sources */, diff --git a/Riot/Modules/Common/Cells/GroupedTableViewCell.swift b/Riot/Modules/Common/Cells/GroupedTableViewCell.swift new file mode 100644 index 000000000..700c05dfe --- /dev/null +++ b/Riot/Modules/Common/Cells/GroupedTableViewCell.swift @@ -0,0 +1,47 @@ +// +// Copyright 2020 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +/// This can be used in grouped table views to hide section separators for a specific cell. +class GroupedTableViewCell: UITableViewCell { + + /// Set to true in order to hide section separators. Default is `false`. + var hideSectionSeparators: Bool = false { + didSet { + if hideSectionSeparators { + removeSectionSeparators() + } + } + } + + private func removeSectionSeparators() { + for subview in subviews { + if subview != contentView && subview.bounds.width == bounds.width { + subview.removeFromSuperview() + } + } + } + + override func layoutSubviews() { + super.layoutSubviews() + + if hideSectionSeparators { + removeSectionSeparators() + } + } + +} diff --git a/Riot/Modules/Common/Cells/TextFieldTableViewCell.swift b/Riot/Modules/Common/Cells/TextFieldTableViewCell.swift index 3a3d83e45..39123b956 100644 --- a/Riot/Modules/Common/Cells/TextFieldTableViewCell.swift +++ b/Riot/Modules/Common/Cells/TextFieldTableViewCell.swift @@ -18,7 +18,7 @@ import UIKit import Reusable /// Table view cell with only a text field spanning the whole content view, insets can be configured via `textField.insets` -class TextFieldTableViewCell: UITableViewCell { +class TextFieldTableViewCell: GroupedTableViewCell { @IBOutlet weak var textField: InsettedTextField! diff --git a/Riot/Modules/Common/Cells/TextViewTableViewCell.swift b/Riot/Modules/Common/Cells/TextViewTableViewCell.swift index 830e6cf69..d82d9082c 100644 --- a/Riot/Modules/Common/Cells/TextViewTableViewCell.swift +++ b/Riot/Modules/Common/Cells/TextViewTableViewCell.swift @@ -18,7 +18,7 @@ import UIKit import Reusable /// Table view cell with only a text view spanning the whole content view, insets can be configured via `textView.textContainerInset` -class TextViewTableViewCell: UITableViewCell { +class TextViewTableViewCell: GroupedTableViewCell { @IBOutlet weak var textView: PlaceholderedTextView!