chore: cleanup

This commit is contained in:
Nathan Walker
2020-07-09 23:43:28 -07:00
parent 0ae8dba962
commit 8100cf7089
89 changed files with 493 additions and 704 deletions

View File

@@ -12,6 +12,7 @@ import { Device, screen } from '../../platform';
import lazy from '../../utils/lazy';
export * from './animation-common';
export { KeyframeAnimation, KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo } from './keyframe-animation';
let argbEvaluator: android.animation.ArgbEvaluator;
function ensureArgbEvaluator() {

View File

@@ -2,6 +2,8 @@
import { Color } from '../../color';
import { PercentLength } from '../styling/style-properties';
export { KeyframeAnimation, KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo } from './keyframe-animation';
/**
* Defines animation options for the View.animate method.
*/

View File

@@ -12,6 +12,7 @@ import { ios as iosNativeHelper } from '../../utils/native-helper';
import { screen } from '../../platform';
export * from './animation-common';
export { KeyframeAnimation, KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo } from './keyframe-animation';
let _transform = '_transform';
let _skip = '_skip';

View File

@@ -1,6 +1,3 @@
// Definitions.
import { Keyframes as KeyframesDefinition, UnparsedKeyframe as UnparsedKeyframeDefinition, KeyframeDeclaration as KeyframeDeclarationDefinition, KeyframeInfo as KeyframeInfoDefinition, KeyframeAnimationInfo as KeyframeAnimationInfoDefinition, KeyframeAnimation as KeyframeAnimationDefinition } from './keyframe-animation';
import { View } from '../core/view';
import { Color } from '../../color';
@@ -13,28 +10,28 @@ import { unsetValue } from '../core/properties';
import { Animation } from '.';
import { backgroundColorProperty, scaleXProperty, scaleYProperty, translateXProperty, translateYProperty, rotateProperty, opacityProperty, rotateXProperty, rotateYProperty, widthProperty, heightProperty, PercentLength } from '../styling/style-properties';
export class Keyframes implements KeyframesDefinition {
export class Keyframes {
name: string;
keyframes: Array<UnparsedKeyframe>;
}
export class UnparsedKeyframe implements UnparsedKeyframeDefinition {
export class UnparsedKeyframe {
values: Array<any>;
declarations: Array<KeyframeDeclaration>;
}
export class KeyframeDeclaration implements KeyframeDeclarationDefinition {
export class KeyframeDeclaration {
public property: string;
public value: any;
}
export class KeyframeInfo implements KeyframeInfoDefinition {
export class KeyframeInfo {
public duration: number;
public declarations: Array<KeyframeDeclaration>;
public curve?: any = AnimationCurve.ease;
}
export class KeyframeAnimationInfo implements KeyframeAnimationInfoDefinition {
export class KeyframeAnimationInfo {
public keyframes: Array<KeyframeInfo>;
public name?: string = '';
public duration?: number = 0.3;
@@ -59,7 +56,7 @@ interface Keyframe {
forceLayer?: boolean;
}
export class KeyframeAnimation implements KeyframeAnimationDefinition {
export class KeyframeAnimation {
public animations: Array<Keyframe>;
public delay: number = 0;
public iterations: number = 1;

View File

@@ -1,46 +0,0 @@
import { Border as BorderDefinition } from '.';
import { ContentView } from '../content-view';
import { View, CSSType } from '../core/view';
import { layout } from '../../utils';
@Deprecated
@CSSType('Border')
export class Border extends ContentView implements BorderDefinition {
get cornerRadius(): number {
if (typeof this.borderRadius === 'number') {
return <number>this.borderRadius;
}
return 0;
}
set cornerRadius(value: number) {
this.borderRadius = value;
}
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
const height = layout.getMeasureSpecSize(heightMeasureSpec);
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
const horizontalBorderLength = this.effectiveBorderLeftWidth + this.effectiveBorderRightWidth;
const verticalBorderLength = this.effectiveBorderTopWidth + this.effectiveBorderBottomWidth;
const result = View.measureChild(this, this.layoutView, layout.makeMeasureSpec(width - horizontalBorderLength, widthMode), layout.makeMeasureSpec(height - verticalBorderLength, heightMode));
const widthAndState = View.resolveSizeAndState(result.measuredWidth + horizontalBorderLength, width, widthMode, 0);
const heightAndState = View.resolveSizeAndState(result.measuredHeight + verticalBorderLength, height, heightMode, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}
public onLayout(left: number, top: number, right: number, bottom: number): void {
let horizontalBorderLength = this.effectiveBorderLeftWidth + this.effectiveBorderRightWidth;
let verticalBorderLength = this.effectiveBorderTopWidth + this.effectiveBorderBottomWidth;
View.layoutChild(this, this.layoutView, this.effectiveBorderLeftWidth, this.effectiveBorderTopWidth, right - left - horizontalBorderLength, bottom - top - verticalBorderLength);
}
}
Border.prototype.recycleNativeView = 'auto';

View File

@@ -1 +1,6 @@
/**
* Helps sanitize a module name if it is prefixed with '~/', '~' or '/'
* @param moduleName the name
* @param removeExtension whether to remove extension
*/
export function sanitizeModuleName(moduleName: string, removeExtension?: boolean): string;

View File

@@ -1,3 +1,8 @@
/**
* Helps sanitize a module name if it is prefixed with '~/', '~' or '/'
* @param moduleName the name
* @param removeExtension whether to remove extension
*/
export function sanitizeModuleName(moduleName: string, removeExtension: boolean = true): string {
moduleName = moduleName.trim();

View File

@@ -417,10 +417,6 @@ export abstract class ViewBase extends Observable {
*/
public ensureDomNode();
//@private
/**
* @private
*/
public recycleNativeView: 'always' | 'never' | 'auto';
/**

View File

@@ -666,3 +666,38 @@ export module UserInterfaceStyle {
*/
export const dark: string;
}
/**
* Singular rollup for convenience of all enums
*/
export declare const Enums: {
Accuracy: typeof Accuracy;
AndroidActionBarIconVisibility: typeof AndroidActionBarIconVisibility;
AndroidActionItemPosition: typeof AndroidActionItemPosition;
AnimationCurve: typeof AnimationCurve;
AutocapitalizationType: typeof AutocapitalizationType;
BackgroundRepeat: typeof BackgroundRepeat;
DeviceOrientation: typeof DeviceOrientation;
DeviceType: typeof DeviceType;
Dock: typeof Dock;
FontAttributes: typeof FontAttributes;
FontStyle: typeof FontStyle;
FontWeight: typeof FontWeight;
HorizontalAlignment: typeof HorizontalAlignment;
IOSActionItemPosition: typeof IOSActionItemPosition;
ImageFormat: typeof ImageFormat;
KeyboardType: typeof KeyboardType;
NavigationBarVisibility: typeof NavigationBarVisibility;
Orientation: typeof Orientation;
ReturnKeyType: typeof ReturnKeyType;
StatusBarStyle: typeof StatusBarStyle;
Stretch: typeof Stretch;
SystemAppearance: typeof SystemAppearance;
TextAlignment: typeof TextAlignment;
TextDecoration: typeof TextDecoration;
TextTransform: typeof TextTransform;
UpdateTextTrigger: typeof UpdateTextTrigger;
VerticalAlignment: typeof VerticalAlignment;
Visibility: typeof Visibility;
WhiteSpace: typeof WhiteSpace;
};

View File

@@ -195,3 +195,35 @@ export module SystemAppearance {
export const light = 'light';
export const dark = 'dark';
}
export const Enums = {
Accuracy,
AndroidActionBarIconVisibility,
AndroidActionItemPosition,
AnimationCurve,
AutocapitalizationType,
BackgroundRepeat,
DeviceOrientation,
DeviceType,
Dock,
FontAttributes,
FontStyle,
FontWeight,
HorizontalAlignment,
IOSActionItemPosition,
ImageFormat,
KeyboardType,
NavigationBarVisibility,
Orientation,
ReturnKeyType,
StatusBarStyle,
Stretch,
SystemAppearance,
TextAlignment,
TextDecoration,
TextTransform,
UpdateTextTrigger,
VerticalAlignment,
Visibility,
WhiteSpace,
};

View File

@@ -1,5 +1,4 @@
// Types.
import { Frame as FrameDefinition } from '.';
import { BackstackEntry, NavigationContext, NavigationEntry, NavigationTransition, NavigationType } from './frame-interfaces';
import { Page } from '../page';
import { View, CustomLayoutView, CSSType } from '../core/view';
@@ -35,7 +34,7 @@ function buildEntryFromArgs(arg: any): NavigationEntry {
}
@CSSType('Frame')
export class FrameBase extends CustomLayoutView implements FrameDefinition {
export class FrameBase extends CustomLayoutView {
public static androidOptionSelectedEvent = 'optionSelected';
private _animated: boolean;

View File

@@ -1,4 +1,4 @@
import { NavigationType } from './frame-common';
import { NavigationType, FrameBase } from './frame-common';
import { Page } from '../page';
import { Observable, EventData } from '../../data/observable';
import { View } from '../core/view';
@@ -10,7 +10,7 @@ export * from './frame-interfaces';
* Represents the logical View unit that is responsible for navigation within an application.
* Nested frames are supported, enabling hierarchical navigation scenarios.
*/
export class Frame extends View {
export class Frame extends FrameBase {
/**
* Gets a frame by id.
*/

View File

@@ -1,10 +1,12 @@
export { ActionBar, ActionItem, ActionItems, NavigationButton } from './action-bar';
export { ActivityIndicator } from './activity-indicator';
export { Animation, AnimationDefinition } from './animation';
export { Animation, AnimationDefinition, KeyframeAnimation, KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo } from './animation';
export { BottomNavigation, SelectedIndexChangedEventData } from './bottom-navigation';
export { Builder, LoadOptions } from './builder';
export { sanitizeModuleName } from './builder/module-name-sanitizer';
export { Button } from './button';
export { ContentView } from './content-view';
export { Binding, BindingOptions } from './core/bindable';
export { ViewBase, ShowModalOptions, eachDescendant, getAncestor, getViewById } from './core/view-base';
export { View, Template, KeyedTemplate, ShownModallyData } from './core/view';
export { Property, CoercibleProperty, InheritedProperty, CssProperty, InheritedCssProperty, ShorthandProperty, CssAnimationProperty, unsetValue } from './core/properties';
@@ -14,8 +16,7 @@ export { DatePicker } from './date-picker';
export { action, alert, confirm, login, prompt, getCurrentPage, Dialogs, DialogStrings, DialogOptions, CancelableOptions, AlertOptions, PromptResult, PromptOptions, ActionOptions, ConfirmOptions, LoginResult, LoginOptions, inputType, capitalizationType } from './dialogs';
export * from './editable-text-base';
import * as enumsModule from './enums';
export const Enums = enumsModule;
export { Enums } from './enums';
export { Frame, NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry } from './frame';
export { GestureEventData, GestureEventDataWithState, GestureStateTypes, GestureTypes, GesturesObserver, TapGestureEventData, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeDirection, SwipeGestureEventData, TouchGestureEventData } from './gestures';
@@ -29,7 +30,7 @@ export * from './layouts'; // barrel export
export { ListPicker } from './list-picker';
export { ListView, ItemEventData, TemplatedItemsView, ItemsSource } from './list-view';
export { Page, NavigatedData } from './page';
export { Page, NavigatedData, PageBase } from './page';
export { Placeholder, CreateViewEventData } from './placeholder';
export { Progress } from './progress';
export { ProxyViewContainer } from './proxy-view-container';
@@ -41,8 +42,11 @@ export { Slider } from './slider';
// TODO: Consider adding APIs from style
// export { addTaggedAdditionalCSS, removeTaggedAdditionalCSS } from "./styling/style-scope";
export { animationTimingFunctionConverter, timeConverter } from './styling/converters';
export { Style, CommonLayoutParams } from './styling/style';
export * from './styling/style-properties';
export { CssAnimationParser, parseKeyframeDeclarations } from './styling/css-animation-parser';
export { CSSHelper } from './styling/css-selector';
export { Switch } from './switch';
export { TabContentItem } from './tab-navigation-base/tab-content-item';
@@ -51,7 +55,7 @@ export { TabStrip, TabStripItemEventData } from './tab-navigation-base/tab-strip
export { TabStripItem } from './tab-navigation-base/tab-strip-item';
export { TabView, TabViewItem } from './tab-view';
export { Tabs } from './tabs';
export { TextBase } from './text-base';
export { TextBase, TextTransform } from './text-base';
export { FormattedString } from './text-base/formatted-string';
export { Span } from './text-base/span';
export { TextField } from './text-field';

View File

@@ -1,10 +1,12 @@
export { ActionBar, ActionItem, ActionItems, NavigationButton } from './action-bar';
export { ActivityIndicator } from './activity-indicator';
export { Animation, AnimationDefinition } from './animation';
export { Animation, AnimationDefinition, KeyframeAnimation, KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo } from './animation';
export { BottomNavigation, SelectedIndexChangedEventData } from './bottom-navigation';
export { Builder, LoadOptions } from './builder';
export { sanitizeModuleName } from './builder/module-name-sanitizer';
export { Button } from './button';
export { ContentView } from './content-view';
export { Binding, BindingOptions } from './core/bindable';
export { ViewBase, ShowModalOptions, eachDescendant, getAncestor, getViewById } from './core/view-base';
export { View, Template, KeyedTemplate, ShownModallyData } from './core/view';
export { Property, CoercibleProperty, InheritedProperty, CssProperty, InheritedCssProperty, ShorthandProperty, CssAnimationProperty, unsetValue } from './core/properties';
@@ -14,8 +16,7 @@ export { DatePicker } from './date-picker';
export { action, alert, confirm, login, prompt, getCurrentPage, Dialogs, DialogStrings, DialogOptions, CancelableOptions, AlertOptions, PromptResult, PromptOptions, ActionOptions, ConfirmOptions, LoginResult, LoginOptions, inputType, capitalizationType } from './dialogs';
export * from './editable-text-base';
import * as enumsModule from './enums';
export const Enums = enumsModule;
export { Enums } from './enums';
export { Frame, NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry } from './frame';
export { GestureEventData, GestureEventDataWithState, GestureStateTypes, GestureTypes, GesturesObserver, TapGestureEventData, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeDirection, SwipeGestureEventData, TouchGestureEventData } from './gestures';
@@ -29,7 +30,7 @@ export * from './layouts'; // barrel export
export { ListPicker } from './list-picker';
export { ListView, ItemEventData, TemplatedItemsView, ItemsSource } from './list-view';
export { Page, NavigatedData } from './page';
export { Page, NavigatedData, PageBase } from './page';
export { Placeholder, CreateViewEventData } from './placeholder';
export { Progress } from './progress';
export { ProxyViewContainer } from './proxy-view-container';
@@ -41,8 +42,11 @@ export { Slider } from './slider';
// TODO: Consider adding APIs from style
// export { addTaggedAdditionalCSS, removeTaggedAdditionalCSS } from "./styling/style-scope";
export { animationTimingFunctionConverter, timeConverter } from './styling/converters';
export { Style, CommonLayoutParams } from './styling/style';
export * from './styling/style-properties';
export { CssAnimationParser, parseKeyframeDeclarations } from './styling/css-animation-parser';
export { CSSHelper } from './styling/css-selector';
export { Switch } from './switch';
export { TabContentItem } from './tab-navigation-base/tab-content-item';

View File

@@ -1,12 +1,14 @@
import { CssProperty, Property } from '../core/properties';
import { PageBase } from './page-common';
import { CssProperty, Property } from '../core/properties';
import { Style } from '../styling/style';
import { EventData } from '../../data/observable';
import { ContentView } from '../content-view';
import { Frame } from '../frame';
import { ActionBar } from '../action-bar';
import { KeyframeAnimationInfo } from '../animation/keyframe-animation';
import { Color } from '../../color';
export * from './page-common';
/**
* Defines the data for the page navigation events.
*/
@@ -29,7 +31,7 @@ export module knownCollections {
/**
* Represents a logical unit for navigation (inside Frame).
*/
export class Page extends ContentView {
export declare class Page extends PageBase {
/**
* String value used when hooking to navigatingTo event.
*/

View File

@@ -0,0 +1,52 @@
import { Page as PageDefinition } from '.';
import { ContentView } from '../content-view';
import { Frame } from '../frame';
import { KeyframeAnimationInfo } from '../animation';
import { NavigatedData } from '.';
import { Color } from '../../color';
import { ActionBar } from '../action-bar';
import { View } from '../core/view';
export declare class PageBase extends ContentView {
static navigatingToEvent: string;
static navigatedToEvent: string;
static navigatingFromEvent: string;
static navigatedFromEvent: string;
_frame: Frame;
actionBarHidden: boolean;
enableSwipeBackNavigation: boolean;
backgroundSpanUnderStatusBar: boolean;
hasActionBar: boolean;
readonly navigationContext: any;
actionBar: ActionBar;
statusBarStyle: 'light' | 'dark';
androidStatusBarBackground: Color;
readonly page: PageDefinition;
_addChildFromBuilder(name: string, value: any): void;
getKeyframeAnimationWithName(animationName: string): KeyframeAnimationInfo;
readonly frame: Frame;
createNavigatedData(eventName: string, isBackNavigation: boolean): NavigatedData {
return {
eventName: eventName,
object: this,
context: this.navigationContext,
isBackNavigation: isBackNavigation,
};
}
onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext?: any): void;
onNavigatedTo(isBackNavigation: boolean): void;
onNavigatingFrom(isBackNavigation: boolean): void;
onNavigatedFrom(isBackNavigation: boolean): void;
eachChildView(callback: (child: View) => boolean): void;
}

View File

@@ -1,4 +1,4 @@
import { Page as PageDefinition, NavigatedData } from '.';
import { Page as PageDefinition } from '.';
import { ContentView } from '../content-view';
import { View, CSSType, ShownModallyData } from '../core/view';
import { booleanConverter } from '../core/view-base';
@@ -12,8 +12,13 @@ import { ActionBar } from '../action-bar';
import { KeyframeAnimationInfo } from '../animation/keyframe-animation';
import { profile } from '../../profiling';
interface NavigatedData extends EventData {
context: any;
isBackNavigation: boolean;
}
@CSSType('Page')
export class PageBase extends ContentView implements PageDefinition {
export class PageBase extends ContentView {
public static navigatingToEvent = 'navigatingTo';
public static navigatedToEvent = 'navigatedTo';
public static navigatingFromEvent = 'navigatingFrom';

View File

@@ -695,3 +695,21 @@ export class SelectorsMatch<T extends Node> implements ChangeAccumulator {
return set;
}
}
export const CSSHelper = {
createSelector,
SelectorCore,
SimpleSelector,
InvalidSelector,
UniversalSelector,
TypeSelector,
ClassSelector,
AttributeSelector,
PseudoClassSelector,
SimpleSelectorSequence,
Selector,
RuleSet,
SelectorsMap,
fromAstNodes,
SelectorsMatch,
};

View File

@@ -10,7 +10,7 @@ import { colorProperty, fontSizeProperty, fontInternalProperty, paddingLeftPrope
import { FormattedString } from './formatted-string';
import { Span } from './span';
import { layout } from '../../utils';
import { isString } from '../../utils/types';
import { isString, isNullOrUndefined } from '../../utils/types';
export * from './text-base-common';
@@ -40,7 +40,7 @@ function initializeTextTransformation(): void {
return createSpannableStringBuilder(formattedText, (<android.widget.TextView>view).getTextSize());
} else {
const text = this.textBase.text;
const stringValue = text === null || text === undefined ? '' : text.toString();
const stringValue = isNullOrUndefined(text) ? '' : text.toString();
return getTransformedText(stringValue, this.textBase.textTransform);
}

View File

@@ -8,7 +8,7 @@ import { Color } from '../../color';
import { FormattedString } from './formatted-string';
import { Span } from './span';
import { colorProperty, fontInternalProperty, VerticalAlignment } from '../styling/style-properties';
import { isString } from '../../utils/types';
import { isString, isDefined, isNullOrUndefined } from '../../utils/types';
import { ios } from '../../utils';
export * from './text-base-common';
@@ -307,7 +307,7 @@ export class TextBase extends TextBaseCommon {
dict.set(NSParagraphStyleAttributeName, paragraphStyle);
}
const source = getTransformedText(this.text ? this.text.toString() : '', this.textTransform);
const source = getTransformedText(isNullOrUndefined(this.text) ? '' : `${this.text}`, this.textTransform);
if (dict.size > 0 || isTextView) {
if (isTextView && this.nativeTextViewProtected.font) {
// UITextView's font seems to change inside.
@@ -349,7 +349,7 @@ export class TextBase extends TextBaseCommon {
const span = formattedString.spans.getItem(i);
const text = span.text;
const textTransform = (<TextBase>formattedString.parent).textTransform;
let spanText = text === null || text === undefined ? '' : text.toString();
let spanText = isNullOrUndefined(text) ? '' : `${text}`;
if (textTransform !== 'none' && textTransform !== 'initial') {
spanText = getTransformedText(spanText, textTransform);
}

View File

@@ -4,6 +4,7 @@ import { ViewBase } from '../core/view-base';
import { FontStyle, FontWeight } from '../styling/font';
import { TextDecoration } from '../text-base';
import { EventData } from '../../data/observable';
import { isNullOrUndefined, isString } from '../../utils/types';
export class Span extends ViewBase implements SpanDefinition {
static linkTapEvent = 'linkTap';
@@ -66,8 +67,12 @@ export class Span extends ViewBase implements SpanDefinition {
}
set text(value: string) {
if (this._text !== value) {
// value can be a number
this._text = `${value}`.replace('\\n', '\n').replace('\\t', '\t');
if (isNullOrUndefined(value)) {
this._text = '';
} else {
// value can be a number
this._text = isString(value) ? `${value}`.replace('\\n', '\n').replace('\\t', '\t') : `${value}`;
}
this.notifyPropertyChange('text', this._text);
}
}

View File

@@ -65,10 +65,15 @@ export abstract class WebViewBase extends ContainerView {
[srcProperty.setNative](src: string) {
this.stopLoading();
// Add file:/// prefix for local files.
// Add file:// prefix for local files.
// They should be loaded with _loadUrl() method as it handles query params.
if (src.indexOf('~/') === 0) {
src = `file:///${knownFolders.currentApp().path}/` + src.substr(2);
let appPath = knownFolders.currentApp().path;
if (appPath && appPath.indexOf('/') !== 0) {
// ensure slash is correct
appPath = `/${appPath}`;
}
src = `file://${appPath}/` + src.substr(2);
} else if (src.indexOf('/') === 0) {
src = 'file://' + src;
}