MojtabaHs / iPhoneNumberField

Elegant SwiftUI phone number textField.
MIT License
542 stars 88 forks source link

Enhancement: Added Insets Support. #87

Closed MussaCharles closed 1 year ago

MussaCharles commented 1 year ago

I have added support to forward paddings to the internally used PhoneNumberTextField.

To achieve this I had to add paddings support to the official PhoneNumberTextField which was recently merged and released with PhoneNumberKit version 3.6.6.

On iPhoneNumberField I have simply added the following two params: -

   private let insets: UIEdgeInsets
   private let clearButtonPadding: CGFloat

Initilized them with the following default values so that it doesn't break developers code.

  public init(
       insets: UIEdgeInsets = .zero,
       clearButtonPadding: CGFloat = 6
      // -- 
    )

and forward them to PhoneNumberKit as follows: -

 let uiView = UIViewType(insets: insets, clearButtonPadding: clearButtonPadding)

All other implementations details are handled on the latest version of PhoneNumberKit which have my suggested changes merged via my PR #669.

Since paddings support are available from version 3.6.6 of PhoneNumberKit I have changed the package dependency version as follows: -

// Package.swift
.package(url: "https://github.com/marmelroy/PhoneNumberKit", from: "3.6.6")

As an added benefit, I have also increased swift tools version to 5.7

// Package.swift
swift-tools-version:5.7

I'm looking forward to your feedback on this enhancement. I believe it's a valuable addition to the library, making it more versatile for usage in diverse design contexts. Please the sample below & the attached screenshot below:

struct MyView: View {

  // MARK: - Properties
 @Binding var directInputText: String
 @Binding var isEditing: Bool
 let placeHolderText: String = "Type something"

// MARK: - Body
var body: some View {
     iPhoneNumberField(
              // -- Other properties,
              insets: UIEdgeInsets(top: 14, left: 16, bottom: 14, right: 16)
            ) {
                $0.textColor = .label
                $0.numberPlaceholderColor = .label
          }
  }

}
Screenshot 2023-07-15 at 1 43 12 PM