| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,12 @@ import { Color } from "tns-core-modules/color"; | |||
| 3 | 3 | import { getColor } from "../helper"; | |
| 4 | 4 | ||
| 5 | 5 | export function getNativeHintColor(searchBar: SearchBar): Color { | |
| 6 | - return (<any>searchBar)._placeholderLabel ? getColor((<any>searchBar)._placeholderLabel.textColor) : undefined; | ||
| 6 | + if ((<any>searchBar)._textField) { | ||
| 7 | + const placeholder = (<any>searchBar)._textField.valueForKey("placeholderLabel"); | ||
| 8 | + return getColor(placeholder.textColor); | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + return undefined; | ||
| 7 | 12 | } | |
| 8 | 13 | ||
| 9 | 14 | export function getNativeTextFieldBackgroundColor(searchBar: SearchBar): Color { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,6 +92,9 @@ export var testSearchBarPropertiesWithCSS = function () { | |||
| 92 | 92 | helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array<viewModule.View>) { | |
| 93 | 93 | var searchBar = <searchBarModule.SearchBar>views[0]; | |
| 94 | 94 | ||
| 95 | + searchBar.text = ""; | ||
| 96 | + searchBar.hint = "hint css test"; | ||
| 97 | + | ||
| 95 | 98 | const expectedHintColor = "#0000FF"; // blue | |
| 96 | 99 | const expectedTextFieldBackgroundColor = "#FF0000"; // red | |
| 97 | 100 | const expectedFontSize = 30; | |
@@ -105,8 +108,6 @@ export var testSearchBarPropertiesWithCSS = function () { | |||
| 105 | 108 | TKUnit.assertAreClose(expectedFontSize, fontSizeActualValue, 0.2, "Font Size - Actual: " + fontSizeActualValue + "; Expected: " + expectedFontSize); | |
| 106 | 109 | }, { pageCss: ` | |
| 107 | 110 | SearchBar { | |
| 108 | - text: test; | ||
| 109 | - hint: test; | ||
| 110 | 111 | text-field-hint-color: blue; | |
| 111 | 112 | text-field-background-color: red; | |
| 112 | 113 | font-size: 30; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,7 +71,6 @@ export class SearchBar extends SearchBarBase { | |||
| 71 | 71 | nativeViewProtected: UISearchBar; | |
| 72 | 72 | private _delegate; | |
| 73 | 73 | private __textField: UITextField; | |
| 74 | - private __placeholderLabel: UILabel; | ||
| 75 | 74 | ||
| 76 | 75 | createNativeView() { | |
| 77 | 76 | return UISearchBarImpl.new(); | |
@@ -113,16 +112,6 @@ export class SearchBar extends SearchBarBase { | |||
| 113 | 112 | return this.__textField; | |
| 114 | 113 | } | |
| 115 | 114 | ||
| 116 | - get _placeholderLabel(): UILabel { | ||
| 117 | - if (!this.__placeholderLabel) { | ||
| 118 | - if (this._textField) { | ||
| 119 | - this.__placeholderLabel = this._textField.valueForKey("placeholderLabel"); | ||
| 120 | - } | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | - return this.__placeholderLabel; | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | 115 | [isEnabledProperty.setNative](value: boolean) { | |
| 127 | 116 | const nativeView = this.nativeViewProtected; | |
| 128 | 117 | if (nativeView instanceof UIControl) { | |
@@ -189,8 +178,7 @@ export class SearchBar extends SearchBarBase { | |||
| 189 | 178 | return ""; | |
| 190 | 179 | } | |
| 191 | 180 | [hintProperty.setNative](value: string) { | |
| 192 | - const text = (value === null || value === undefined) ? "" : value.toString(); | ||
| 193 | - this.ios.placeholder = text; | ||
| 181 | + this._updateAttributedPlaceholder(); | ||
| 194 | 182 | } | |
| 195 | 183 | ||
| 196 | 184 | [textFieldBackgroundColorProperty.getDefault](): UIColor { | |
@@ -210,18 +198,30 @@ export class SearchBar extends SearchBarBase { | |||
| 210 | 198 | } | |
| 211 | 199 | ||
| 212 | 200 | [textFieldHintColorProperty.getDefault](): UIColor { | |
| 213 | - const placeholderLabel = this._placeholderLabel; | ||
| 214 | - if (placeholderLabel) { | ||
| 215 | - return placeholderLabel.textColor; | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | 201 | return null; | |
| 219 | 202 | } | |
| 220 | 203 | [textFieldHintColorProperty.setNative](value: Color | UIColor) { | |
| 221 | - const color = value instanceof Color ? value.ios : value | ||
| 222 | - const placeholderLabel = this._placeholderLabel; | ||
| 223 | - if (placeholderLabel) { | ||
| 224 | - placeholderLabel.textColor = color; | ||
| 204 | + this._updateAttributedPlaceholder(); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + // Very similar to text-field.ios.ts implementation. Maybe unify APIs and base classes? | ||
| 208 | + _updateAttributedPlaceholder(): void { | ||
| 209 | + let stringValue = this.hint; | ||
| 210 | + if (stringValue === null || stringValue === void 0) { | ||
| 211 | + stringValue = ""; | ||
| 212 | + } else { | ||
| 213 | + stringValue = stringValue + ""; | ||
| 214 | + } | ||
| 215 | + if (stringValue === "") { | ||
| 216 | + // we do not use empty string since initWithStringAttributes does not return proper value and | ||
| 217 | + // nativeView.attributedPlaceholder will be null | ||
| 218 | + stringValue = " "; | ||
| 219 | + } | ||
| 220 | + const attributes: any = {}; | ||
| 221 | + if (this.textFieldHintColor) { | ||
| 222 | + attributes[NSForegroundColorAttributeName] = this.textFieldHintColor.ios; | ||
| 225 | 223 | } | |
| 224 | + const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, attributes); | ||
| 225 | + this._textField.attributedPlaceholder = attributedPlaceholder; | ||
| 226 | 226 | } | |
| 227 | 227 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments