Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions iBox/Sources/BoxList/AddBookmark/AddBookmarkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class AddBookmarkView: UIView {
$0.autocorrectionType = .no
}

private let clearButton = UIButton().then {
$0.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
$0.tintColor = .systemGray3
$0.isHidden = true
}

private let separatorView = UIView().then {
$0.backgroundColor = .systemGray3
}
Expand Down Expand Up @@ -111,6 +117,7 @@ class AddBookmarkView: UIView {
private func setupProperty() {
backgroundColor = .systemGroupedBackground
updateTextFieldWithIncomingData()
clearButton.addTarget(self, action: #selector(clearTextView), for: .touchUpInside)
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
nameTextView.delegate = self
urlTextView.delegate = self
Expand All @@ -119,6 +126,7 @@ class AddBookmarkView: UIView {
private func setupHierarchy() {
addSubview(textFieldView)
addSubview(nameTextView)
addSubview(clearButton)
addSubview(separatorView)
addSubview(urlTextView)
addSubview(nameTextViewPlaceHolder)
Expand Down Expand Up @@ -150,6 +158,11 @@ class AddBookmarkView: UIView {
make.leading.equalTo(nameTextView.snp.leading).offset(5)
}

clearButton.snp.makeConstraints { make in
make.top.equalTo(nameTextView.snp.top).offset(7)
make.trailing.equalTo(nameTextView.snp.trailing).offset(-5)
}

separatorView.snp.makeConstraints { make in
make.top.equalTo(nameTextView.snp.bottom).offset(10)
make.leading.equalTo(nameTextView.snp.leading).offset(5)
Expand Down Expand Up @@ -202,9 +215,15 @@ class AddBookmarkView: UIView {
if let data = data, !data.isEmpty {
textField.text = data
placeholder.isHidden = true
if textField == nameTextView {
clearButton.isHidden = false
}
} else {
textField.text = ""
placeholder.isHidden = false
if textField == nameTextView {
clearButton.isHidden = true
}
}
}

Expand All @@ -221,6 +240,11 @@ class AddBookmarkView: UIView {
onTextChange?(isBothTextViewsFilled)
}

@objc func clearTextView() {
nameTextView.text = ""
textViewDidChange(nameTextView)
}

@objc private func buttonTapped() {
onButtonTapped?()
}
Expand Down Expand Up @@ -255,6 +279,7 @@ extension AddBookmarkView: UITextViewDelegate {

if textView == nameTextView {
nameTextViewPlaceHolder.isHidden = !nameTextView.text.isEmpty
clearButton.isHidden = nameTextView.text.isEmpty
}

if textView == urlTextView {
Expand Down