@@ -72,6 +72,51 @@ interface DialogOptions {
7272 dismissCallback : ( ) => void ;
7373}
7474
75+ let OnBackPressedCallback ;
76+
77+ if ( SDK_VERSION >= 33 ) {
78+ OnBackPressedCallback = ( androidx . activity . OnBackPressedCallback as any ) . extend ( {
79+ handleOnBackPressed ( ) {
80+ console . log ( 'OnBackPressedCallback handleOnBackPressed called' ) ;
81+ const dialog = this [ '_dialog' ] ?. get ( ) ;
82+
83+ if ( ! dialog ) {
84+ // disable the callback and call super to avoid infinite loop
85+
86+ this . setEnabled ( false ) ;
87+
88+ return ;
89+ }
90+
91+ const view = dialog . fragment . owner ;
92+
93+ const args : AndroidActivityBackPressedEventData = {
94+ eventName : 'activityBackPressed' ,
95+ object : view ,
96+ activity : view . _context ,
97+ cancel : false ,
98+ } ;
99+
100+ // Fist fire application.android global event
101+ getNativeScriptGlobals ( ) . events . notify ( args ) ;
102+
103+ if ( args . cancel ) {
104+ return ;
105+ }
106+
107+ view . notify ( args ) ;
108+
109+ if ( ! args . cancel ) {
110+ this . setEnabled ( false ) ;
111+
112+ dialog . getOnBackPressedDispatcher ( ) . onBackPressed ( ) ;
113+
114+ this . setEnabled ( true ) ;
115+ }
116+ } ,
117+ } ) ;
118+ }
119+
75120interface TouchListener {
76121 new ( owner : View ) : android . view . View . OnTouchListener ;
77122}
@@ -121,14 +166,24 @@ function initializeDialogFragment() {
121166 }
122167
123168 @NativeClass
124- class DialogImpl extends android . app . Dialog {
169+ class DialogImpl extends androidx . appcompat . app . AppCompatDialog {
125170 constructor (
126171 public fragment : DialogFragmentImpl ,
127172 context : android . content . Context ,
128173 themeResId : number ,
129174 ) {
130175 super ( context , themeResId ) ;
131176
177+ if ( SDK_VERSION >= 33 && OnBackPressedCallback ) {
178+ const callback = new OnBackPressedCallback ( true ) ;
179+
180+ callback [ '_dialog' ] = new WeakRef ( this ) ;
181+
182+ // @ts -ignore
183+
184+ this . getOnBackPressedDispatcher ( ) . addCallback ( this , callback ) ;
185+ }
186+
132187 return global . __native ( this ) ;
133188 }
134189
@@ -138,6 +193,10 @@ function initializeDialogFragment() {
138193 }
139194
140195 public onBackPressed ( ) : void {
196+ if ( SDK_VERSION >= 33 ) {
197+ super . onBackPressed ( ) ;
198+ return ;
199+ }
141200 const view = this . fragment . owner ;
142201 const args = < AndroidActivityBackPressedEventData > {
143202 eventName : 'activityBackPressed' ,
@@ -1448,17 +1507,23 @@ export class View extends ViewCommon {
14481507 }
14491508 }
14501509
1451- protected _drawBoxShadow ( boxShadow : BoxShadow ) {
1510+ protected _drawBoxShadow ( boxShadows : BoxShadow [ ] ) {
14521511 const nativeView = this . nativeViewProtected ;
1453- const config = {
1454- shadowColor : boxShadow . color . android ,
1455- cornerRadius : Length . toDevicePixels ( this . borderRadius as CoreTypes . LengthType , 0.0 ) ,
1456- spreadRadius : boxShadow . spreadRadius ,
1457- blurRadius : boxShadow . blurRadius ,
1458- offsetX : boxShadow . offsetX ,
1459- offsetY : boxShadow . offsetY ,
1460- } ;
1461- org . nativescript . widgets . Utils . drawBoxShadow ( nativeView , JSON . stringify ( config ) ) ;
1512+ const valueCount = 6 ;
1513+ const nativeArray : number [ ] = Array . create ( 'int' , boxShadows . length * valueCount ) ;
1514+
1515+ for ( let i = 0 , length = boxShadows . length ; i < length ; i ++ ) {
1516+ const boxShadow = boxShadows [ i ] ;
1517+ const nativeIndex = i * valueCount ;
1518+
1519+ nativeArray [ nativeIndex + 0 ] = boxShadow . color . android ;
1520+ nativeArray [ nativeIndex + 1 ] = boxShadow . spreadRadius ;
1521+ nativeArray [ nativeIndex + 2 ] = boxShadow . blurRadius ;
1522+ nativeArray [ nativeIndex + 3 ] = boxShadow . offsetX ;
1523+ nativeArray [ nativeIndex + 4 ] = boxShadow . offsetY ;
1524+ nativeArray [ nativeIndex + 5 ] = boxShadow . inset ? 1 : 0 ;
1525+ }
1526+ org . nativescript . widgets . Utils . drawBoxShadow ( nativeView , nativeArray ) ;
14621527 }
14631528
14641529 _redrawNativeBackground ( value : android . graphics . drawable . Drawable | Background ) : void {
@@ -1507,15 +1572,15 @@ export class View extends ViewCommon {
15071572 // prettier-ignore
15081573 const onlyColor = ! background . hasBorderWidth ( )
15091574 && ! background . hasBorderRadius ( )
1510- && ! background . hasBoxShadow ( )
1575+ && ! background . hasBoxShadows ( )
15111576 && ! background . clipPath
15121577 && ! background . image
15131578 && ! ! background . color ;
15141579
15151580 this . _applyBackground ( background , isBorderDrawable , onlyColor , drawable ) ;
15161581
1517- if ( background . hasBoxShadow ( ) ) {
1518- this . _drawBoxShadow ( background . getBoxShadow ( ) ) ;
1582+ if ( background . hasBoxShadows ( ) ) {
1583+ this . _drawBoxShadow ( background . getBoxShadows ( ) ) ;
15191584 }
15201585
15211586 // TODO: Can we move BorderWidths as separate native setter?
0 commit comments