UNPKG

4.03 kBJavaScriptView Raw
1import { SwitchBase, checkedProperty, offBackgroundColorProperty } from './switch-common';
2import { colorProperty, backgroundColorProperty, backgroundInternalProperty } from '../styling/style-properties';
3import { Color } from '../../color';
4import { AndroidHelper } from '../core/view';
5export * from './switch-common';
6let CheckedChangeListener;
7function initializeCheckedChangeListener() {
8 if (CheckedChangeListener) {
9 return;
10 }
11 var CheckedChangeListenerImpl = /** @class */ (function (_super) {
12 __extends(CheckedChangeListenerImpl, _super);
13 function CheckedChangeListenerImpl(owner) {
14 var _this = _super.call(this) || this;
15 _this.owner = owner;
16 return global.__native(_this);
17 }
18 CheckedChangeListenerImpl.prototype.onCheckedChanged = function (buttonView, isChecked) {
19 var owner = this.owner;
20 checkedProperty.nativeValueChange(owner, isChecked);
21 };
22 var _a;
23 CheckedChangeListenerImpl = __decorate([
24 Interfaces([android.widget.CompoundButton.OnCheckedChangeListener]),
25 __metadata("design:paramtypes", [typeof (_a = typeof Switch !== "undefined" && Switch) === "function" ? _a : Object])
26 ], CheckedChangeListenerImpl);
27 return CheckedChangeListenerImpl;
28}(java.lang.Object));
29 CheckedChangeListener = CheckedChangeListenerImpl;
30}
31export class Switch extends SwitchBase {
32 createNativeView() {
33 return new android.widget.Switch(this._context);
34 }
35 initNativeView() {
36 super.initNativeView();
37 const nativeView = this.nativeViewProtected;
38 initializeCheckedChangeListener();
39 const listener = new CheckedChangeListener(this);
40 nativeView.setOnCheckedChangeListener(listener);
41 nativeView.listener = listener;
42 }
43 disposeNativeView() {
44 const nativeView = this.nativeViewProtected;
45 if (nativeView.listener) {
46 nativeView.listener.owner = null;
47 }
48 super.disposeNativeView();
49 }
50 setNativeBackgroundColor(value) {
51 if (this.nativeViewProtected) {
52 const drawable = this.nativeViewProtected.getTrackDrawable();
53 if (value instanceof Color) {
54 AndroidHelper.setDrawableColor(value.android, drawable, androidx.core.graphics.BlendModeCompat.SRC_OVER);
55 }
56 else {
57 AndroidHelper.clearDrawableColor(drawable);
58 }
59 }
60 }
61 _onCheckedPropertyChanged(newValue) {
62 super._onCheckedPropertyChanged(newValue);
63 if (this.offBackgroundColor) {
64 if (!newValue) {
65 this.setNativeBackgroundColor(this.offBackgroundColor);
66 }
67 else {
68 this.setNativeBackgroundColor(this.backgroundColor);
69 }
70 }
71 }
72 [checkedProperty.getDefault]() {
73 return false;
74 }
75 [checkedProperty.setNative](value) {
76 this.nativeViewProtected.setChecked(value);
77 }
78 [colorProperty.getDefault]() {
79 return -1;
80 }
81 [colorProperty.setNative](value) {
82 const drawable = this.nativeViewProtected.getThumbDrawable();
83 if (value instanceof Color) {
84 AndroidHelper.setDrawableColor(value.android, drawable, androidx.core.graphics.BlendModeCompat.SRC_ATOP);
85 }
86 else {
87 AndroidHelper.clearDrawableColor(drawable);
88 }
89 }
90 [backgroundColorProperty.getDefault]() {
91 return -1;
92 }
93 [backgroundColorProperty.setNative](value) {
94 if (!this.offBackgroundColor || this.checked) {
95 this.setNativeBackgroundColor(value);
96 }
97 }
98 [backgroundInternalProperty.getDefault]() {
99 return null;
100 }
101 [backgroundInternalProperty.setNative](value) {
102 //
103 }
104 [offBackgroundColorProperty.getDefault]() {
105 return -1;
106 }
107 [offBackgroundColorProperty.setNative](value) {
108 if (!this.checked) {
109 this.setNativeBackgroundColor(value);
110 }
111 }
112}
113//# sourceMappingURL=index.android.js.map
\No newline at end of file