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;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -24,15 +24,15 @@ function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.Pr
|
|||||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
|
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
|
||||||
|
|
||||||
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
// This should be in a Try Catch in case Apple eliminates which ever method in the future;
|
// This should be in a Try Catch in case Apple eliminates which ever method in the future;
|
||||||
try {
|
try {
|
||||||
// TODO; convert this code into NativeScript Code
|
// TODO; convert this code into NativeScript Code
|
||||||
/* if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
|
/* if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
|
||||||
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
|
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
|
||||||
} */
|
} */
|
||||||
} catch (Err) {
|
} catch (Err) {
|
||||||
// Do Nothing
|
// Do Nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldHintColorProperty.metadata).onSetNativeValue = onTextFieldHintColorPropertyChanged;
|
(<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;
|
(<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() {
|
||||||
@@ -122,5 +117,18 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user