diff --git a/Icro.xcodeproj/project.pbxproj b/Icro.xcodeproj/project.pbxproj index b53ac805..2887b3cc 100644 --- a/Icro.xcodeproj/project.pbxproj +++ b/Icro.xcodeproj/project.pbxproj @@ -77,8 +77,6 @@ C504652D274F77C60004B812 /* KeyboardLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B3C79D521C52D2C00F699B8 /* KeyboardLayoutGuide.swift */; }; C504652E274F77C60004B812 /* ItemTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BE9455D2079EFCE004F9FF4 /* ItemTableViewCell.swift */; }; C504652F274F77C60004B812 /* UIViewController+Loading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA6D1782087ACF900F484B2 /* UIViewController+Loading.swift */; }; - C5046530274F77C60004B812 /* KeyboardInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B3F68782098BBA200A24983 /* KeyboardInputView.xib */; }; - C5046532274F77C60004B812 /* KeyboardInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B3F68762098BB8800A24983 /* KeyboardInputView.swift */; }; C5046533274F77C60004B812 /* ComposeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B60CF4C2072A66C00C51258 /* ComposeViewController.swift */; }; C5046534274F77C70004B812 /* VideoThumbnailImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BD2FE672259E0DC00591490 /* VideoThumbnailImageProvider.swift */; }; C5046535274F77C70004B812 /* LocalizedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1384221C6332B0040353C /* LocalizedString.swift */; }; @@ -93,8 +91,6 @@ C504653E274F77C70004B812 /* KeyboardLayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B3C79D521C52D2C00F699B8 /* KeyboardLayoutGuide.swift */; }; C504653F274F77C70004B812 /* ItemTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BE9455D2079EFCE004F9FF4 /* ItemTableViewCell.swift */; }; C5046540274F77C70004B812 /* UIViewController+Loading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA6D1782087ACF900F484B2 /* UIViewController+Loading.swift */; }; - C5046541274F77C70004B812 /* KeyboardInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B3F68782098BBA200A24983 /* KeyboardInputView.xib */; }; - C5046543274F77C70004B812 /* KeyboardInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B3F68762098BB8800A24983 /* KeyboardInputView.swift */; }; C5046544274F77C70004B812 /* ComposeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B60CF4C2072A66C00C51258 /* ComposeViewController.swift */; }; C5046545274F77CD0004B812 /* IcroEditorTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5A498F423B69636006ED94F /* IcroEditorTheme.swift */; }; C5046546274F77CE0004B812 /* IcroEditorTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5A498F423B69636006ED94F /* IcroEditorTheme.swift */; }; @@ -116,6 +112,8 @@ C5454DB423CB9FD200739A6C /* TypedSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = C5454DB323CB9FD200739A6C /* TypedSymbols */; }; C5454DB523CBA0EF00739A6C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C5FA2ACA1EB4482C006DEB40 /* Assets.xcassets */; }; C550D77A2740F0E800E10CF6 /* Style in Frameworks */ = {isa = PBXBuildFile; productRef = C550D7792740F0E800E10CF6 /* Style */; }; + C55BAF29275D489D009E8A9C /* ComposeKeyboardInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55BAF28275D489D009E8A9C /* ComposeKeyboardInputView.swift */; }; + C55BAF2A275D489D009E8A9C /* ComposeKeyboardInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55BAF28275D489D009E8A9C /* ComposeKeyboardInputView.swift */; }; C577C3C8274A46B200CCC4CD /* DropdownTitleView in Frameworks */ = {isa = PBXBuildFile; productRef = C577C3C7274A46B200CCC4CD /* DropdownTitleView */; }; C57D6F182748EFE400278AD5 /* Style in Frameworks */ = {isa = PBXBuildFile; productRef = C57D6F172748EFE400278AD5 /* Style */; }; C58956D527500B3C00B7E392 /* MicropubEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B869B07214E4633000A051C /* MicropubEndpoint.swift */; }; @@ -285,8 +283,6 @@ 5B3C79C121C518B700F699B8 /* MainNavigator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainNavigator.swift; path = Navigator/MainNavigator.swift; sourceTree = ""; }; 5B3C79C521C51B4900F699B8 /* ItemNavigatorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemNavigatorProtocol.swift; sourceTree = ""; }; 5B3C79D521C52D2C00F699B8 /* KeyboardLayoutGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardLayoutGuide.swift; sourceTree = ""; }; - 5B3F68762098BB8800A24983 /* KeyboardInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardInputView.swift; sourceTree = ""; }; - 5B3F68782098BBA200A24983 /* KeyboardInputView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KeyboardInputView.xib; sourceTree = ""; }; 5B44C71620979CF20003B35D /* MuteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MuteViewModel.swift; path = ViewModel/MuteViewModel.swift; sourceTree = ""; }; 5B4639DC2168FE9B00200D8F /* TabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = ""; }; 5B4639DE216901BE00200D8F /* SplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = ""; }; @@ -385,6 +381,7 @@ C550D7782740F0BC00E10CF6 /* Style */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Style; sourceTree = ""; }; C550D77F2740F79000E10CF6 /* Font+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+Settings.swift"; sourceTree = ""; }; C553DD5023F7CABC0001E7DF /* Client */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Client; sourceTree = ""; }; + C55BAF28275D489D009E8A9C /* ComposeKeyboardInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeKeyboardInputView.swift; sourceTree = ""; }; C55D7AC523F7C756004E5DBB /* Icro.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Icro.xctestplan; sourceTree = ""; }; C589571627500C0100B7E392 /* libiconv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libiconv.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/lib/libiconv.tbd; sourceTree = DEVELOPER_DIR; }; C589572927500FF200B7E392 /* Icro-Share-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Icro-Share-Bridging-Header.h"; sourceTree = ""; }; @@ -650,9 +647,8 @@ 5B2A5A7920A6196700B54399 /* FakeTableCellButton.swift */, 5BE9455D2079EFCE004F9FF4 /* ItemTableViewCell.swift */, 5BE9455E2079EFCE004F9FF4 /* ItemTableViewCell.xib */, - 5B3F68762098BB8800A24983 /* KeyboardInputView.swift */, - 5B3F68782098BBA200A24983 /* KeyboardInputView.xib */, 5B3C79AC21C4E58B00F699B8 /* LinkLabel.swift */, + C55BAF28275D489D009E8A9C /* ComposeKeyboardInputView.swift */, ); path = View; sourceTree = ""; @@ -1230,7 +1226,6 @@ files = ( C5046539274F77C70004B812 /* ItemTableViewCell.xib in Resources */, C504653C274F77C70004B812 /* ComposeViewController.xib in Resources */, - C5046541274F77C70004B812 /* KeyboardInputView.xib in Resources */, 5BC1384721C639160040353C /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1268,7 +1263,6 @@ C504652B274F77C60004B812 /* ComposeViewController.xib in Resources */, BF707E742131C45600506E64 /* Localizable.strings in Resources */, C5FA2ACE1EB4482C006DEB40 /* LaunchScreen.storyboard in Resources */, - C5046530274F77C60004B812 /* KeyboardInputView.xib in Resources */, C5FA2ACB1EB4482C006DEB40 /* Assets.xcassets in Resources */, 5B20952122F6B0CF00C06123 /* acknowledgements.json in Resources */, ); @@ -1329,10 +1323,10 @@ C58956D827500B3C00B7E392 /* ListViewModelListType.swift in Sources */, C58956D527500B3C00B7E392 /* MicropubEndpoint.swift in Sources */, C58956DD27500B3C00B7E392 /* DiscoveryCategory.swift in Sources */, - C5046543274F77C70004B812 /* KeyboardInputView.swift in Sources */, C58956E527500B3C00B7E392 /* Item.swift in Sources */, C504654A274F78460004B812 /* ComposeNavigatorProtocol.swift in Sources */, C58956D627500B3C00B7E392 /* ComposeViewModel.swift in Sources */, + C55BAF2A275D489D009E8A9C /* ComposeKeyboardInputView.swift in Sources */, C5046538274F77C70004B812 /* FakeTableCellButton.swift in Sources */, C58956D727500B3C00B7E392 /* Date+Ago.swift in Sources */, C504653F274F77C70004B812 /* ItemTableViewCell.swift in Sources */, @@ -1381,6 +1375,7 @@ C58956F727500B3D00B7E392 /* Media.swift in Sources */, 5B583728212861770076121E /* SettingsNavigator.swift in Sources */, C504652D274F77C60004B812 /* KeyboardLayoutGuide.swift in Sources */, + C55BAF29275D489D009E8A9C /* ComposeKeyboardInputView.swift in Sources */, C5DEA4E1275B49C300530E96 /* HostingCell.swift in Sources */, C5DEA4E3275B4A0C00530E96 /* ProfileCellView.swift in Sources */, C589571327500B9100B7E392 /* WPBase64Utils.m in Sources */, @@ -1460,7 +1455,6 @@ C5046546274F77CE0004B812 /* IcroEditorTheme.swift in Sources */, 5B3B4C2C21D0C6BF00F511A6 /* AppearanceManager.swift in Sources */, C58956F527500B3D00B7E392 /* Author.swift in Sources */, - C5046532274F77C60004B812 /* KeyboardInputView.swift in Sources */, C5046523274F77C60004B812 /* VideoThumbnailImageProvider.swift in Sources */, C58956EE27500B3D00B7E392 /* DiscoveryCategoryStore.swift in Sources */, C5046527274F77C60004B812 /* FakeTableCellButton.swift in Sources */, diff --git a/IcroKit/ViewModel/ComposeViewModel.swift b/IcroKit/ViewModel/ComposeViewModel.swift index 67de3d1c..c48a71f5 100644 --- a/IcroKit/ViewModel/ComposeViewModel.swift +++ b/IcroKit/ViewModel/ComposeViewModel.swift @@ -64,15 +64,6 @@ public final class ComposeViewModel { } } - public var canUploadImage: Bool { - switch mode { - case .shareText, .shareURL: - return false - case .post, .reply, .shareImage: - return true - } - } - public var startText: String { switch mode { case .post: diff --git a/IcroUIKit/View/ComposeKeyboardInputView.swift b/IcroUIKit/View/ComposeKeyboardInputView.swift new file mode 100644 index 00000000..78752769 --- /dev/null +++ b/IcroUIKit/View/ComposeKeyboardInputView.swift @@ -0,0 +1,126 @@ +// +// ComposeKeyboardInputView.swift +// Icro +// +// Created by martinhartl on 05.12.21. +// Copyright © 2021 Martin Hartl. All rights reserved. +// + +import Combine +import SwiftUI +import Style + +final class ComposeKeyboardInputViewModel: ObservableObject { + @Published var characterCountText = "" + @Published var postButtonEnabled = false + @Published var imageButtonEnabled = false + @Published var imageButtonHidden = false + @Published var progressHidden = false + @Published var progress: Float = 0.0 + + func update(for text: String, numberOfImages: Int, imageState: ImageState, hidesImageButton: Bool) { + if text.isEmpty { + characterCountText = "" + } else { + characterCountText = "\(text.count)c" + } + + imageButtonHidden = hidesImageButton + + switch imageState { + case .idle: + progressHidden = true + postButtonEnabled = text.count > 0 || numberOfImages > 0 + imageButtonEnabled = true + case .uploading(let progress): + postButtonEnabled = false + imageButtonEnabled = false + progressHidden = false + self.progress = progress + } + } +} + +struct ComposeKeyboardInputView: View { + @ObservedObject private var viewModel: ComposeKeyboardInputViewModel + + var didPressLinkButton: (() -> Void)? + var didPressImageButton: (() -> Void)? + var didPressCancelButton: (() -> Void)? + var didPressPostButton: (() -> Void)? + + init(viewModel: ComposeKeyboardInputViewModel) { + self.viewModel = viewModel + } + + var body: some View { + HStack { + Button(action: { + didPressLinkButton?() + }, label: { + HStack { + Text("KEYBOARDINPUTVIEW_LINKBUTTON_TTILE") + .foregroundColor(Color(uiColor: Style.Color.accent)) + } + }) + .tint(Color(uiColor: Style.Color.buttonColor)) + .buttonStyle(.borderedProminent) + if !viewModel.imageButtonHidden { + Button(action: { + didPressImageButton?() + }, label: { + HStack { + Text("KEYBOARDINPUTVIEW_IMAGEBUTTON_TITLE") + .foregroundColor(Color(uiColor: Style.Color.accent)) + } + }) + .tint(Color(uiColor: Style.Color.buttonColor)) + .buttonStyle(.borderedProminent) + .disabled(!viewModel.imageButtonEnabled) + } + Spacer() + if !viewModel.progressHidden { + ProgressView(value: viewModel.progress, total: 1) + Button { + didPressCancelButton?() + } label: { + Image("cancel", bundle: nil) + } + } + + Spacer() + Text(viewModel.characterCountText) + .foregroundColor(Color(uiColor: Style.Color.secondaryTextColor)) + .font(.footnote) + Button(action: { + didPressPostButton?() + }, label: { + HStack { + Text("KEYBOARDINPUTVIEW_POSTBUTTON_TITLE") + .foregroundColor(Color(uiColor: Style.Color.main)) + .fontWeight(.medium) + } + }) + .tint(Color(uiColor: Style.Color.buttonColor)) + .buttonStyle(.borderedProminent) + .disabled(!viewModel.postButtonEnabled) + } + .padding(6.0) + .background(Color(uiColor: Style.Color.accentLight)) + } +} + +struct ComposeKeyboardInputView_Previews: PreviewProvider { + static var previews: some View { + let viewModel = ComposeKeyboardInputViewModel() + + let view = ComposeKeyboardInputView(viewModel: viewModel) + viewModel.update( + for: "Hi123", + numberOfImages: 1, + imageState: .uploading(progress: 0.5), + hidesImageButton: false + ) + return view + } +} diff --git a/IcroUIKit/View/KeyboardInputView.swift b/IcroUIKit/View/KeyboardInputView.swift deleted file mode 100644 index 41685222..00000000 --- a/IcroUIKit/View/KeyboardInputView.swift +++ /dev/null @@ -1,81 +0,0 @@ -// -// Created by martin on 01.05.18. -// Copyright © 2018 Martin Hartl. All rights reserved. -// - -import UIKit -import Style - -final class KeyboardInputView: UIView { - private var text: String? { - didSet { - guard let text = text, text.count > 0 else { - characterCountLabel.text = "" - return - } - - characterCountLabel.text = "\(text.count)c" - } - } - - @IBOutlet weak var postButton: UIButton! { - didSet { - postButton.backgroundColor = Color.buttonColor - } - } - - @IBOutlet weak var linkButton: UIButton! { - didSet { - linkButton.backgroundColor = Color.buttonColor - } - } - - @IBOutlet weak var imageButton: UIButton! { - didSet { - imageButton.backgroundColor = Color.buttonColor - } - } - - @IBOutlet weak var cancelButton: UIButton! - @IBOutlet weak var progressView: UIProgressView! - - @IBOutlet private weak var characterCountLabel: UILabel! { - didSet { - characterCountLabel.textColor = Color.secondaryTextColor - } - } - - class func instanceFromNib() -> KeyboardInputView { - let nib = UINib(nibName: "KeyboardInputView", bundle: Bundle(for: KeyboardInputView.self)) - // swiftlint:disable force_cast - return nib.instantiate(withOwner: nil, options: nil)[0] as! KeyboardInputView - } - - override func awakeFromNib() { - super.awakeFromNib() - backgroundColor = Color.accentSuperLight - text = nil - linkButton.setTitle(localizedString(key: "KEYBOARDINPUTVIEW_LINKBUTTON_TTILE"), for: .normal) - imageButton.setTitle(localizedString(key: "KEYBOARDINPUTVIEW_IMAGEBUTTON_TITLE"), for: .normal) - postButton.setTitle(localizedString(key: "KEYBOARDINPUTVIEW_POSTBUTTON_TITLE"), for: .normal) - update(for: "", numberOfImages: 0, imageState: .idle) - } - - func update(for text: String, numberOfImages: Int, imageState: ImageState) { - self.text = text - - switch imageState { - case .idle: - cancelButton.isHidden = true - progressView.isHidden = true - postButton.isEnabled = text.count > 0 || numberOfImages > 0 - imageButton.isEnabled = true - case .uploading(let progress): - postButton.isEnabled = false - imageButton.isEnabled = false - cancelButton.isHidden = false - progressView.isHidden = false - progressView.progress = progress - } - } -} diff --git a/IcroUIKit/View/KeyboardInputView.xib b/IcroUIKit/View/KeyboardInputView.xib deleted file mode 100644 index d71eef2f..00000000 --- a/IcroUIKit/View/KeyboardInputView.xib +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/IcroUIKit/ViewController/ComposeViewController.swift b/IcroUIKit/ViewController/ComposeViewController.swift index ae44e787..89eafb83 100644 --- a/IcroUIKit/ViewController/ComposeViewController.swift +++ b/IcroUIKit/ViewController/ComposeViewController.swift @@ -6,6 +6,7 @@ import UIKit import MobileCoreServices import Style +import SwiftUI import Kingfisher import Sourceful import UniformTypeIdentifiers @@ -22,9 +23,11 @@ public final class ComposeViewController: UIViewController, LoadingViewControlle private let viewModel: ComposeViewModel private let composeNavigator: ComposeNavigatorProtocol + private var composeKeyboardInputViewModel: ComposeKeyboardInputViewModel? + private var keyboardInputViewController: UIHostingController? + private var cancelButton: UIBarButtonItem? private let itemNavigator: ItemNavigatorProtocol - private let keyboardInputView = KeyboardInputView.instanceFromNib() @IBOutlet weak var scrollView: UIScrollView! @IBOutlet private weak var tableView: UITableView! { didSet { @@ -62,30 +65,39 @@ public final class ComposeViewController: UIViewController, LoadingViewControlle self.viewModel = viewModel self.composeNavigator = composeNavigator self.itemNavigator = itemNavigator + super.init(nibName: "ComposeViewController", bundle: Bundle(for: ComposeViewController.self)) + + let composeKeyboardInputViewModel = ComposeKeyboardInputViewModel() + var composeKeyboardInputView = ComposeKeyboardInputView(viewModel: composeKeyboardInputViewModel) + self.composeKeyboardInputViewModel = composeKeyboardInputViewModel + composeKeyboardInputView.didPressPostButton = post + composeKeyboardInputView.didPressLinkButton = insertLink + composeKeyboardInputView.didPressImageButton = insertImage + composeKeyboardInputView.didPressCancelButton = canelImageUpload + self.keyboardInputViewController = UIHostingController(rootView: composeKeyboardInputView) + title = localizedString(key: "COMPOSEVIEWCONTROLLER_TITLE") cancelButton = UIBarButtonItem(title: localizedString(key: "COMPOSEVIEWCONTROLLER_CANCELBUTTON_TITLE"), style: .plain, target: self, action: #selector(cancel)) let sendButton = UIBarButtonItem(title: localizedString(key: "KEYBOARDINPUTVIEW_POSTBUTTON_TITLE"), style: .plain, target: self, action: #selector(post)) - keyboardInputView.postButton.addTarget(self, action: #selector(post), for: .touchUpInside) - keyboardInputView.linkButton.addTarget(self, action: #selector(insertLink), for: .touchUpInside) - keyboardInputView.imageButton.addTarget(self, action: #selector(insertImage), for: .touchUpInside) - keyboardInputView.cancelButton.addTarget(self, action: #selector(canelImageUpload), for: .touchUpInside) viewModel.didUpdateImages = { [weak self] in guard let strongSelf = self else { return } strongSelf.updateImageCollection() - strongSelf.keyboardInputView.update(for: strongSelf.syntaxView.text, - numberOfImages: strongSelf.viewModel.numberOfImages, - imageState: strongSelf.viewModel.imageState) + strongSelf.composeKeyboardInputViewModel?.update(for: strongSelf.syntaxView.text, + numberOfImages: strongSelf.viewModel.numberOfImages, + imageState: strongSelf.viewModel.imageState, + hidesImageButton: !viewModel.imageUploadEnabled) } viewModel.didChangeImageState = { [weak self] imageState in guard let strongSelf = self else { return } - strongSelf.keyboardInputView.update(for: strongSelf.syntaxView.text, - numberOfImages: strongSelf.viewModel.numberOfImages, - imageState: strongSelf.viewModel.imageState) + strongSelf.composeKeyboardInputViewModel?.update(for: strongSelf.syntaxView.text, + numberOfImages: strongSelf.viewModel.numberOfImages, + imageState: strongSelf.viewModel.imageState, + hidesImageButton: !viewModel.imageUploadEnabled) } navigationItem.leftBarButtonItem = cancelButton @@ -128,12 +140,21 @@ public final class ComposeViewController: UIViewController, LoadingViewControlle // MARK: - Private private func setupKeyboardInputView() { - keyboardInputView.update(for: viewModel.startText, - numberOfImages: viewModel.numberOfImages, - imageState: viewModel.imageState) - keyboardInputView.backgroundColor = Color.accentSuperLight - keyboardInputView.translatesAutoresizingMaskIntoConstraints = false - keyboardInputView.addConstraint(NSLayoutConstraint(item: keyboardInputView, + guard let composeKeyboardInputViewModel = composeKeyboardInputViewModel, let keyboardInputViewController = keyboardInputViewController else { + return + } + + composeKeyboardInputViewModel.update( + for: viewModel.startText, + numberOfImages: viewModel.numberOfImages, + imageState: viewModel.imageState, + hidesImageButton: !viewModel.imageUploadEnabled + ) + addChild(keyboardInputViewController) + view.addSubview(keyboardInputViewController.view) + keyboardInputViewController.didMove(toParent: self) + keyboardInputViewController.view.translatesAutoresizingMaskIntoConstraints = false + keyboardInputViewController.view.addConstraint(NSLayoutConstraint(item: keyboardInputViewController.view!, attribute: .height, relatedBy: .equal, toItem: nil, @@ -141,13 +162,11 @@ public final class ComposeViewController: UIViewController, LoadingViewControlle multiplier: 1, constant: Constants.KeyboardInputViewHeight)) - keyboardInputView.imageButton.isHidden = !viewModel.canUploadImage - - view.addSubview(keyboardInputView) + view.addSubview(keyboardInputViewController.view) if let layoutGuide = layoutGuide { - keyboardInputView.bottomAnchor.constraint(equalTo: layoutGuide.topGuide.topAnchor).isActive = true - keyboardInputView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true - keyboardInputView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true + keyboardInputViewController.view.bottomAnchor.constraint(equalTo: layoutGuide.topGuide.topAnchor).isActive = true + keyboardInputViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true + keyboardInputViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true } } @@ -185,7 +204,7 @@ public final class ComposeViewController: UIViewController, LoadingViewControlle @objc private func insertImage() { syntaxView.resignFirstResponder() - composeNavigator.openImageInsertion(sourceView: keyboardInputView.imageButton, imageInsertion: { [weak self] image in + composeNavigator.openImageInsertion(sourceView: keyboardInputViewController?.view ?? view, imageInsertion: { [weak self] image in self?.viewModel.insertImage(image: image) }, imageUpload: { [weak self] image in self?.viewModel.upload(image: image) @@ -198,7 +217,7 @@ public final class ComposeViewController: UIViewController, LoadingViewControlle private func setButtonState(enabled: Bool) { cancelButton?.isEnabled = enabled - keyboardInputView.postButton.isEnabled = enabled + composeKeyboardInputViewModel?.postButtonEnabled = enabled } private func updateImageCollection() { @@ -298,6 +317,9 @@ extension ComposeViewController: SyntaxTextViewDelegate { } public func didChangeText(_ syntaxTextView: SyntaxTextView) { - keyboardInputView.update(for: syntaxTextView.text, numberOfImages: viewModel.numberOfImages, imageState: viewModel.imageState) + composeKeyboardInputViewModel?.update(for: syntaxTextView.text, + numberOfImages: viewModel.numberOfImages, + imageState: viewModel.imageState, + hidesImageButton: !viewModel.imageUploadEnabled) } } diff --git a/IcroUIKit/ViewController/ComposeViewController.xib b/IcroUIKit/ViewController/ComposeViewController.xib index 09885630..da2175f7 100644 --- a/IcroUIKit/ViewController/ComposeViewController.xib +++ b/IcroUIKit/ViewController/ComposeViewController.xib @@ -1,14 +1,15 @@ - + - + + - + @@ -40,7 +41,7 @@ - + @@ -89,6 +90,7 @@ + @@ -96,7 +98,6 @@ - @@ -104,5 +105,8 @@ + + +