Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this library with SwiftUI? #38

Open
bhavitha-fission opened this issue Mar 17, 2020 · 5 comments
Open

How to use this library with SwiftUI? #38

bhavitha-fission opened this issue Mar 17, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@bhavitha-fission
Copy link

How to use this library with SwiftUI?

@xornorik
Copy link
Owner

Hi @bhavitha-fission, I have yet to provide support for SwiftUI. Will work on this soon - please stay tuned. Thanks.

@xornorik xornorik self-assigned this Mar 28, 2020
@xornorik xornorik added the enhancement New feature or request label Mar 28, 2020
@ArkInnovationsPH
Copy link

+1 also need it in Swift UI

@bhavitha-fission
Copy link
Author

Hi @bhavitha-fission, I have yet to provide support for SwiftUI. Will work on this soon - please stay tuned. Thanks.

Hi, Any update on this?

@xornorik
Copy link
Owner

xornorik commented Apr 17, 2020

@bhavitha-fission I'm working on it. Will be a little while before I have this up and working on SwiftUI. Please stay tuned.

@codetanmoy
Copy link

codetanmoy commented Nov 3, 2020

import SwiftUI
import SVPinView
import UIKit

struct OTPWithKAPin: UIViewRepresentable {
var otpCode: String?
var numberofElement: Int = 6

var getotp : (_ code: String) -> ()

class Coordinator: NSObject {
    var parent: OTPWithKAPin

    init(_ parent: OTPWithKAPin) {
        self.parent = parent
    }

}

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


func makeUIView(context: Context) ->  SVPinView {
    let pinView:SVPinView = SVPinView()
    
    pinView.pinLength = numberofElement
    pinView.secureCharacter = "\u{25CF}"
    pinView.interSpace = CGFloat(numberofElement)
    pinView.textColor = UIColor.black
    pinView.shouldSecureText = true
    pinView.style = .underline

    pinView.borderLineColor = UIColor(named: "TintColor")!.withAlphaComponent(0.50)
    pinView.activeBorderLineColor = UIColor(named: "TintColor")!.withAlphaComponent(1.0)
    pinView.borderLineThickness = 1
    pinView.activeBorderLineThickness = 3

    pinView.font = UIFont.systemFont(ofSize: 15)
    pinView.keyboardType = .phonePad
    pinView.keyboardAppearance = .default
    pinView.placeholder = "******"
    pinView.isContentTypeOneTimeCode = true
    pinView.updateFocusIfNeeded()
    pinView.becomeFirstResponderAtIndex = 0
    
    
    pinView.didFinishCallback = {  pin in
        print("The pin entered is \(pin)")
    }
    
    pinView.didChangeCallback = { pin in
        self.getotp(pin)
    }
    
    return pinView
}

func updateUIView(_ uiView: SVPinView, context: Context) {
    
}

}

And use this with your swiftui

OTPWithKAPin(numberofElement: 4) { (pin) in
print(pin)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants