Skip to content

SwiftUI Implementation #20

@elai950

Description

@elai950

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
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions