@@ -68,138 +68,139 @@ if (ios.MajorVersion >= 13) {
6868 protocols . push ( ASWebAuthenticationPresentationContextProviding ) ;
6969}
7070
71- const InAppBrowser = ( < any > NSObject ) . extend ( {
72- safariVC : < SFSafariViewController > null ,
73- redirectResolve : null ,
74- redirectReject : null ,
75- authSession : < SFAuthenticationSession | ASWebAuthenticationSession > null ,
76- animated : false ,
77- isAvailable ( ) : Promise < boolean > {
71+ class InAppBrowserModule extends NSObject {
72+
73+ public static ObjCProtocols = protocols ;
74+
75+ private safariVC : SFSafariViewController = null ;
76+ private redirectResolve = null ;
77+ private redirectReject = null ;
78+ private authSession : SFAuthenticationSession | ASWebAuthenticationSession = null ;
79+ private animated = false ;
80+
81+ public isAvailable ( ) : Promise < boolean > {
7882 return Promise . resolve ( ios . MajorVersion >= 9 ) ;
79- } ,
80- open ( authURL : string , inAppBrowserOptions : InAppBrowserOptions = { } ) : Promise < BrowserResult > {
81- const self = this ;
82- return new Promise ( function ( resolve , reject ) {
83- if ( ! self . initializeWebBrowser ( resolve , reject ) ) return ;
83+ }
84+ public open ( authURL : string , inAppBrowserOptions : InAppBrowserOptions = { } ) : Promise < BrowserResult > {
85+ return new Promise ( ( resolve , reject ) => {
86+ if ( ! this . initializeWebBrowser ( resolve , reject ) ) return ;
8487
8588 const options : InAppBrowserOptions = getDefaultOptions ( authURL , inAppBrowserOptions ) ;
86- self . animated = options . animated ;
89+ this . animated = options . animated ;
8790
8891 const url = NSURL . URLWithString ( options [ 'url' ] ) ;
8992 if ( ios . MajorVersion >= 11 ) {
9093 const config = SFSafariViewControllerConfiguration . alloc ( ) . init ( ) ;
9194 config . barCollapsingEnabled = options . enableBarCollapsing ;
9295 config . entersReaderIfAvailable = options . readerMode ;
93- self . safariVC = SFSafariViewController . alloc ( ) . initWithURLConfiguration ( url , config ) ;
96+ this . safariVC = SFSafariViewController . alloc ( ) . initWithURLConfiguration ( url , config ) ;
9497 } else {
95- self . safariVC = SFSafariViewController . alloc ( ) . initWithURLEntersReaderIfAvailable (
98+ this . safariVC = SFSafariViewController . alloc ( ) . initWithURLEntersReaderIfAvailable (
9699 url ,
97100 options . readerMode
98101 ) ;
99102 }
100- self . safariVC . delegate = self ;
103+ this . safariVC . delegate = this ;
101104
102105 if ( ios . MajorVersion >= 11 ) {
103106 if ( options . dismissButtonStyle === 'done' ) {
104- self . safariVC . dismissButtonStyle = SFSafariViewControllerDismissButtonStyle . Done ;
107+ this . safariVC . dismissButtonStyle = SFSafariViewControllerDismissButtonStyle . Done ;
105108 }
106109 else if ( options . dismissButtonStyle === 'close' ) {
107- self . safariVC . dismissButtonStyle = SFSafariViewControllerDismissButtonStyle . Close ;
110+ this . safariVC . dismissButtonStyle = SFSafariViewControllerDismissButtonStyle . Close ;
108111 }
109112 else if ( options . dismissButtonStyle === 'cancel' ) {
110- self . safariVC . dismissButtonStyle = SFSafariViewControllerDismissButtonStyle . Cancel ;
113+ this . safariVC . dismissButtonStyle = SFSafariViewControllerDismissButtonStyle . Cancel ;
111114 }
112115 }
113116
114117 if ( ios . MajorVersion >= 10 ) {
115118 if ( options . preferredBarTintColor ) {
116- self . safariVC . preferredBarTintColor = new Color ( options . preferredBarTintColor ) . ios ;
119+ this . safariVC . preferredBarTintColor = new Color ( options . preferredBarTintColor ) . ios ;
117120 }
118121 if ( options . preferredControlTintColor ) {
119- self . safariVC . preferredControlTintColor = new Color ( options . preferredControlTintColor ) . ios ;
122+ this . safariVC . preferredControlTintColor = new Color ( options . preferredControlTintColor ) . ios ;
120123 }
121124 }
122125
123126 const ctrl = UIApplication . sharedApplication . keyWindow . rootViewController ;
124127
125128 if ( options . modalEnabled ) {
126129 // This is a hack to present the SafariViewController modally
127- const safariHackVC = UINavigationController . alloc ( ) . initWithRootViewController ( self . safariVC ) ;
130+ const safariHackVC = UINavigationController . alloc ( ) . initWithRootViewController ( this . safariVC ) ;
128131 safariHackVC . setNavigationBarHiddenAnimated ( true , false ) ;
129132 safariHackVC . modalPresentationStyle = getPresentationStyle ( options . modalPresentationStyle ) ;
130- if ( self . animated ) {
133+ if ( this . animated ) {
131134 safariHackVC . modalTransitionStyle = getTransitionStyle ( options . modalTransitionStyle ) ;
132135 }
133136 if ( ios . MajorVersion >= 13 ) {
134137 safariHackVC . modalInPresentation = true ;
135138 }
136- safariHackVC . presentationController . delegate = self ;
139+ safariHackVC . presentationController . delegate = this ;
137140
138141 ctrl . presentViewControllerAnimatedCompletion ( safariHackVC , options . animated , null ) ;
139142 }
140143 else {
141- ctrl . presentViewControllerAnimatedCompletion ( self . safariVC , options . animated , null ) ;
144+ ctrl . presentViewControllerAnimatedCompletion ( this . safariVC , options . animated , null ) ;
142145 }
143146 } ) ;
144- } ,
145- close ( ) {
146- const self = this ;
147+ }
148+ public close ( ) {
147149 const ctrl = UIApplication . sharedApplication . keyWindow . rootViewController ;
148- ctrl . dismissViewControllerAnimatedCompletion ( self . animated , function ( ) {
149- if ( self . redirectResolve ) {
150- self . redirectResolve ( {
150+ ctrl . dismissViewControllerAnimatedCompletion ( this . animated , ( ) => {
151+ if ( this . redirectResolve ) {
152+ this . redirectResolve ( {
151153 type : 'dismiss'
152154 } ) ;
153- self . flowDidFinish ( ) ;
155+ this . flowDidFinish ( ) ;
154156 }
155157 } ) ;
156- } ,
157- async openAuth (
158+ }
159+ public async openAuth (
158160 authUrl : string ,
159161 redirectUrl : string
160162 ) : Promise < AuthSessionResult > {
161- const self = this ;
162163 if ( ios . MajorVersion >= 11 ) {
163- return new Promise < AuthSessionResult > ( function ( resolve , reject ) {
164- if ( ! self . initializeWebBrowser ( resolve , reject ) ) return ;
164+ return new Promise < AuthSessionResult > ( ( resolve , reject ) => {
165+ if ( ! this . initializeWebBrowser ( resolve , reject ) ) return ;
165166
166167 const url = NSURL . URLWithString ( authUrl ) ;
167- self . authSession = (
168+ this . authSession = (
168169 ios . MajorVersion >= 12 ? ASWebAuthenticationSession : SFAuthenticationSession
169170 ) . alloc ( ) . initWithURLCallbackURLSchemeCompletionHandler (
170171 url ,
171172 redirectUrl ,
172- function ( callbackURL , error ) {
173+ ( callbackURL , error ) => {
173174 if ( ! error ) {
174- self . redirectResolve ( {
175+ this . redirectResolve ( {
175176 type : 'success' ,
176177 url : callbackURL . absoluteString
177178 } ) ;
178179 }
179180 else {
180- self . redirectResolve ( {
181+ this . redirectResolve ( {
181182 type : 'cancel'
182183 } ) ;
183184 }
184- self . flowDidFinish ( ) ;
185+ this . flowDidFinish ( ) ;
185186 }
186187 ) ;
187188 if ( ios . MajorVersion >= 13 ) {
188- self . authSession . presentationContextProvider = self ;
189+ this . authSession [ ' presentationContextProvider' ] = this ;
189190 }
190- self . authSession . start ( ) ;
191+ this . authSession . start ( ) ;
191192 } ) ;
192193 }
193194 else {
194- self . flowDidFinish ( ) ;
195+ this . flowDidFinish ( ) ;
195196 const response : AuthSessionResult = {
196197 type : 'cancel' ,
197198 message : 'openAuth requires iOS 11 or greater'
198199 } ;
199200 return Promise . resolve ( response ) ;
200201 }
201- } ,
202- closeAuth ( ) {
202+ }
203+ public closeAuth ( ) {
203204 if ( ios . MajorVersion >= 11 ) {
204205 const authSession : SFAuthenticationSession | ASWebAuthenticationSession = this . authSession ;
205206 authSession . cancel ( ) ;
@@ -213,11 +214,11 @@ const InAppBrowser = (<any>NSObject).extend({
213214 else {
214215 this . close ( ) ;
215216 }
216- } ,
217- presentationAnchorForWebAuthenticationSession : function ( session : ASWebAuthenticationSession ) : UIWindow {
217+ }
218+ public presentationAnchorForWebAuthenticationSession ( session : ASWebAuthenticationSession ) : UIWindow {
218219 return UIApplication . sharedApplication . keyWindow ;
219- } ,
220- dismissWithoutAnimation ( controller : SFSafariViewController ) : void {
220+ }
221+ private dismissWithoutAnimation ( controller : SFSafariViewController ) : void {
221222 const transition = CATransition . animation ( ) ;
222223 transition . duration = 0 ;
223224 transition . timingFunction = CAMediaTimingFunction . functionWithName ( kCAMediaTimingFunctionLinear ) ;
@@ -233,8 +234,8 @@ const InAppBrowser = (<any>NSObject).extend({
233234 ctrl . dismissViewControllerAnimatedCompletion ( false , ( ) => {
234235 ctrl . view . layer . removeAnimationForKey ( animationKey ) ;
235236 } ) ;
236- } ,
237- safariViewControllerDidFinish (
237+ }
238+ public safariViewControllerDidFinish (
238239 controller : SFSafariViewController
239240 ) : void {
240241 if ( ! this . animated ) {
@@ -246,14 +247,14 @@ const InAppBrowser = (<any>NSObject).extend({
246247 } ) ;
247248 this . flowDidFinish ( ) ;
248249 }
249- } ,
250-
251- flowDidFinish ( ) {
250+ }
251+ private flowDidFinish ( ) {
252252 this . safariVC = null ;
253253 this . redirectResolve = null ;
254254 this . redirectReject = null ;
255- } ,
256- initializeWebBrowser ( resolve , reject ) : boolean {
255+ }
256+
257+ private initializeWebBrowser ( resolve , reject ) {
257258 if ( this . redirectResolve ) {
258259 reject ( 'Another InAppBrowser is already being presented.' ) ;
259260 return false ;
@@ -262,8 +263,6 @@ const InAppBrowser = (<any>NSObject).extend({
262263 this . redirectReject = reject ;
263264 return true ;
264265 }
265- } , {
266- protocols : protocols
267- } ) ;
266+ }
268267
269- export default InAppBrowser . new ( ) ;
268+ export default InAppBrowserModule . new ( ) ;
0 commit comments