From 8330ac0ac1813be314dddb94cc8d7ee3afcf564c Mon Sep 17 00:00:00 2001 From: Martin Yankov Date: Wed, 13 Feb 2019 15:10:06 +0200 Subject: [PATCH 1/5] fix(css): widget properties in css didn't work (#6889) --- .../search-bar-tests-native.android.ts | 9 ++++ .../search-bar/search-bar-tests-native.d.ts | 1 + .../search-bar/search-bar-tests-native.ios.ts | 5 ++ tests/app/ui/search-bar/search-bar-tests.ts | 50 ++++++++++++++++++- tns-core-modules/ui/styling/style-scope.ts | 3 +- 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tests/app/ui/search-bar/search-bar-tests-native.android.ts b/tests/app/ui/search-bar/search-bar-tests-native.android.ts index 743638199..77b316d2b 100644 --- a/tests/app/ui/search-bar/search-bar-tests-native.android.ts +++ b/tests/app/ui/search-bar/search-bar-tests-native.android.ts @@ -23,6 +23,15 @@ export function getNativeHintColor(searchBar: searchBarModule.SearchBar): colorM return undefined; } +export function getNativeTextFieldBackgroundColor(searchBar: searchBarModule.SearchBar): colorModule.Color { + var textView = getTextView(searchBar.android); + + if (textView) { + return new colorModule.Color((textView.getBackground()).getColor()); + } + return undefined; +} + export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number { var textView = getTextView(searchBar.android); diff --git a/tests/app/ui/search-bar/search-bar-tests-native.d.ts b/tests/app/ui/search-bar/search-bar-tests-native.d.ts index 30a126a99..2f62edce7 100644 --- a/tests/app/ui/search-bar/search-bar-tests-native.d.ts +++ b/tests/app/ui/search-bar/search-bar-tests-native.d.ts @@ -3,4 +3,5 @@ import * as searchBarModule from "tns-core-modules/ui/search-bar"; import * as colorModule from "tns-core-modules/color"; export declare function getNativeHintColor(textView: searchBarModule.SearchBar): colorModule.Color; +export declare function getNativeTextFieldBackgroundColor(textView: searchBarModule.SearchBar): colorModule.Color; export declare function getNativeFontSize(searchBar: searchBarModule.SearchBar): number; diff --git a/tests/app/ui/search-bar/search-bar-tests-native.ios.ts b/tests/app/ui/search-bar/search-bar-tests-native.ios.ts index 3f4b158c3..ca87c46fe 100644 --- a/tests/app/ui/search-bar/search-bar-tests-native.ios.ts +++ b/tests/app/ui/search-bar/search-bar-tests-native.ios.ts @@ -5,6 +5,11 @@ import { getColor } from "../helper"; export function getNativeHintColor(searchBar: SearchBar): Color { return (searchBar)._placeholderLabel ? getColor((searchBar)._placeholderLabel.textColor) : undefined; } + +export function getNativeTextFieldBackgroundColor(searchBar: SearchBar): Color { + return (searchBar)._textField ? getColor((searchBar)._textField.backgroundColor) : undefined; +} + export function getNativeFontSize(searchBar: SearchBar): number { return (searchBar)._textField ? (searchBar)._textField.font.pointSize : undefined; } diff --git a/tests/app/ui/search-bar/search-bar-tests.ts b/tests/app/ui/search-bar/search-bar-tests.ts index e7c417c77..446abb66b 100644 --- a/tests/app/ui/search-bar/search-bar-tests.ts +++ b/tests/app/ui/search-bar/search-bar-tests.ts @@ -28,7 +28,7 @@ export function test_recycling() { helper.nativeView_recycling_test(() => new searchBarModule.SearchBar()); } -export var testSearchBarHintColorAndroid = function () { +export var testSearchBarHintColor = function () { helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array) { var searchBar = views[0]; @@ -50,6 +50,28 @@ export var testSearchBarHintColorAndroid = function () { }); }; +export var testSearchBarTextFieldBackgroundColor = function () { + helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array) { + var searchBar = views[0]; + + searchBar.text = ""; + searchBar.hint = ""; + + var expectedNormalizedValue; + var actualValue; + + searchBar.textFieldBackgroundColor = new colorModule.Color("blue"); + expectedNormalizedValue = "#0000FF"; // blue + actualValue = searchBarTestsNative.getNativeTextFieldBackgroundColor(searchBar).hex; + TKUnit.assert(actualValue === expectedNormalizedValue, "Actual: " + actualValue + "; Expected: " + expectedNormalizedValue); + + searchBar.textFieldBackgroundColor = new colorModule.Color("red"); + expectedNormalizedValue = "#FF0000"; // red + actualValue = searchBarTestsNative.getNativeTextFieldBackgroundColor(searchBar).hex; + TKUnit.assert(actualValue === expectedNormalizedValue, "Actual: " + actualValue + "; Expected: " + expectedNormalizedValue); + }); +}; + export var testSearchBarFontSize = function () { helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array) { var searchBar = views[0]; @@ -66,6 +88,32 @@ export var testSearchBarFontSize = function () { }); }; +export var testSearchBarPropertiesWithCSS = function () { + helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array) { + var searchBar = views[0]; + + const expectedHintColor = "#0000FF"; // blue + const expectedTextFieldBackgroundColor = "#FF0000"; // red + const expectedFontSize = 30; + + const hintColorActualValue = searchBarTestsNative.getNativeHintColor(searchBar).hex; + const textFieldBackgroundColorActualValue = searchBarTestsNative.getNativeTextFieldBackgroundColor(searchBar).hex; + const fontSizeActualValue = searchBarTestsNative.getNativeFontSize(searchBar); + + TKUnit.assert(hintColorActualValue === expectedHintColor, "HintColor - Actual: " + hintColorActualValue + "; Expected: " + expectedHintColor); + TKUnit.assert(expectedTextFieldBackgroundColor === textFieldBackgroundColorActualValue, "Text Background Color - Actual: " + textFieldBackgroundColorActualValue + "; Expected: " + expectedTextFieldBackgroundColor); + TKUnit.assertAreClose(expectedFontSize, fontSizeActualValue, 0.2, "Font Size - Actual: " + fontSizeActualValue + "; Expected: " + expectedFontSize); + }, { pageCss: ` + SearchBar { + text: test; + hint: test; + text-field-hint-color: blue; + text-field-background-color: red; + font-size: 30; + } + `}); +}; + export function test_DummyTestForSnippetOnly() { // >> article-searching var searchBar = new searchBarModule.SearchBar(); diff --git a/tns-core-modules/ui/styling/style-scope.ts b/tns-core-modules/ui/styling/style-scope.ts index a915b559d..a643f5a93 100644 --- a/tns-core-modules/ui/styling/style-scope.ts +++ b/tns-core-modules/ui/styling/style-scope.ts @@ -481,7 +481,8 @@ export class CssState { if (property in this.view.style) { this.view.style[`css:${property}`] = value; } else { - this.view[property] = value; + const camelCasedProperty = property.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); + this.view[camelCasedProperty] = value; } } catch (e) { traceWrite(`Failed to apply property [${property}] with value [${value}] to ${this.view}. ${e}`, traceCategories.Error, traceMessageType.error); From 57f07a3ec72f095fd7e0d1955f3275816f9d3354 Mon Sep 17 00:00:00 2001 From: Alexander Djenkov Date: Wed, 13 Feb 2019 15:11:04 +0200 Subject: [PATCH 2/5] fix(frame-ios): tearDownUI when UINavigationController disappear (#6892) --- tests/app/navigation/navigation-tests.ts | 7 +++++-- tns-core-modules/ui/frame/frame.ios.ts | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/app/navigation/navigation-tests.ts b/tests/app/navigation/navigation-tests.ts index bdd5de1c2..42cc2327d 100644 --- a/tests/app/navigation/navigation-tests.ts +++ b/tests/app/navigation/navigation-tests.ts @@ -101,8 +101,11 @@ export function test_backAndForwardParentPage_nestedFrames() { helper.waitUntilNavigatedTo(parentPage1, () => frame.goBack()); currentPageMustBe("ParentPage1"); - helper.waitUntilNavigatedTo(parentPage2, () => topmost.navigate({ create: () => parentPage2 })); - currentPageMustBe("ParentPage2"); + const innerPage3 = page("InnerPage3"); + const parentPage3 = parentPage("ParentPage3", innerPage3); + + helper.waitUntilNavigatedTo(parentPage3, () => topmost.navigate({ create: () => parentPage3 })); + currentPageMustBe("ParentPage3"); back(2); TKUnit.waitUntilReady(() => topmostFrame().navigationQueueIsEmpty()); diff --git a/tns-core-modules/ui/frame/frame.ios.ts b/tns-core-modules/ui/frame/frame.ios.ts index 849d3b0b2..4fcbf0902 100644 --- a/tns-core-modules/ui/frame/frame.ios.ts +++ b/tns-core-modules/ui/frame/frame.ios.ts @@ -37,6 +37,8 @@ export class Frame extends FrameBase { public disposeNativeView() { this._removeFromFrameStack(); + this.viewController = null; + this._ios.controller = null; super.disposeNativeView(); } @@ -389,9 +391,8 @@ class UINavigationControllerImpl extends UINavigationController { const owner = this._owner.get(); if (owner && owner.isLoaded && !owner.parent && !this.presentedViewController) { owner.callUnloaded(); + owner._tearDownUI(true); - owner.viewController = null; - owner.ios.controller = null; } } From 0416f7e80ec0f5af95c443eafd082f8161aa9b61 Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Thu, 14 Feb 2019 15:00:04 +0200 Subject: [PATCH 3/5] fix(ios-textview): text alignment reset to default on blur (#6903) --- tns-core-modules/ui/text-base/text-base.ios.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tns-core-modules/ui/text-base/text-base.ios.ts b/tns-core-modules/ui/text-base/text-base.ios.ts index 446f9b794..e9303a108 100644 --- a/tns-core-modules/ui/text-base/text-base.ios.ts +++ b/tns-core-modules/ui/text-base/text-base.ios.ts @@ -138,6 +138,10 @@ export class TextBase extends TextBaseCommon { paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; } attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length }); + } else if (this.nativeTextViewProtected instanceof UITextView) { + const paragraphStyle = NSMutableParagraphStyle.alloc().init(); + paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; + attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length }); } if (this.nativeTextViewProtected instanceof UIButton) { @@ -175,6 +179,7 @@ export class TextBase extends TextBaseCommon { dict.set(NSKernAttributeName, style.letterSpacing * this.nativeTextViewProtected.font.pointSize); } + const isTextView = this.nativeTextViewProtected instanceof UITextView; if (style.lineHeight) { const paragraphStyle = NSMutableParagraphStyle.alloc().init(); paragraphStyle.lineSpacing = style.lineHeight; @@ -185,9 +190,12 @@ export class TextBase extends TextBaseCommon { paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; } dict.set(NSParagraphStyleAttributeName, paragraphStyle); + } else if (isTextView) { + const paragraphStyle = NSMutableParagraphStyle.alloc().init(); + paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; + dict.set(NSParagraphStyleAttributeName, paragraphStyle); } - const isTextView = this.nativeTextViewProtected instanceof UITextView; if (style.color && (dict.size > 0 || isTextView)) { dict.set(NSForegroundColorAttributeName, style.color.ios); } From 5dd01a3cb999efd33458363988deef0abc3d4ae3 Mon Sep 17 00:00:00 2001 From: Martin Yankov Date: Thu, 14 Feb 2019 16:21:19 +0200 Subject: [PATCH 4/5] fix(ios): searcbar hint color before hint property (#6902) --- .../search-bar/search-bar-tests-native.ios.ts | 7 ++- tests/app/ui/search-bar/search-bar-tests.ts | 5 ++- .../ui/search-bar/search-bar.ios.ts | 44 +++++++++---------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/tests/app/ui/search-bar/search-bar-tests-native.ios.ts b/tests/app/ui/search-bar/search-bar-tests-native.ios.ts index ca87c46fe..0076d8bb3 100644 --- a/tests/app/ui/search-bar/search-bar-tests-native.ios.ts +++ b/tests/app/ui/search-bar/search-bar-tests-native.ios.ts @@ -3,7 +3,12 @@ import { Color } from "tns-core-modules/color"; import { getColor } from "../helper"; export function getNativeHintColor(searchBar: SearchBar): Color { - return (searchBar)._placeholderLabel ? getColor((searchBar)._placeholderLabel.textColor) : undefined; + if ((searchBar)._textField) { + const placeholder = (searchBar)._textField.valueForKey("placeholderLabel"); + return getColor(placeholder.textColor); + } + + return undefined; } export function getNativeTextFieldBackgroundColor(searchBar: SearchBar): Color { diff --git a/tests/app/ui/search-bar/search-bar-tests.ts b/tests/app/ui/search-bar/search-bar-tests.ts index 446abb66b..a6b2198fe 100644 --- a/tests/app/ui/search-bar/search-bar-tests.ts +++ b/tests/app/ui/search-bar/search-bar-tests.ts @@ -92,6 +92,9 @@ export var testSearchBarPropertiesWithCSS = function () { helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array) { var searchBar = views[0]; + searchBar.text = ""; + searchBar.hint = "hint css test"; + const expectedHintColor = "#0000FF"; // blue const expectedTextFieldBackgroundColor = "#FF0000"; // red const expectedFontSize = 30; @@ -105,8 +108,6 @@ export var testSearchBarPropertiesWithCSS = function () { TKUnit.assertAreClose(expectedFontSize, fontSizeActualValue, 0.2, "Font Size - Actual: " + fontSizeActualValue + "; Expected: " + expectedFontSize); }, { pageCss: ` SearchBar { - text: test; - hint: test; text-field-hint-color: blue; text-field-background-color: red; font-size: 30; 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 b32de5320..0e28efa26 100644 --- a/tns-core-modules/ui/search-bar/search-bar.ios.ts +++ b/tns-core-modules/ui/search-bar/search-bar.ios.ts @@ -71,7 +71,6 @@ export class SearchBar extends SearchBarBase { nativeViewProtected: UISearchBar; private _delegate; private __textField: UITextField; - private __placeholderLabel: UILabel; createNativeView() { return UISearchBarImpl.new(); @@ -113,16 +112,6 @@ export class SearchBar extends SearchBarBase { return this.__textField; } - get _placeholderLabel(): UILabel { - if (!this.__placeholderLabel) { - if (this._textField) { - this.__placeholderLabel = this._textField.valueForKey("placeholderLabel"); - } - } - - return this.__placeholderLabel; - } - [isEnabledProperty.setNative](value: boolean) { const nativeView = this.nativeViewProtected; if (nativeView instanceof UIControl) { @@ -189,8 +178,7 @@ export class SearchBar extends SearchBarBase { return ""; } [hintProperty.setNative](value: string) { - const text = (value === null || value === undefined) ? "" : value.toString(); - this.ios.placeholder = text; + this._updateAttributedPlaceholder(); } [textFieldBackgroundColorProperty.getDefault](): UIColor { @@ -210,18 +198,30 @@ export class SearchBar extends SearchBarBase { } [textFieldHintColorProperty.getDefault](): UIColor { - const placeholderLabel = this._placeholderLabel; - if (placeholderLabel) { - return placeholderLabel.textColor; - } - return null; } [textFieldHintColorProperty.setNative](value: Color | UIColor) { - const color = value instanceof Color ? value.ios : value - const placeholderLabel = this._placeholderLabel; - if (placeholderLabel) { - placeholderLabel.textColor = color; + this._updateAttributedPlaceholder(); + } + + // Very similar to text-field.ios.ts implementation. Maybe unify APIs and base classes? + _updateAttributedPlaceholder(): void { + let stringValue = this.hint; + if (stringValue === null || stringValue === void 0) { + stringValue = ""; + } else { + stringValue = stringValue + ""; } + if (stringValue === "") { + // we do not use empty string since initWithStringAttributes does not return proper value and + // nativeView.attributedPlaceholder will be null + stringValue = " "; + } + const attributes: any = {}; + if (this.textFieldHintColor) { + attributes[NSForegroundColorAttributeName] = this.textFieldHintColor.ios; + } + const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, attributes); + this._textField.attributedPlaceholder = attributedPlaceholder; } } From 46ce8666d20bc998fa0631f3d10ce8994925c467 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Tue, 19 Feb 2019 11:50:29 +0200 Subject: [PATCH 5/5] release: cut the 5.2.1 release (#6925) --- CHANGELOG.md | 13 +++++++++++++ tns-core-modules/package.json | 2 +- tns-platform-declarations/package.json | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eed8fa67..a8531de07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ + +## [5.2.1](https://github.com/NativeScript/NativeScript/compare/5.2.0...5.2.1) (2019-02-19) + + +### Bug Fixes + +* **css:** widget properties in css didn't work ([#6889](https://github.com/NativeScript/NativeScript/issues/6889)) ([8330ac0](https://github.com/NativeScript/NativeScript/commit/8330ac0)) +* **frame-ios:** tearDownUI when UINavigationController disappear ([#6892](https://github.com/NativeScript/NativeScript/issues/6892)) ([57f07a3](https://github.com/NativeScript/NativeScript/commit/57f07a3)) +* **ios:** searcbar hint color before hint property ([#6902](https://github.com/NativeScript/NativeScript/issues/6902)) ([5dd01a3](https://github.com/NativeScript/NativeScript/commit/5dd01a3)) +* **ios-textview:** text alignment reset to default on blur ([#6903](https://github.com/NativeScript/NativeScript/issues/6903)) ([0416f7e](https://github.com/NativeScript/NativeScript/commit/0416f7e)) + + + # [5.2.0](https://github.com/NativeScript/NativeScript/compare/5.1.2...5.2.0) (2019-02-08) diff --git a/tns-core-modules/package.json b/tns-core-modules/package.json index aac49b8ed..d856903dd 100644 --- a/tns-core-modules/package.json +++ b/tns-core-modules/package.json @@ -1,7 +1,7 @@ { "name": "tns-core-modules", "description": "Telerik NativeScript Core Modules", - "version": "5.2.0", + "version": "5.2.1", "homepage": "https://www.nativescript.org", "repository": { "type": "git", diff --git a/tns-platform-declarations/package.json b/tns-platform-declarations/package.json index b3d093a34..41c672ff6 100644 --- a/tns-platform-declarations/package.json +++ b/tns-platform-declarations/package.json @@ -1,6 +1,6 @@ { "name": "tns-platform-declarations", - "version": "5.2.0", + "version": "5.2.1", "description": "Platform-specific TypeScript declarations for NativeScript for accessing native objects", "main": "", "scripts": {