Merge pull request #3470 from NativeScript/view-tests

View tests turned green
This commit is contained in:
Alexander Vakrilov
2017-01-12 11:28:58 +02:00
committed by GitHub
14 changed files with 578 additions and 605 deletions

View File

@@ -1,6 +1,7 @@
import { IOSActionItemSettings, ActionItem as ActionItemDefinition } from "ui/action-bar";
import { ActionItemBase, ActionBarBase, isVisible, View, colorProperty, backgroundColorProperty, backgroundInternalProperty, layout } from "./action-bar-common";
import { ImageSource, fromFileOrResource } from "image-source";
import { Color } from "color";
export * from "./action-bar-common";
@@ -295,10 +296,15 @@ export class ActionBar extends ActionBarBase {
get [colorProperty.native](): UIColor {
return null;
}
set [colorProperty.native](color: UIColor) {
let navBar = this.navBar;
navBar.tintColor = color;
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color };
set [colorProperty.native](color: Color) {
const navBar = this.navBar;
if (color) {
navBar.tintColor = color.ios;
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
} else {
navBar.tintColor = null;
navBar.titleTextAttributes = null;
}
}
get [backgroundColorProperty.native](): UIColor {

View File

@@ -1,5 +1,6 @@
import { ActivityIndicatorBase, busyProperty, colorProperty } from "./activity-indicator-common";
import { ios } from "utils/utils";
import { Color } from "color";
export * from "./activity-indicator-common";
@@ -36,7 +37,7 @@ export class ActivityIndicator extends ActivityIndicatorBase {
get [colorProperty.native](): UIColor {
return this.nativeView.color;
}
set [colorProperty.native](value: UIColor) {
this.nativeView.color = value;
set [colorProperty.native](value: UIColor | Color) {
this.nativeView.color = value instanceof Color ? value.ios : value;;
}
}

View File

@@ -104,7 +104,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
public bindingContext: any;
public nativeView: any;
public parent: ViewBase;
public isCollapsed;
public isCollapsed = false;
public id: string;
public className: string;
@@ -402,7 +402,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
}
protected _addViewCore(view: ViewBase, atIndex?: number) {
if (isIOS || this._context) {
if (this._context) {
view._setupUI(this._context, atIndex);
}
@@ -443,7 +443,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
// view.unsetInheritedProperties();
if (isIOS || view._context) {
if (view._context) {
view._tearDownUI();
}
}
@@ -465,7 +465,17 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
}
public _setupUI(context: android.content.Context, atIndex?: number) {
traceNotifyEvent(this, "_setupUI");
if (traceEnabled) {
traceWrite(`${this}._setupUI(${context})`, traceCategories.VisualTreeEvents);
}
if (this._context === context) {
return;
}
this._context = context;
traceNotifyEvent(this, "_onContextChanged");
// TODO: refactor createUI to return native view
this._createNativeView();
@@ -474,7 +484,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
this._initNativeView();
if (this.parent) {
this.parent._addViewToNativeVisualTree(this, atIndex);
this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, atIndex);
}
if (this.nativeView) {
@@ -485,13 +495,13 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
child._setupUI(context);
return true;
});
// if (traceEnabled) {
// traceNotifyEvent(this, "_onAttached");
// }
}
public _tearDownUI(force?: boolean) {
if (traceEnabled) {
traceWrite(`${this}._tearDownUI(${force})`, traceCategories.VisualTreeEvents);
}
this.eachChild((child) => {
child._tearDownUI(force);
return true;
@@ -511,6 +521,8 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
this._disposeNativeView();
this._context = null;
traceNotifyEvent(this, "_onContextChanged");
traceNotifyEvent(this, "_tearDownUI");
}
_childIndexToNativeChildIndex(index?: number): number {
@@ -532,6 +544,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
* Method is intended to be overridden by inheritors and used as "protected"
*/
public _removeViewFromNativeVisualTree(view: ViewBase) {
traceNotifyEvent(view, "_removeViewFromNativeVisualTree");
view._isAddedToNativeVisualTree = false;
}

View File

@@ -16,6 +16,8 @@ const DELEGATE = "_delegate";
let navDepth = -1;
const FRAME_CONTEXT = {};
export class Frame extends FrameBase {
private _ios: iOSFrame;
private _paramToNavigate: any;
@@ -29,6 +31,13 @@ export class Frame extends FrameBase {
public _bottom: number;
public _isInitialNavigation: boolean = true;
public get _context(): any {
return FRAME_CONTEXT;
}
public set _context(value:any) {
throw new Error("Frame _context is readonly");
}
constructor() {
super();
this._ios = new iOSFrame(this);
@@ -657,7 +666,7 @@ export function _getNativeCurve(transition: NavigationTransition): UIViewAnimati
traceWrite("Transition curve resolved to UIViewAnimationCurve.Linear.", traceCategories.Transition);
}
return UIViewAnimationCurve.Linear;
default:
if (traceEnabled) {
traceWrite("Transition curve resolved to original: " + transition.curve, traceCategories.Transition);

View File

@@ -38,11 +38,7 @@ export class Progress extends ProgressBase {
return this._ios.progressTintColor;
}
set [colorProperty.native](value: Color) {
if (value instanceof Color) {
this._ios.progressTintColor = value.ios;
} else {
this._ios.progressTintColor = value;
}
this._ios.progressTintColor = value instanceof Color ? value.ios : value;;
}
get [backgroundColorProperty.native](): UIColor {

View File

@@ -1,51 +1,30 @@
import { Font as FontDefinition, ParsedFont } from "ui/styling/font";
import { makeValidator, makeParser} from "ui/core/properties";
import { makeValidator, makeParser } from "ui/core/properties";
export abstract class FontBase implements FontDefinition {
public static default = undefined;
private _fontFamily: string;
private _fontStyle: FontStyle;
private _fontWeight: FontWeight;
private _fontSize: number;
get fontFamily(): string {
return this._fontFamily;
}
get fontStyle(): FontStyle {
return this._fontStyle;
}
get fontWeight(): FontWeight {
return this._fontWeight;
}
get fontSize(): number {
return this._fontSize;
}
get isItalic(): boolean {
return this._fontStyle === FontStyle.ITALIC;
return this.fontStyle === FontStyle.ITALIC;
}
get isBold(): boolean {
return this._fontWeight === FontWeight.BOLD
|| this._fontWeight === "700";
return this.fontWeight === FontWeight.BOLD
|| this.fontWeight === "700";
}
protected constructor(family: string, size: number, style: FontStyle, weight: FontWeight) {
this._fontFamily = family;
this._fontSize = size;
this._fontStyle = style;
this._fontWeight = weight;
protected constructor(
public readonly fontFamily: string,
public readonly fontSize: number,
public readonly fontStyle: FontStyle,
public readonly fontWeight: FontWeight) {
}
public abstract getAndroidTypeface(): android.graphics.Typeface;
public abstract getUIFont(defaultFont: UIFont): UIFont;
public abstract withFontFamily(family: string): FontBase;
public abstract withFontStyle(style: string): FontBase;
public abstract withFontWeight(weight: string):FontBase;
public abstract withFontWeight(weight: string): FontBase;
public abstract withFontSize(size: number): FontBase;
public static equals(value1: FontBase, value2: FontBase): boolean {
@@ -79,10 +58,10 @@ export namespace FontWeight {
export const THIN: "100" = "100";
export const EXTRA_LIGHT: "200" = "200";
export const LIGHT: "300" = "300";
export const NORMAL: "normal" = "normal";
export const NORMAL: "normal" = "normal";
export const MEDIUM: "500" = "500";
export const SEMI_BOLD: "600" = "600";
export const BOLD: "bold" = "bold";
export const BOLD: "bold" = "bold";
export const EXTRA_BOLD: "800" = "800";
export const BLACK: "900" = "900";
export const isValid = makeValidator<FontWeight>(THIN, EXTRA_LIGHT, LIGHT, NORMAL, "400", MEDIUM, SEMI_BOLD, BOLD, "700", EXTRA_BOLD, BLACK);
@@ -114,7 +93,7 @@ export module genericFontFamilies {
const styles = new Set();
[
FontStyle.NORMAL,
FontStyle.NORMAL,
FontStyle.ITALIC
].forEach((val, i, a) => styles.add(val));
@@ -132,16 +111,16 @@ const styles = new Set();
//- 900(Black / Heavy) (API21 -black)
const weights = new Set();
[
FontWeight.THIN,
FontWeight.EXTRA_LIGHT,
FontWeight.LIGHT,
FontWeight.NORMAL,
"400",
FontWeight.MEDIUM,
FontWeight.SEMI_BOLD,
FontWeight.BOLD,
"700",
FontWeight.EXTRA_BOLD,
FontWeight.THIN,
FontWeight.EXTRA_LIGHT,
FontWeight.LIGHT,
FontWeight.NORMAL,
"400",
FontWeight.MEDIUM,
FontWeight.SEMI_BOLD,
FontWeight.BOLD,
"700",
FontWeight.EXTRA_BOLD,
FontWeight.BLACK
].forEach((val, i, a) => weights.add(val));

View File

@@ -36,7 +36,7 @@ export class Font extends FontBase {
public getAndroidTypeface(): android.graphics.Typeface {
if (!this._typeface) {
var fontStyle = 0;
let fontStyle = 0;
if (this.isBold) {
fontStyle |= android.graphics.Typeface.BOLD;
}
@@ -44,7 +44,7 @@ export class Font extends FontBase {
fontStyle |= android.graphics.Typeface.ITALIC;
}
var typeFace = createTypeface(this);
const typeFace = createTypeface(this);
this._typeface = android.graphics.Typeface.create(typeFace, fontStyle);
}
return this._typeface;
@@ -66,8 +66,8 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface {
if (result === undefined) {
result = null;
var fontAssetPath: string;
var basePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts", fontFamily);
let fontAssetPath: string;
const basePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts", fontFamily);
if (fs.File.exists(basePath + ".ttf")) {
fontAssetPath = FONTS_BASE_PATH + fontFamily + ".ttf";
}
@@ -83,7 +83,7 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface {
if (fontAssetPath) {
try {
fontAssetPath = fs.path.join(fs.knownFolders.currentApp().path, fontAssetPath);
result = android.graphics.Typeface.createFromFile(fontAssetPath)
result = android.graphics.Typeface.createFromFile(fontAssetPath);
} catch (e) {
if (traceEnabled) {
traceWrite("Error loading font asset: " + fontAssetPath, traceCategories.Error, traceMessageType.error);
@@ -98,13 +98,13 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface {
function createTypeface(font: Font): android.graphics.Typeface {
//http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to
var fonts = parseFontFamily(font.fontFamily);
var result = null;
const fonts = parseFontFamily(font.fontFamily);
let result = null;
if (fonts.length === 0) {
return null;
}
for (var i = 0; i < fonts.length; i++) {
for (let i = 0; i < fonts.length; i++) {
switch (fonts[i].toLowerCase()) {
case genericFontFamilies.serif:
result = android.graphics.Typeface.create("serif" + getFontWeightSuffix(font.fontWeight), 0);

View File

@@ -1,7 +1,7 @@
import {
TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty,
textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, whiteSpaceProperty,
Font, Color, FormattedString, TextDecoration, TextAlignment, TextTransform, WhiteSpace,
TextBaseCommon, formattedTextProperty, textAlignmentProperty, textDecorationProperty, fontSizeProperty,
textProperty, textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty,
whiteSpaceProperty, Font, Color, FormattedString, TextDecoration, TextAlignment, TextTransform, WhiteSpace,
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length
} from "./text-base-common";
import { toUIString } from "utils/types";
@@ -64,6 +64,18 @@ export class TextBase extends TextBaseCommon {
}
}
//FontSize
get [fontSizeProperty.native](): { nativeSize: number } {
return { nativeSize: this._nativeView.getTextSize() };
}
set [fontSizeProperty.native](value: number | { nativeSize: number }) {
if (typeof value === "number") {
this._nativeView.setTextSize(value);
} else {
this._nativeView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
}
}
//FontInternal
get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } {
let textView = this._nativeView;
@@ -75,14 +87,11 @@ export class TextBase extends TextBaseCommon {
set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) {
let textView = this._nativeView;
if (value instanceof Font) {
// Set value
// Set value. Note: Size is handled in fontSizeProperty.native
textView.setTypeface(value.getAndroidTypeface());
if (value.fontSize !== undefined) {
textView.setTextSize(value.fontSize);
}
}
else {
// Reset value
// Reset value. Note: Resetting fontInternal will reset the size also.
textView.setTypeface(value.typeface);
textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize);
}