Skip to content

Commit

Permalink
[TextField#278] Make leftView and rightView scalable
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklyn-situmorang committed Nov 6, 2023
1 parent a5846c7 commit b169d8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public final class TextFieldUIView: UITextField {
}

@ScaledUIMetric private var height: CGFloat = 44
@ScaledUIMetric private var leftViewSize: CGFloat = .zero
@ScaledUIMetric private var rightViewSize: CGFloat = .zero

// MARK: - Initializers

Expand Down Expand Up @@ -139,13 +141,21 @@ public final class TextFieldUIView: UITextField {

public override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
var rect = super.rightViewRect(forBounds: bounds)
rect.origin.x -= self.viewModel.spacings.right
self.rightViewSize = rect.width
rect.origin.x = (rect.maxX - self.viewModel.spacings.right - self.rightViewSize)
rect.origin.y = bounds.size.height / 2 - self.rightViewSize / 2
rect.size.width = self.rightViewSize
rect.size.height = self.rightViewSize
return rect
}

public override func leftViewRect(forBounds bounds: CGRect) -> CGRect {
var rect = super.leftViewRect(forBounds: bounds)
self.leftViewSize = rect.width
rect.origin.x += self.viewModel.spacings.left
rect.origin.y = bounds.size.height / 2 - self.leftViewSize / 2
rect.size.width = self.leftViewSize
rect.size.height = self.leftViewSize
return rect
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ final class TextFieldComponentUIView: UIView {
self.vStack.addArrangedSubview(self.leftViewModeStackView)
self.vStack.addArrangedSubview(self.clearButtonModeStackView)
self.vStack.addArrangedSubview(self.standaloneTextFieldLabel)
// self.vStack.addArrangedSubview(self.textField)
self.vStack.addArrangedSubview(self.textField)
self.vStack.addArrangedSubview(self.addOnTextFieldLabel)
self.vStack.addArrangedSubview(self.addOnTextField)

Expand Down

0 comments on commit b169d8e

Please sign in to comment.