1 import AuthenticationServices 2 import ABI49_0_0ExpoModulesCore 3 4 public final class AppleAuthenticationButton: ExpoView { 5 let onButtonPress = EventDispatcher() 6 7 var type: ButtonType = .signIn 8 var style: ButtonStyle = .white 9 var childView: ASAuthorizationAppleIDButton? 10 11 var needsUpdate = true 12 13 var cornerRadius: Double = 0.0 { 14 didSet { 15 childView?.cornerRadius = cornerRadius 16 } 17 } 18 updateChildIfNeedednull19 func updateChildIfNeeded() { 20 guard needsUpdate else { 21 return 22 } 23 unmountChild() 24 mountNewChild() 25 needsUpdate = false 26 } 27 mountNewChildnull28 private func mountNewChild() { 29 let newChildView = ASAuthorizationAppleIDButton( 30 authorizationButtonType: type.toAppleAuthButtonType(), 31 authorizationButtonStyle: style.toAppleAuthButtonStyle() 32 ) 33 34 newChildView.cornerRadius = cornerRadius 35 newChildView.translatesAutoresizingMaskIntoConstraints = false 36 newChildView.addTarget(self, action: #selector(onTouchUp), for: .touchUpInside) 37 38 addSubview(newChildView) 39 childView = newChildView 40 41 NSLayoutConstraint.activate([ 42 newChildView.topAnchor.constraint(equalTo: self.topAnchor), 43 newChildView.bottomAnchor.constraint(equalTo: self.bottomAnchor), 44 newChildView.leadingAnchor.constraint(equalTo: self.leadingAnchor), 45 newChildView.trailingAnchor.constraint(equalTo: self.trailingAnchor) 46 ]) 47 } 48 unmountChildnull49 private func unmountChild() { 50 childView?.removeTarget(self, action: #selector(onTouchUp), for: .touchUpInside) 51 childView?.removeFromSuperview() 52 childView = nil 53 } 54 55 @objc onTouchUpnull56 private func onTouchUp() { 57 onButtonPress() 58 } 59 } 60