From 25c99d8f7188af5d50e4920e4ca3f1e961cb1bcc Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Thu, 29 Nov 2018 11:18:14 +0200 Subject: [PATCH] fix(searchbar): isEnabled and isUserInteractionEnabled (#6636) --- .../ui/search-bar/search-bar.android.ts | 38 ++++++++++++++++++- .../ui/search-bar/search-bar.ios.ts | 14 ++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/tns-core-modules/ui/search-bar/search-bar.android.ts b/tns-core-modules/ui/search-bar/search-bar.android.ts index cb95c547c..c059dee02 100644 --- a/tns-core-modules/ui/search-bar/search-bar.android.ts +++ b/tns-core-modules/ui/search-bar/search-bar.android.ts @@ -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(); diff --git a/tns-core-modules/ui/search-bar/search-bar.ios.ts b/tns-core-modules/ui/search-bar/search-bar.ios.ts index 2b85cb710..b32de5320 100644 --- a/tns-core-modules/ui/search-bar/search-bar.ios.ts +++ b/tns-core-modules/ui/search-bar/search-bar.ios.ts @@ -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; }