Skip to content

Commit 25c99d8

Browse files
manoldonevdtopuzov
authored andcommitted
fix(searchbar): isEnabled and isUserInteractionEnabled (#6636)
1 parent 7a04a4d commit 25c99d8

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

tns-core-modules/ui/search-bar/search-bar.android.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Font } from "../styling/font";
22
import {
33
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
4-
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty, fontSizeProperty
4+
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty, fontSizeProperty,
5+
isEnabledProperty, isUserInteractionEnabledProperty
56
} from "./search-bar-common";
67
import { ad } from "../../utils/utils";
78

@@ -76,6 +77,33 @@ function initializeNativeClasses(): void {
7677
CloseListener = CompatCloseListenerImpl;
7778
}
7879

80+
function enableSearchView(nativeView: any, value: boolean) {
81+
nativeView.setEnabled(value);
82+
83+
if (!(nativeView instanceof android.view.ViewGroup)) {
84+
return;
85+
}
86+
87+
for (let i = 0; i < nativeView.getChildCount(); i++) {
88+
let child = nativeView.getChildAt(i);
89+
enableSearchView(child, value);
90+
}
91+
}
92+
93+
function enableUserInteractionSearchView(nativeView: any, value: boolean) {
94+
nativeView.setClickable(value);
95+
nativeView.setFocusable(value);
96+
97+
if (!(nativeView instanceof android.view.ViewGroup)) {
98+
return;
99+
}
100+
101+
for (let i = 0; i < nativeView.getChildCount(); i++) {
102+
let child = nativeView.getChildAt(i);
103+
enableUserInteractionSearchView(child, value);
104+
}
105+
}
106+
79107
export class SearchBar extends SearchBarBase {
80108
nativeViewProtected: android.support.v7.widget.SearchView;
81109
private _searchTextView: android.widget.TextView;
@@ -122,6 +150,14 @@ export class SearchBar extends SearchBarBase {
122150
super.disposeNativeView();
123151
}
124152

153+
[isEnabledProperty.setNative](value: boolean) {
154+
enableSearchView(this.nativeViewProtected, value);
155+
}
156+
157+
[isUserInteractionEnabledProperty.setNative](value: boolean) {
158+
enableUserInteractionSearchView(this.nativeViewProtected, value);
159+
}
160+
125161
[backgroundColorProperty.getDefault](): number {
126162
// TODO: Why do we get DrawingCacheBackgroundColor but set backgroundColor?????
127163
const result = this.nativeViewProtected.getDrawingCacheBackgroundColor();

tns-core-modules/ui/search-bar/search-bar.ios.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Font } from "../styling/font";
22
import {
33
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
4-
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty
4+
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty, isEnabledProperty
55
} from "./search-bar-common";
66
import { ios as iosUtils } from "../../utils/utils";
77

@@ -123,6 +123,18 @@ export class SearchBar extends SearchBarBase {
123123
return this.__placeholderLabel;
124124
}
125125

126+
[isEnabledProperty.setNative](value: boolean) {
127+
const nativeView = this.nativeViewProtected;
128+
if (nativeView instanceof UIControl) {
129+
nativeView.enabled = value;
130+
}
131+
132+
const textField = this._textField;
133+
if (textField) {
134+
textField.enabled = value;
135+
}
136+
}
137+
126138
[backgroundColorProperty.getDefault](): UIColor {
127139
return this.ios.barTintColor;
128140
}

0 commit comments

Comments
 (0)