mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(searchbar): isEnabled and isUserInteractionEnabled (#6636)
This commit is contained in:
committed by
Dimitar Topuzov
parent
7a04a4d0bc
commit
25c99d8f71
@@ -1,7 +1,8 @@
|
||||
import { Font } from "../styling/font";
|
||||
import {
|
||||
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
|
||||
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty, fontSizeProperty
|
||||
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty, fontSizeProperty,
|
||||
isEnabledProperty, isUserInteractionEnabledProperty
|
||||
} from "./search-bar-common";
|
||||
import { ad } from "../../utils/utils";
|
||||
|
||||
@@ -76,6 +77,33 @@ function initializeNativeClasses(): void {
|
||||
CloseListener = CompatCloseListenerImpl;
|
||||
}
|
||||
|
||||
function enableSearchView(nativeView: any, value: boolean) {
|
||||
nativeView.setEnabled(value);
|
||||
|
||||
if (!(nativeView instanceof android.view.ViewGroup)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < nativeView.getChildCount(); i++) {
|
||||
let child = nativeView.getChildAt(i);
|
||||
enableSearchView(child, value);
|
||||
}
|
||||
}
|
||||
|
||||
function enableUserInteractionSearchView(nativeView: any, value: boolean) {
|
||||
nativeView.setClickable(value);
|
||||
nativeView.setFocusable(value);
|
||||
|
||||
if (!(nativeView instanceof android.view.ViewGroup)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < nativeView.getChildCount(); i++) {
|
||||
let child = nativeView.getChildAt(i);
|
||||
enableUserInteractionSearchView(child, value);
|
||||
}
|
||||
}
|
||||
|
||||
export class SearchBar extends SearchBarBase {
|
||||
nativeViewProtected: android.support.v7.widget.SearchView;
|
||||
private _searchTextView: android.widget.TextView;
|
||||
@@ -122,6 +150,14 @@ export class SearchBar extends SearchBarBase {
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
[isEnabledProperty.setNative](value: boolean) {
|
||||
enableSearchView(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[isUserInteractionEnabledProperty.setNative](value: boolean) {
|
||||
enableUserInteractionSearchView(this.nativeViewProtected, value);
|
||||
}
|
||||
|
||||
[backgroundColorProperty.getDefault](): number {
|
||||
// TODO: Why do we get DrawingCacheBackgroundColor but set backgroundColor?????
|
||||
const result = this.nativeViewProtected.getDrawingCacheBackgroundColor();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Font } from "../styling/font";
|
||||
import {
|
||||
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
|
||||
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty
|
||||
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty, isEnabledProperty
|
||||
} from "./search-bar-common";
|
||||
import { ios as iosUtils } from "../../utils/utils";
|
||||
|
||||
@@ -123,6 +123,18 @@ export class SearchBar extends SearchBarBase {
|
||||
return this.__placeholderLabel;
|
||||
}
|
||||
|
||||
[isEnabledProperty.setNative](value: boolean) {
|
||||
const nativeView = this.nativeViewProtected;
|
||||
if (nativeView instanceof UIControl) {
|
||||
nativeView.enabled = value;
|
||||
}
|
||||
|
||||
const textField = this._textField;
|
||||
if (textField) {
|
||||
textField.enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
[backgroundColorProperty.getDefault](): UIColor {
|
||||
return this.ios.barTintColor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user