11import type { Point , Position } from './view-interfaces' ;
2- import { ViewCommon , isEnabledProperty , originXProperty , originYProperty , isUserInteractionEnabledProperty , testIDProperty , iosGlassEffectProperty , GlassEffectType , GlassEffectVariant , statusBarStyleProperty } from './view-common' ;
2+ import { ViewCommon , isEnabledProperty , originXProperty , originYProperty , isUserInteractionEnabledProperty , testIDProperty , iosGlassEffectProperty , GlassEffectType , GlassEffectVariant , GlassEffectConfig , statusBarStyleProperty } from './view-common' ;
33import { isAccessibilityServiceEnabled } from '../../../application' ;
44import { updateA11yPropertiesCallback } from '../../../application/helpers-common' ;
55import { ShowModalOptions , hiddenProperty } from '../view-base' ;
@@ -904,6 +904,62 @@ export class View extends ViewCommon {
904904 }
905905 }
906906
907+ protected _applyGlassEffect (
908+ value : GlassEffectType ,
909+ options : {
910+ effectType : 'glass' | 'container' ;
911+ targetView ?: UIVisualEffectView ;
912+ toGlassStyleFn ?: ( variant ?: GlassEffectVariant ) => number ;
913+ onCreate ?: ( effectView : UIVisualEffectView , effect : UIVisualEffect ) => void ;
914+ onUpdate ?: ( effectView : UIVisualEffectView , effect : UIVisualEffect , duration : number ) => void ;
915+ } ,
916+ ) : UIVisualEffectView | undefined {
917+ const config : GlassEffectConfig | null = typeof value !== 'string' ? value : null ;
918+ const variant = config ? config . variant : ( value as GlassEffectVariant ) ;
919+ const defaultDuration = 0.3 ;
920+ const duration = config ? ( config . animateChangeDuration ?? defaultDuration ) : defaultDuration ;
921+
922+ let effect : UIGlassEffect | UIGlassContainerEffect | UIVisualEffect ;
923+
924+ // Create the appropriate effect based on type and variant
925+ if ( ! value || [ 'identity' , 'none' ] . includes ( variant ) ) {
926+ effect = UIVisualEffect . new ( ) ;
927+ } else {
928+ if ( options . effectType === 'glass' ) {
929+ const styleFn = options . toGlassStyleFn || this . toUIGlassStyle . bind ( this ) ;
930+ effect = UIGlassEffect . effectWithStyle ( styleFn ( variant ) ) ;
931+ if ( config ) {
932+ ( effect as UIGlassEffect ) . interactive = ! ! config . interactive ;
933+ if ( config . tint ) {
934+ ( effect as UIGlassEffect ) . tintColor = typeof config . tint === 'string' ? new Color ( config . tint ) . ios : config . tint ;
935+ }
936+ }
937+ } else if ( options . effectType === 'container' ) {
938+ effect = UIGlassContainerEffect . alloc ( ) . init ( ) ;
939+ ( effect as UIGlassContainerEffect ) . spacing = config ?. spacing ?? 8 ;
940+ }
941+ }
942+
943+ // Handle creating new effect view or updating existing one
944+ if ( options . targetView ) {
945+ // Update existing effect view
946+ if ( options . onUpdate ) {
947+ options . onUpdate ( options . targetView , effect , duration ) ;
948+ } else {
949+ // Default update behavior: animate effect changes
950+ UIView . animateWithDurationAnimations ( duration , ( ) => {
951+ options . targetView . effect = effect ;
952+ } ) ;
953+ }
954+ return undefined ;
955+ } else if ( options . onCreate ) {
956+ // Create new effect view and let caller handle setup
957+ const effectView = UIVisualEffectView . alloc ( ) . initWithEffect ( effect ) ;
958+ options . onCreate ( effectView , effect ) ;
959+ return effectView ;
960+ }
961+ return undefined ;
962+ }
907963 [ statusBarStyleProperty . getDefault ] ( ) {
908964 return this . style . statusBarStyle ;
909965 }
@@ -929,45 +985,37 @@ export class View extends ViewCommon {
929985 if ( ! this . nativeViewProtected || ! supportsGlass ( ) ) {
930986 return ;
931987 }
932- if ( this . _glassEffectView ) {
933- this . _glassEffectView . removeFromSuperview ( ) ;
934- this . _glassEffectView = null ;
935- }
936- if ( ! value ) {
937- return ;
938- }
939- let effect : UIGlassEffect ;
940- if ( typeof value === 'string' ) {
941- effect = UIGlassEffect . effectWithStyle ( this . toUIGlassStyle ( value ) ) ;
988+
989+ if ( ! this . _glassEffectView ) {
990+ // Create new glass effect view
991+ this . _glassEffectView = this . _applyGlassEffect ( value , {
992+ effectType : 'glass' ,
993+ onCreate : ( effectView , effect ) => {
994+ // let touches pass to content
995+ effectView . userInteractionEnabled = false ;
996+ effectView . clipsToBounds = true ;
997+ // size & autoresize
998+ if ( this . _glassEffectMeasure ) {
999+ clearTimeout ( this . _glassEffectMeasure ) ;
1000+ }
1001+ this . _glassEffectMeasure = setTimeout ( ( ) => {
1002+ const size = this . nativeViewProtected . bounds . size ;
1003+ effectView . frame = CGRectMake ( 0 , 0 , size . width , size . height ) ;
1004+ effectView . autoresizingMask = 2 ;
1005+ this . nativeViewProtected . insertSubviewAtIndex ( effectView , 0 ) ;
1006+ } ) ;
1007+ } ,
1008+ } ) ;
9421009 } else {
943- if ( value . variant === 'identity' ) {
944- return ;
945- }
946- effect = UIGlassEffect . effectWithStyle ( this . toUIGlassStyle ( value . variant ) ) ;
947- if ( value . interactive ) {
948- effect . interactive = true ;
949- }
950- if ( value . tint ) {
951- effect . tintColor = typeof value . tint === 'string' ? new Color ( value . tint ) . ios : value . tint ;
952- }
1010+ // Update existing glass effect view
1011+ this . _applyGlassEffect ( value , {
1012+ effectType : 'glass' ,
1013+ targetView : this . _glassEffectView ,
1014+ } ) ;
9531015 }
954- this . _glassEffectView = UIVisualEffectView . alloc ( ) . initWithEffect ( effect ) ;
955- // let touches pass to content
956- this . _glassEffectView . userInteractionEnabled = false ;
957- this . _glassEffectView . clipsToBounds = true ;
958- // size & autoresize
959- if ( this . _glassEffectMeasure ) {
960- clearTimeout ( this . _glassEffectMeasure ) ;
961- }
962- this . _glassEffectMeasure = setTimeout ( ( ) => {
963- const size = this . nativeViewProtected . bounds . size ;
964- this . _glassEffectView . frame = CGRectMake ( 0 , 0 , size . width , size . height ) ;
965- this . _glassEffectView . autoresizingMask = 2 ;
966- this . nativeViewProtected . insertSubviewAtIndex ( this . _glassEffectView , 0 ) ;
967- } ) ;
9681016 }
9691017
970- public toUIGlassStyle ( value ?: GlassEffectVariant ) {
1018+ toUIGlassStyle ( value ?: GlassEffectVariant ) {
9711019 if ( supportsGlass ( ) ) {
9721020 switch ( value ) {
9731021 case 'regular' :
0 commit comments