Root-vb / OTPFieldView

One Time Password View for iOS. Built in Swift 5
MIT License
218 stars 63 forks source link

SwiftUI Implementation #20

Open elai950 opened 3 years ago

elai950 commented 3 years ago

I'm trying to implement OTPFieldView Delegation with SwiftUI but no luck. Is there anyone who successfully implemented this repo?

My test:

import SwiftUI
import OTPFieldView

struct OTP: UIViewRepresentable{

    func makeUIView(context: Context) -> OTPFieldView{

        let otp = OTPFieldView()
        otp.fieldsCount = 6
        otp.displayType = .underlinedBottom
        otp.separatorSpace = 8
        otp.initializeUI()
        return otp
    }

    func updateUIView(_ uiView: OTPFieldView, context: Context){

    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    internal class Coordinator: OTPFieldViewDelegate{

        func shouldBecomeFirstResponderForOTP(otpTextFieldIndex index: Int) -> Bool {
            return true
        }

        func enteredOTP(otp: String) {
            print(otp)
        }

        func hasEnteredAllOTP(hasEnteredAll: Bool) -> Bool {
            return false
        }

        var parent: OTP

        init(_ parent: OTP){
            self.parent = parent
        }
    }
}
ParagDevac commented 2 years ago

Same happen with me . When i click on OTP field no keyboard open. Looks like not consider as textField.