@@ -41,20 +41,20 @@ function isString(value): value is string {
41
41
42
42
function createAlertDialogBuilder ( options ?: DialogOptions & MDCAlertControlerOptions ) : androidx . appcompat . app . AlertDialog . Builder {
43
43
const activity = androidApp . foregroundActivity || ( androidApp . startActivity as globalAndroid . app . Activity ) ;
44
- const alert = new androidx . appcompat . app . AlertDialog . Builder ( activity ) ;
45
- alert . setTitle ( options && isString ( options . title ) ? options . title : null ) ;
46
- alert . setMessage ( options && isString ( options . message ) ? options . message : null ) ;
44
+ const builder = new androidx . appcompat . app . AlertDialog . Builder ( activity ) ;
45
+ builder . setTitle ( options && isString ( options . title ) ? options . title : null ) ;
46
+ builder . setMessage ( options && isString ( options . message ) ? options . message : null ) ;
47
47
if ( options . titleIcon ) {
48
- alert . setIcon ( options . titleIcon . android ) ;
48
+ builder . setIcon ( options . titleIcon . android ) ;
49
49
}
50
50
if ( options && options . cancelable === false ) {
51
- alert . setCancelable ( false ) ;
51
+ builder . setCancelable ( false ) ;
52
52
}
53
53
if ( options . titleIcon ) {
54
- alert . setIcon ( options . titleIcon . android ) ;
54
+ builder . setIcon ( options . titleIcon . android ) ;
55
55
}
56
56
if ( options . customTitleView ) {
57
- alert . setCustomTitle ( options . customTitleView . nativeViewProtected ) ;
57
+ builder . setCustomTitle ( options . customTitleView . nativeViewProtected ) ;
58
58
}
59
59
if ( options . view ) {
60
60
const view =
@@ -68,32 +68,20 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
68
68
const modalRootViewCssClasses = getSystemCssClasses ( ) ;
69
69
modalRootViewCssClasses . forEach ( ( c ) => view . cssClasses . add ( c ) ) ;
70
70
71
- ( activity as any ) . _currentModalCustomView = view ;
71
+ ( builder as any ) . _currentModalCustomView = view ;
72
72
view . _setupAsRootView ( activity ) ;
73
73
view . _isAddedToNativeVisualTree = true ;
74
74
view . callLoaded ( ) ;
75
75
76
76
// seems necessary to add a frame or the view wont correctly size itself
77
77
const frame = new android . widget . FrameLayout ( activity ) ;
78
78
frame . addView ( view . nativeViewProtected ) ;
79
- alert . setView ( frame ) ;
79
+ builder . setView ( frame ) ;
80
80
}
81
- return alert ;
81
+ return builder ;
82
82
}
83
83
84
84
function showDialog ( dlg : androidx . appcompat . app . AlertDialog , options : DialogOptions & MDCAlertControlerOptions , resolve ?: Function ) {
85
- const activity = androidApp . foregroundActivity || ( androidApp . startActivity as globalAndroid . app . Activity ) ;
86
- if ( ( activity as any ) . _currentModalCustomView ) {
87
- const view = ( activity as any ) . _currentModalCustomView as View ;
88
- const context = options . context || { } ;
89
- context . closeCallback = function ( ...originalArgs ) {
90
- dlg . dismiss ( ) ;
91
- if ( resolve ) {
92
- resolve . apply ( this , originalArgs ) ;
93
- }
94
- } ;
95
- view . bindingContext = fromObject ( context ) ;
96
- }
97
85
if ( options . titleColor ) {
98
86
const textViewId = dlg . getContext ( ) . getResources ( ) . getIdentifier ( 'android:id/alertTitle' , null , null ) ;
99
87
if ( textViewId ) {
@@ -185,12 +173,12 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
185
173
new android . content . DialogInterface . OnDismissListener ( {
186
174
onDismiss : function ( ) {
187
175
onDone ( false ) ;
188
- if ( ( activity as any ) . _currentModalCustomView ) {
189
- const view = ( activity as any ) . _currentModalCustomView ;
176
+ if ( ( builder as any ) . _currentModalCustomView ) {
177
+ const view = ( builder as any ) . _currentModalCustomView ;
190
178
view . callUnloaded ( ) ;
191
179
view . _tearDownUI ( true ) ;
192
180
view . _isAddedToNativeVisualTree = false ;
193
- ( activity as any ) . _currentModalCustomView = null ;
181
+ ( builder as any ) . _currentModalCustomView = null ;
194
182
}
195
183
} ,
196
184
} )
@@ -199,6 +187,17 @@ function prepareAndCreateAlertDialog(builder: androidx.appcompat.app.AlertDialog
199
187
if ( ! options ) {
200
188
return dlg ;
201
189
}
190
+ if ( ( builder as any ) . _currentModalCustomView ) {
191
+ const view = ( builder as any ) . _currentModalCustomView as View ;
192
+ const context = options . context || { } ;
193
+ context . closeCallback = function ( ...originalArgs ) {
194
+ dlg . dismiss ( ) ;
195
+ if ( callback ) {
196
+ callback . apply ( this , originalArgs ) ;
197
+ }
198
+ } ;
199
+ view . bindingContext = fromObject ( context ) ;
200
+ }
202
201
203
202
if ( options . okButtonText ) {
204
203
dlg . setButton (
@@ -287,22 +286,8 @@ export class AlertDialog {
287
286
show ( ) {
288
287
if ( ! this . dialog ) {
289
288
const alert = createAlertDialogBuilder ( this . options ) ;
290
-
291
- const activity = androidApp . foregroundActivity || ( androidApp . startActivity as globalAndroid . app . Activity ) ;
292
- alert . setOnDismissListener (
293
- new android . content . DialogInterface . OnDismissListener ( {
294
- onDismiss : function ( ) {
295
- if ( ( activity as any ) . _currentModalCustomView ) {
296
- const view = ( activity as any ) . _currentModalCustomView ;
297
- view . callUnloaded ( ) ;
298
- view . _tearDownUI ( true ) ;
299
- view . _isAddedToNativeVisualTree = false ;
300
- ( activity as any ) . _currentModalCustomView = null ;
301
- }
302
- } ,
303
- } )
304
- ) ;
305
289
this . dialog = alert . create ( ) ;
290
+ this . dialog = prepareAndCreateAlertDialog ( alert , this . options , null ) ;
306
291
showDialog ( this . dialog , this . options ) ;
307
292
}
308
293
}
0 commit comments