mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
valueForKey("_searchField") replaced
This commit is contained in:
@@ -6,8 +6,7 @@ export function getNativeHintColor(searchBar: searchBarModule.SearchBar): colorM
|
||||
return undefined;
|
||||
}
|
||||
export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number {
|
||||
var bar = <UISearchBar>searchBar.ios;
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>searchBar)._textField;
|
||||
if (sf) {
|
||||
return sf.font.pointSize;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ function onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var bar = <SearchBar>data.object;
|
||||
if (data.newValue instanceof color.Color) {
|
||||
var tf = getUITextField(bar.ios);
|
||||
var tf = (<any>bar)._textField;
|
||||
if (tf) {
|
||||
tf.backgroundColor = data.newValue.ios;
|
||||
}
|
||||
@@ -24,15 +24,15 @@ function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.Pr
|
||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
|
||||
|
||||
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
// This should be in a Try Catch in case Apple eliminates which ever method in the future;
|
||||
try {
|
||||
// TODO; convert this code into NativeScript Code
|
||||
// This should be in a Try Catch in case Apple eliminates which ever method in the future;
|
||||
try {
|
||||
// TODO; convert this code into NativeScript Code
|
||||
/* if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
|
||||
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
|
||||
} */
|
||||
} catch (Err) {
|
||||
// Do Nothing
|
||||
}
|
||||
} catch (Err) {
|
||||
// Do Nothing
|
||||
}
|
||||
}
|
||||
|
||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldHintColorProperty.metadata).onSetNativeValue = onTextFieldHintColorPropertyChanged;
|
||||
@@ -52,14 +52,6 @@ function onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
|
||||
(<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);
|
||||
|
||||
class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
|
||||
@@ -102,9 +94,11 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
|
||||
export class SearchBar extends common.SearchBar {
|
||||
private _ios: UISearchBar;
|
||||
private _delegate;
|
||||
public _textField: UITextField;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._ios = new UISearchBar();
|
||||
|
||||
this._delegate = UISearchBarDelegateImpl.new().initWithOwner(this);
|
||||
@@ -113,6 +107,7 @@ export class SearchBar extends common.SearchBar {
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
this._ios.delegate = this._delegate;
|
||||
this._textField = SearchBar.findTextField(this.ios);
|
||||
}
|
||||
|
||||
public onUnloaded() {
|
||||
@@ -122,5 +117,18 @@ export class SearchBar extends common.SearchBar {
|
||||
|
||||
get ios(): UISearchBar {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,9 +409,7 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
||||
}
|
||||
|
||||
private static getColorProperty(view: view.View): any {
|
||||
var bar = <UISearchBar>view.ios;
|
||||
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
return sf.textColor;
|
||||
}
|
||||
@@ -420,18 +418,14 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
||||
}
|
||||
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var bar = <UISearchBar>view.ios;
|
||||
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
sf.textColor = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||
var bar = <UISearchBar>view.ios;
|
||||
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
sf.textColor = nativeValue;
|
||||
}
|
||||
@@ -439,24 +433,21 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
||||
|
||||
// font
|
||||
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) {
|
||||
var bar = <UISearchBar>view.ios;
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
sf.font = (<font.Font>newValue).getUIFont(nativeValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static resetFontInternalProperty(view: view.View, nativeValue: any) {
|
||||
var bar = <UISearchBar>view.ios;
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
sf.font = nativeValue;
|
||||
}
|
||||
}
|
||||
|
||||
private static getNativeFontInternalValue(view: view.View): any {
|
||||
var bar = <UISearchBar>view.ios;
|
||||
var sf = <UITextField>bar.valueForKey("_searchField");
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
return sf.font;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user