valueForKey("_searchField") replaced

This commit is contained in:
Vladimir Enchev
2015-08-13 11:40:30 +03:00
parent ef6b73a4a5
commit 6a42e6019c
3 changed files with 30 additions and 32 deletions

View File

@@ -6,8 +6,7 @@ export function getNativeHintColor(searchBar: searchBarModule.SearchBar): colorM
return undefined; return undefined;
} }
export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number { export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number {
var bar = <UISearchBar>searchBar.ios; var sf = <UITextField>(<any>searchBar)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
return sf.font.pointSize; return sf.font.pointSize;
} }

View File

@@ -14,7 +14,7 @@ function onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) { function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var bar = <SearchBar>data.object; var bar = <SearchBar>data.object;
if (data.newValue instanceof color.Color) { if (data.newValue instanceof color.Color) {
var tf = getUITextField(bar.ios); var tf = (<any>bar)._textField;
if (tf) { if (tf) {
tf.backgroundColor = data.newValue.ios; tf.backgroundColor = data.newValue.ios;
} }
@@ -52,14 +52,6 @@ function onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
(<proxy.PropertyMetadata>common.SearchBar.hintProperty.metadata).onSetNativeValue = onHintPropertyChanged; (<proxy.PropertyMetadata>common.SearchBar.hintProperty.metadata).onSetNativeValue = onHintPropertyChanged;
function getUITextField(bar: UISearchBar): UITextField {
if (bar) {
return <UITextField> bar.valueForKey("_searchField");
}
return undefined;
}
global.moduleMerge(common, exports); global.moduleMerge(common, exports);
class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate { class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
@@ -102,9 +94,11 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
export class SearchBar extends common.SearchBar { export class SearchBar extends common.SearchBar {
private _ios: UISearchBar; private _ios: UISearchBar;
private _delegate; private _delegate;
public _textField: UITextField;
constructor() { constructor() {
super(); super();
this._ios = new UISearchBar(); this._ios = new UISearchBar();
this._delegate = UISearchBarDelegateImpl.new().initWithOwner(this); this._delegate = UISearchBarDelegateImpl.new().initWithOwner(this);
@@ -113,6 +107,7 @@ export class SearchBar extends common.SearchBar {
public onLoaded() { public onLoaded() {
super.onLoaded(); super.onLoaded();
this._ios.delegate = this._delegate; this._ios.delegate = this._delegate;
this._textField = SearchBar.findTextField(this.ios);
} }
public onUnloaded() { public onUnloaded() {
@@ -123,4 +118,17 @@ export class SearchBar extends common.SearchBar {
get ios(): UISearchBar { get ios(): UISearchBar {
return this._ios; return this._ios;
} }
private static findTextField(view: UIView) {
for (let i = 0, l = view.subviews.count; i < l; i++) {
let v: UIView = view.subviews[i];
if (v instanceof UITextField) {
return v;
} else if (v.subviews.count > 0) {
return SearchBar.findTextField(v);
}
}
return undefined;
}
} }

View File

@@ -409,9 +409,7 @@ export class SearchBarStyler implements definition.stylers.Styler {
} }
private static getColorProperty(view: view.View): any { private static getColorProperty(view: view.View): any {
var bar = <UISearchBar>view.ios; var sf = <UITextField>(<any>view)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
return sf.textColor; return sf.textColor;
} }
@@ -420,18 +418,14 @@ export class SearchBarStyler implements definition.stylers.Styler {
} }
private static setColorProperty(view: view.View, newValue: any) { private static setColorProperty(view: view.View, newValue: any) {
var bar = <UISearchBar>view.ios; var sf = <UITextField>(<any>view)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
sf.textColor = newValue; sf.textColor = newValue;
} }
} }
private static resetColorProperty(view: view.View, nativeValue: any) { private static resetColorProperty(view: view.View, nativeValue: any) {
var bar = <UISearchBar>view.ios; var sf = <UITextField>(<any>view)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
sf.textColor = nativeValue; sf.textColor = nativeValue;
} }
@@ -439,24 +433,21 @@ export class SearchBarStyler implements definition.stylers.Styler {
// font // font
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) { private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) {
var bar = <UISearchBar>view.ios; var sf = <UITextField>(<any>view)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
sf.font = (<font.Font>newValue).getUIFont(nativeValue); sf.font = (<font.Font>newValue).getUIFont(nativeValue);
} }
} }
private static resetFontInternalProperty(view: view.View, nativeValue: any) { private static resetFontInternalProperty(view: view.View, nativeValue: any) {
var bar = <UISearchBar>view.ios; var sf = <UITextField>(<any>view)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
sf.font = nativeValue; sf.font = nativeValue;
} }
} }
private static getNativeFontInternalValue(view: view.View): any { private static getNativeFontInternalValue(view: view.View): any {
var bar = <UISearchBar>view.ios; var sf = <UITextField>(<any>view)._textField;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) { if (sf) {
return sf.font; return sf.font;
} }