11import { SwitchBase , checkedProperty , offBackgroundColorProperty } from './switch-common' ;
22import { colorProperty , backgroundColorProperty , backgroundInternalProperty } from '../styling/style-properties' ;
33import { Color } from '../../color' ;
4- import { iOSNativeHelper , layout } from '../../utils' ;
4+ import { SDK_VERSION } from '../../utils/constants ' ;
55
66export * from './switch-common' ;
77
8- const majorVersion = iOSNativeHelper . MajorVersion ;
9-
108@NativeClass
119class SwitchChangeHandlerImpl extends NSObject {
1210 private _owner : WeakRef < Switch > ;
@@ -30,7 +28,6 @@ class SwitchChangeHandlerImpl extends NSObject {
3028 } ;
3129}
3230
33- const zeroSize = { width : 0 , height : 0 } ;
3431export class Switch extends SwitchBase {
3532 nativeViewProtected : UISwitch ;
3633 private _handler : NSObject ;
@@ -48,11 +45,6 @@ export class Switch extends SwitchBase {
4845 const nativeView = this . nativeViewProtected ;
4946 this . _handler = SwitchChangeHandlerImpl . initWithOwner ( new WeakRef ( this ) ) ;
5047 nativeView . addTargetActionForControlEvents ( this . _handler , 'valueChanged' , UIControlEvents . ValueChanged ) ;
51-
52- // Set proper dimensions based on actual native size (important for iOS 26+ switches)
53- const nativeSize = nativeView . sizeThatFits ( zeroSize ) ;
54- this . width = nativeSize . width ;
55- this . height = nativeSize . height ;
5648 }
5749
5850 public disposeNativeView ( ) {
@@ -78,7 +70,7 @@ export class Switch extends SwitchBase {
7870 // only add :checked pseudo handling on supported iOS versions
7971 // ios <13 works but causes glitchy animations when toggling
8072 // so we decided to keep the old behavior on older versions.
81- if ( majorVersion >= 13 ) {
73+ if ( SDK_VERSION >= 13 ) {
8274 super . _onCheckedPropertyChanged ( newValue ) ;
8375
8476 if ( this . offBackgroundColor ) {
@@ -96,18 +88,6 @@ export class Switch extends SwitchBase {
9688 return this . nativeViewProtected ;
9789 }
9890
99- public onMeasure ( widthMeasureSpec : number , heightMeasureSpec : number ) : void {
100- // Get actual native size - iOS 26+ switches have different dimensions than the legacy 51x31
101- const nativeSize = this . nativeViewProtected . sizeThatFits ( zeroSize ) ;
102- this . width = nativeSize . width ;
103- this . height = nativeSize . height ;
104-
105- // Use actual native dimensions instead of hardcoded fallback values
106- const widthAndState = Switch . resolveSizeAndState ( layout . toDevicePixels ( nativeSize . width ) , layout . toDevicePixels ( nativeSize . width ) , layout . EXACTLY , 0 ) ;
107- const heightAndState = Switch . resolveSizeAndState ( layout . toDevicePixels ( nativeSize . height ) , layout . toDevicePixels ( nativeSize . height ) , layout . EXACTLY , 0 ) ;
108- this . setMeasuredDimension ( widthAndState , heightAndState ) ;
109- }
110-
11191 [ checkedProperty . getDefault ] ( ) : boolean {
11292 return false ;
11393 }
@@ -134,7 +114,7 @@ export class Switch extends SwitchBase {
134114 return this . nativeViewProtected . onTintColor ;
135115 }
136116 [ backgroundColorProperty . setNative ] ( value : UIColor | Color ) {
137- if ( majorVersion >= 13 ) {
117+ if ( SDK_VERSION >= 13 ) {
138118 if ( ! this . offBackgroundColor || this . checked ) {
139119 this . setNativeBackgroundColor ( value ) ;
140120 }
@@ -155,7 +135,7 @@ export class Switch extends SwitchBase {
155135 return this . nativeViewProtected . backgroundColor ;
156136 }
157137 [ offBackgroundColorProperty . setNative ] ( value : Color | UIColor ) {
158- if ( majorVersion >= 13 ) {
138+ if ( SDK_VERSION >= 13 ) {
159139 if ( ! this . checked ) {
160140 this . setNativeBackgroundColor ( value ) ;
161141 }
0 commit comments