Skip to content

Commit

Permalink
Remove unused Bindings in RoundedBorderTextField/Editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Mar 24, 2022
1 parent 70d39ef commit d475c30
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 70 deletions.
38 changes: 10 additions & 28 deletions RiotSwiftUI/Modules/Common/Util/RoundedBorderTextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ struct RoundedBorderTextEditor: View {

// MARK: - Properties

var title: String?
var placeHolder: String
var title: String? = nil
let placeHolder: String
@Binding var text: String
var textMaxHeight: CGFloat?
@Binding var error: String?
var textMaxHeight: CGFloat? = nil
var error: String? = nil

var onTextChanged: ((String) -> Void)?
var onEditingChanged: ((Bool) -> Void)?
var onTextChanged: ((String) -> Void)? = nil
var onEditingChanged: ((Bool) -> Void)? = nil

@State private var editing = false

Expand All @@ -37,24 +37,6 @@ struct RoundedBorderTextEditor: View {
@Environment(\.theme) private var theme: ThemeSwiftUI
@Environment(\.isEnabled) private var isEnabled

// MARK: Setup

init(title: String? = nil,
placeHolder: String,
text: Binding<String>,
textMaxHeight: CGFloat? = nil,
error: Binding<String?> = .constant(nil),
onTextChanged: ((String) -> Void)? = nil,
onEditingChanged: ((Bool) -> Void)? = nil) {
self.title = title
self.placeHolder = placeHolder
self._text = text
self.textMaxHeight = textMaxHeight
self._error = error
self.onTextChanged = onTextChanged
self.onEditingChanged = onEditingChanged
}

// MARK: Public

var body: some View {
Expand Down Expand Up @@ -131,10 +113,10 @@ struct ThemableTextEditor_Previews: PreviewProvider {

static var sampleView: some View {
VStack(alignment: .center, spacing: 40) {
RoundedBorderTextEditor(title: "A title", placeHolder: "A placeholder", text: .constant(""), error: .constant(nil))
RoundedBorderTextEditor(placeHolder: "A placeholder", text: .constant("Some text"), error: .constant(nil))
RoundedBorderTextEditor(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), error: .constant("Some error text"))
RoundedBorderTextEditor(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), error: .constant("Some error text"))
RoundedBorderTextEditor(title: "A title", placeHolder: "A placeholder", text: .constant(""), error: nil)
RoundedBorderTextEditor(placeHolder: "A placeholder", text: .constant("Some text"), error: nil)
RoundedBorderTextEditor(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), error: "Some error text")
RoundedBorderTextEditor(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), error: "Some error text")
.disabled(true)
}
}
Expand Down
44 changes: 11 additions & 33 deletions RiotSwiftUI/Modules/Common/Util/RoundedBorderTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,24 @@ struct RoundedBorderTextField: View {

// MARK: - Properties

var title: String?
var placeHolder: String
var title: String? = nil
let placeHolder: String
@Binding var text: String
@Binding var footerText: String?
@Binding var isError: Bool
var footerText: String? = nil
var isError: Bool = false
var isFirstResponder = false

var configuration: UIKitTextInputConfiguration = UIKitTextInputConfiguration()

var onTextChanged: ((String) -> Void)?
var onEditingChanged: ((Bool) -> Void)?
var onTextChanged: ((String) -> Void)? = nil
var onEditingChanged: ((Bool) -> Void)? = nil

// MARK: Private

@State private var editing = false

@Environment(\.theme) private var theme: ThemeSwiftUI
@Environment(\.isEnabled) private var isEnabled

// MARK: Setup

init(title: String? = nil,
placeHolder: String,
text: Binding<String>,
footerText: Binding<String?> = .constant(nil),
isError: Binding<Bool> = .constant(false),
isFirstResponder: Bool = false,
configuration: UIKitTextInputConfiguration = UIKitTextInputConfiguration(),
onTextChanged: ((String) -> Void)? = nil,
onEditingChanged: ((Bool) -> Void)? = nil) {
self.title = title
self.placeHolder = placeHolder
self._text = text
self._footerText = footerText
self._isError = isError
self.isFirstResponder = isFirstResponder
self.configuration = configuration
self.onTextChanged = onTextChanged
self.onEditingChanged = onEditingChanged
}

// MARK: Public

Expand Down Expand Up @@ -139,11 +117,11 @@ struct TextFieldWithError_Previews: PreviewProvider {

static var sampleView: some View {
VStack(alignment: .center, spacing: 20) {
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant(""), footerText: .constant(nil), isError: .constant(false))
RoundedBorderTextField(placeHolder: "A placeholder", text: .constant("Some text"), footerText: .constant(nil), isError: .constant(false))
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), footerText: .constant("Some error text"), isError: .constant(true))
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), footerText: .constant("Some normal text"), isError: .constant(false))
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), footerText: .constant("Some normal text"), isError: .constant(false))
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant(""), footerText: nil, isError: false)
RoundedBorderTextField(placeHolder: "A placeholder", text: .constant("Some text"), footerText: nil, isError: false)
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), footerText: "Some error text", isError: true)
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), footerText: "Some normal text", isError: false)
RoundedBorderTextField(title: "A title", placeHolder: "A placeholder", text: .constant("Some very long text used to check overlapping with the delete button"), footerText: "Some normal text", isError: false)
.disabled(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct SpaceCreationEmailInvites: View {
VStack {
VStack(spacing: 20) {
ForEach(viewModel.emailInvites.indices) { index in
RoundedBorderTextField(title: VectorL10n.spacesCreationEmailInvitesEmailTitle, placeHolder: VectorL10n.spacesCreationEmailInvitesEmailTitle, text: $viewModel.emailInvites[index], footerText: .constant(viewModel.viewState.emailAddressesValid[index] ? nil : VectorL10n.authInvalidEmail), isError: .constant(!viewModel.viewState.emailAddressesValid[index]), configuration: UIKitTextInputConfiguration(keyboardType: .emailAddress, returnKeyType: index < viewModel.emailInvites.endIndex - 1 ? .next : .done, autocapitalizationType: .none, autocorrectionType: .no))
RoundedBorderTextField(title: VectorL10n.spacesCreationEmailInvitesEmailTitle, placeHolder: VectorL10n.spacesCreationEmailInvitesEmailTitle, text: $viewModel.emailInvites[index], footerText: viewModel.viewState.emailAddressesValid[index] ? nil : VectorL10n.authInvalidEmail, isError: !viewModel.viewState.emailAddressesValid[index], configuration: UIKitTextInputConfiguration(keyboardType: .emailAddress, returnKeyType: index < viewModel.emailInvites.endIndex - 1 ? .next : .done, autocapitalizationType: .none, autocorrectionType: .no))
.accessibility(identifier: "emailTextField")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ struct SpaceCreationSettings: View {
Spacer()
avatarView
Spacer().frame(height:40)
RoundedBorderTextField(title: VectorL10n.createRoomPlaceholderName, placeHolder: "", text: $viewModel.roomName, footerText: .constant(viewModel.viewState.roomNameError), isError: .constant(true), isFirstResponder: false, configuration: UIKitTextInputConfiguration( returnKeyType: .next), onTextChanged: { newText in
RoundedBorderTextField(title: VectorL10n.createRoomPlaceholderName, placeHolder: "", text: $viewModel.roomName, footerText: viewModel.viewState.roomNameError, isError: true, isFirstResponder: false, configuration: UIKitTextInputConfiguration( returnKeyType: .next), onTextChanged: { newText in
viewModel.send(viewAction: .nameChanged(newText))
})
.id("nameTextField")
.padding(.horizontal, 2)
.padding(.bottom, 20)
RoundedBorderTextEditor(title: nil, placeHolder: VectorL10n.spaceTopic, text: $viewModel.topic, textMaxHeight: 72, error: .constant(nil), onTextChanged: {
RoundedBorderTextEditor(title: nil, placeHolder: VectorL10n.spaceTopic, text: $viewModel.topic, textMaxHeight: 72, error: nil, onTextChanged: {
newText in
viewModel.send(viewAction: .topicChanged(newText))
}, onEditingChanged: { editing in
Expand All @@ -122,7 +122,7 @@ struct SpaceCreationSettings: View {
.padding(.horizontal, 2)
.padding(.bottom, viewModel.viewState.showRoomAddress ? 20 : 3)
if viewModel.viewState.showRoomAddress {
RoundedBorderTextField(title: VectorL10n.spacesCreationAddress, placeHolder: "# \(viewModel.viewState.defaultAddress)", text: $viewModel.address, footerText: .constant(viewModel.viewState.addressMessage), isError: .constant(!viewModel.viewState.isAddressValid), configuration: UIKitTextInputConfiguration(keyboardType: .URL, returnKeyType: .done, autocapitalizationType: .none), onTextChanged: {
RoundedBorderTextField(title: VectorL10n.spacesCreationAddress, placeHolder: "# \(viewModel.viewState.defaultAddress)", text: $viewModel.address, footerText: viewModel.viewState.addressMessage, isError: !viewModel.viewState.isAddressValid, configuration: UIKitTextInputConfiguration(keyboardType: .URL, returnKeyType: .done, autocapitalizationType: .none), onTextChanged: {
newText in
viewModel.send(viewAction: .addressChanged(newText))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ struct SpaceSettings: View {
title: VectorL10n.createRoomPlaceholderName,
placeHolder: "",
text: $viewModel.name,
footerText: .constant(viewModel.viewState.roomNameError),
isError: .constant(true),
footerText: viewModel.viewState.roomNameError,
isError: true,
configuration: UIKitTextInputConfiguration( returnKeyType: .next))
.padding(.horizontal, 2)
.padding(.bottom, 20)
Expand All @@ -127,7 +127,7 @@ struct SpaceSettings: View {
placeHolder: VectorL10n.spaceTopic,
text: $viewModel.topic,
textMaxHeight: 72,
error: .constant(nil))
error: nil)
.padding(.horizontal, 2)
.padding(.bottom, viewModel.viewState.showRoomAddress ? 20 : 3)
.disabled(viewModel.viewState.roomProperties?.isTopicEditable != true)
Expand All @@ -136,8 +136,8 @@ struct SpaceSettings: View {
title: VectorL10n.spacesCreationAddress,
placeHolder: "# \(viewModel.viewState.defaultAddress)",
text: $viewModel.address,
footerText: .constant(viewModel.viewState.addressMessage),
isError: .constant(!viewModel.viewState.isAddressValid),
footerText: viewModel.viewState.addressMessage,
isError: !viewModel.viewState.isAddressValid,
configuration: UIKitTextInputConfiguration(keyboardType: .URL, returnKeyType: .done, autocapitalizationType: .none), onTextChanged: {
newText in
viewModel.send(viewAction: .addressChanged(newText))
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-5910.api
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unused Bindings in RoundedBorderTextField/Editor

0 comments on commit d475c30

Please sign in to comment.