fix(searchbar): isEnabled and isUserInteractionEnabled (#6636)

This commit is contained in:
Manol Donev
2018-11-29 11:18:14 +02:00
committed by Dimitar Topuzov
parent 7a04a4d0bc
commit 25c99d8f71
2 changed files with 50 additions and 2 deletions

View File

@@ -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();

View File

@@ -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;
}