Skip to content

Commit

Permalink
Replace KeyboardInputView with SwiftUI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
hartlco committed Dec 8, 2021
1 parent dabee4a commit 410a5c9
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 271 deletions.
18 changes: 6 additions & 12 deletions Icro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand All @@ -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 */; };
Expand Down Expand Up @@ -285,8 +283,6 @@
5B3C79C121C518B700F699B8 /* MainNavigator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainNavigator.swift; path = Navigator/MainNavigator.swift; sourceTree = "<group>"; };
5B3C79C521C51B4900F699B8 /* ItemNavigatorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemNavigatorProtocol.swift; sourceTree = "<group>"; };
5B3C79D521C52D2C00F699B8 /* KeyboardLayoutGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardLayoutGuide.swift; sourceTree = "<group>"; };
5B3F68762098BB8800A24983 /* KeyboardInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardInputView.swift; sourceTree = "<group>"; };
5B3F68782098BBA200A24983 /* KeyboardInputView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KeyboardInputView.xib; sourceTree = "<group>"; };
5B44C71620979CF20003B35D /* MuteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MuteViewModel.swift; path = ViewModel/MuteViewModel.swift; sourceTree = "<group>"; };
5B4639DC2168FE9B00200D8F /* TabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = "<group>"; };
5B4639DE216901BE00200D8F /* SplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -385,6 +381,7 @@
C550D7782740F0BC00E10CF6 /* Style */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Style; sourceTree = "<group>"; };
C550D77F2740F79000E10CF6 /* Font+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+Settings.swift"; sourceTree = "<group>"; };
C553DD5023F7CABC0001E7DF /* Client */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Client; sourceTree = "<group>"; };
C55BAF28275D489D009E8A9C /* ComposeKeyboardInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeKeyboardInputView.swift; sourceTree = "<group>"; };
C55D7AC523F7C756004E5DBB /* Icro.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Icro.xctestplan; sourceTree = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */,
);
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
9 changes: 0 additions & 9 deletions IcroKit/ViewModel/ComposeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
126 changes: 126 additions & 0 deletions IcroUIKit/View/ComposeKeyboardInputView.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
81 changes: 0 additions & 81 deletions IcroUIKit/View/KeyboardInputView.swift

This file was deleted.

Loading

0 comments on commit 410a5c9

Please sign in to comment.