-
Notifications
You must be signed in to change notification settings - Fork 76
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
SwiftUI support #202
Comments
@morizmartiner We'll have to investigate more but we currently don't have plans to support SwiftUI. Based on the screenshot, it looks like the background of the Drop-in view is showing but not the subviews. |
@morizmartiner It might make sense to use a You could try something like this: struct ContentView: View {
let token = "tokenization-key"
@State var showDropIn = false
var body: some View {
ZStack {
Button(action: {
self.showDropIn = true
}) {
// configure button with text, etc.
}
if self.showDropIn {
BTDropInRepresentable(authorization: token, handler: { controller, result, error in
// check for error or result
// send tokenized payment method to your server
self.showDropIn = false
}).edgesIgnoringSafeArea(.vertical)
}
}
}
} While I was trying this out, I noticed that this condition in |
Thanks you so much, it worked! |
General information
Hi all, in my app DropIn UI not show subviews. I used as reference the braintree-ios-drop-in-swiftui-demo. As you can see in image below the BTDropInController is showed but without subviews. DropInRepresentable import SwiftUI
import BraintreeDropIn
struct DropInRepresentable: UIViewControllerRepresentable {
var authorization: String
var handler: BTDropInControllerHandler
init(authorization: String, handler: @escaping BTDropInControllerHandler) {
self.authorization = authorization
self.handler = handler
}
func makeUIViewController(context: Context) -> BTDropInController {
let request = BTDropInRequest()
//request.payPalRequest = payPalRequest
//request.applePayDisabled = true
let dropInController = BTDropInController(authorization: authorization, request: request, handler: handler)!
return dropInController
}
func updateUIViewController(_ uiViewController: BTDropInController, context: UIViewControllerRepresentableContext<DropInRepresentable>) {
}
} ContentView VStack {
//.........
Group {
HStack {
Button(action: {
self.showDropIn = true
}) {
HStack {
Spacer()
Text("Checkout")
.fontWeight(.bold)
.font(.body)
Spacer()
}
.padding(.vertical, 12)
.foregroundColor(.white)
.background(Color.blue)
}
}
}.disabled(self.clientToken.client_token.isEmpty)
if self.showDropIn {
DropInRepresentable(authorization: self.clientToken.client_token, handler: { controller, result, error in
if let error = error {
print("Error: \(error.localizedDescription)")
} else if let result = result, result.isCancelled {
print("Cancelled🎲")
} else {
print("Ready for checkout...")
}
self.showDropIn = false
}).edgesIgnoringSafeArea(.vertical)
}
} Any ideas on that? Surely the mistake is under my nose... 😟 |
Hello @hevelius. In Susan's comment above - she points out a bug in our SDK that was causing the modal to be empty. We have a PR out for this fix that we will include in our next release of the SDK. I will close this issue once that fix is released. |
Can someone release a new version of the library that includes the swiftui support? I would love to start using it. |
Fixed in 8.1.1 |
General information
Issue description
I am trying to set up payment with Braintree, but Braintree does not yet support SwiftUI so I have to integrate it with UIKit. I created a wrapper using
UIViewControllerRepresentable
and I am presenting it as a modal using thesheet
function; however, it does not work as expected, it seems it is opening two modals.The screen when I open the modal:
Here's my wrapper:
Here is where I am trying to open the modal:
Does anyone have experience with Braintree in SwiftUI or with a similar situation? Am I doing something wrong or forgetting something?
I know writing my own views for Braintree checkout is an option, but I'd like to avoid that.
Thanks!
The text was updated successfully, but these errors were encountered: