@@ -19,35 +19,33 @@ public struct SIWA: View {
1919
2020 private let button : UIControl
2121
22- public init ( button: UIControl = ASAuthorizationAppleIDButton ( type: . default, style: . whiteOutline) , result: @escaping ( Result < Credential , Error > ) -> Void ) {
22+ public init (
23+ button: UIControl = ASAuthorizationAppleIDButton ( type: . default, style: . whiteOutline) ,
24+ result: @escaping ( Result < Credential , Error > ) -> Void
25+ ) {
2326 self . button = button
2427 self . result = result
2528 }
2629
2730 public var body : some View {
28- let controller = Controller ( credentialResult: result, button: button)
29- return controller
30- . frame ( width: controller. button. frame. width, height: controller. button. frame. height, alignment: . center)
31+ Controller ( credentialResult: result, button: button)
3132 }
3233
33- private struct Controller : UIViewControllerRepresentable {
34+ private struct Controller : UIViewRepresentable {
3435
3536 let credentialResult : ( Result < Credential , Error > ) -> Void
3637
3738 let button : UIControl
3839
39- let vc : UIViewController = UIViewController ( )
40-
4140 func makeCoordinator( ) -> Coordinator {
42- return Coordinator ( self )
41+ Coordinator ( self )
4342 }
4443
45- func makeUIViewController( context: Context ) -> UIViewController {
46- vc. view. addSubview ( button)
47- return vc
44+ func makeUIView( context: Context ) -> UIControl {
45+ button
4846 }
4947
50- func updateUIViewController ( _ uiViewController : UIViewController , context: Context ) { }
48+ func updateUIView ( _ uiView : UIControl , context: UIViewRepresentableContext < SIWA . Controller > ) { }
5149
5250 final class Coordinator : NSObject , ASAuthorizationControllerDelegate , ASAuthorizationControllerPresentationContextProviding {
5351
@@ -75,7 +73,7 @@ public struct SIWA: View {
7573 }
7674
7775 func presentationAnchor( for controller: ASAuthorizationController ) -> ASPresentationAnchor {
78- parent. vc . view . window!
76+ parent. button . window!
7977 }
8078
8179 func authorizationController( controller: ASAuthorizationController , didCompleteWithAuthorization authorization: ASAuthorization ) {
@@ -145,4 +143,13 @@ public struct SIWA: View {
145143 }
146144 }
147145}
146+
147+ @available ( iOS 13 , * )
148+ struct SIWA_Previews : PreviewProvider {
149+ static var previews : some View {
150+ SIWA ( ) { _ in }
151+ . frame ( width: 200 , height: 40 , alignment: . center)
152+ }
153+ }
154+
148155#endif
0 commit comments