mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fix nativeView issues
Fix Listeners base class
This commit is contained in:
@@ -10,6 +10,20 @@ let cssSymbolPropertyMap = {};
|
||||
let inheritableProperties = new Array<InheritedProperty<any, any>>();
|
||||
let inheritableCssProperties = new Array<InheritedCssProperty<any, any>>();
|
||||
|
||||
function print(map) {
|
||||
let symbols = (<any>Object).getOwnPropertySymbols(map);
|
||||
for (let symbol of symbols) {
|
||||
const prop = map[symbol];
|
||||
if (!prop.registered) {
|
||||
console.log(`Property ${prop.name} not Registered!!!!!`);
|
||||
}
|
||||
}
|
||||
}
|
||||
export function printUnregisteredProperties(): void {
|
||||
print(symbolPropertyMap);
|
||||
print(cssSymbolPropertyMap)
|
||||
}
|
||||
|
||||
const enum ValueSource {
|
||||
Default = 0,
|
||||
Inherited = 1,
|
||||
@@ -650,6 +664,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
|
||||
}
|
||||
|
||||
export class ShorthandProperty<T extends Style> {
|
||||
private registered: boolean;
|
||||
private readonly setLocalValue: (value: string) => void;
|
||||
private readonly setCssValue: (value: string) => void;
|
||||
|
||||
@@ -721,6 +736,10 @@ export class ShorthandProperty<T extends Style> {
|
||||
}
|
||||
|
||||
public register(cls: { prototype: T }): void {
|
||||
if (this.registered) {
|
||||
throw new Error(`Property ${this.name} already registered.`);
|
||||
}
|
||||
this.registered = true;
|
||||
Object.defineProperty(cls.prototype, this.name, this.localValueDescriptor);
|
||||
Object.defineProperty(cls.prototype, this.cssName, this.cssValueDescriptor);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Background } from "ui/styling/background";
|
||||
import {
|
||||
ViewBase, getEventOrGestureName, Observable, EventData, Style,
|
||||
Property, InheritedProperty, CssProperty, ShorthandProperty, InheritedCssProperty,
|
||||
gestureFromString, isIOS, traceEnabled, traceWrite, traceCategories, traceNotifyEvent
|
||||
gestureFromString, isIOS, traceEnabled, traceWrite, traceCategories, traceNotifyEvent, printUnregisteredProperties
|
||||
} from "./view-base";
|
||||
import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures";
|
||||
import { Font, parseFont } from "ui/styling/font";
|
||||
@@ -931,11 +931,6 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public _shouldApplyStyleHandlers() {
|
||||
// If we have native view we are ready to apply style handelr;
|
||||
return !!this._nativeView;
|
||||
}
|
||||
|
||||
public focus(): boolean {
|
||||
return undefined;
|
||||
}
|
||||
@@ -1456,10 +1451,12 @@ function convertToTransform(value: string): [CssProperty<any, any>, any][] {
|
||||
|
||||
// Background properties.
|
||||
export const backgroundInternalProperty = new CssProperty<Style, Background>({ name: "backgroundInternal", cssName: "_backgroundInternal", defaultValue: Background.default });
|
||||
backgroundInternalProperty.register(Style);
|
||||
|
||||
let pattern: RegExp = /url\(('|")(.*?)\1\)/;
|
||||
export const backgroundImageProperty = new CssProperty<Style, string>({
|
||||
name: "backgroundImage", cssName: "background-image", valueChanged: (target, oldValue, newValue) => {
|
||||
|
||||
let style = target;
|
||||
let currentBackground = target.backgroundInternal;
|
||||
let url: string = newValue;
|
||||
@@ -1505,6 +1502,7 @@ backgroundImageProperty.register(Style);
|
||||
|
||||
export const backgroundColorProperty = new CssProperty<Style, Color>({
|
||||
name: "backgroundColor", cssName: "background-color", valueChanged: (target, newValue) => {
|
||||
printUnregisteredProperties();
|
||||
let background = target.backgroundInternal;
|
||||
target.backgroundInternal = background.withColor(newValue);
|
||||
}, equalityComparer: Color.equals, valueConverter: (value) => new Color(value)
|
||||
|
||||
@@ -23,8 +23,9 @@ const VIEW_GROUP = "_viewGroup";
|
||||
|
||||
// TODO: Move this class into widgets.
|
||||
@Interfaces([android.view.View.OnTouchListener])
|
||||
class DisableUserInteractionListener implements android.view.View.OnTouchListener {
|
||||
class DisableUserInteractionListener extends java.lang.Object implements android.view.View.OnTouchListener {
|
||||
constructor() {
|
||||
super();
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
@@ -34,8 +35,9 @@ class DisableUserInteractionListener implements android.view.View.OnTouchListene
|
||||
}
|
||||
|
||||
@Interfaces([android.view.View.OnTouchListener])
|
||||
class TouchListener implements android.view.View.OnTouchListener {
|
||||
class TouchListener extends java.lang.Object implements android.view.View.OnTouchListener {
|
||||
constructor(private owner: WeakRef<View>) {
|
||||
super();
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
@@ -223,6 +225,8 @@ export class View extends ViewCommon {
|
||||
this._nativeView.setLayoutParams(new org.nativescript.widgets.CommonLayoutParams());
|
||||
}
|
||||
|
||||
this.nativeView = this._nativeView;
|
||||
|
||||
if (traceEnabled) {
|
||||
traceNotifyEvent(this, "_onContextChanged");
|
||||
}
|
||||
@@ -1079,11 +1083,11 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
|
||||
public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean {
|
||||
super._addViewToNativeVisualTree(child);
|
||||
|
||||
if (this.nativeView && child.nativeView) {
|
||||
if (this._nativeView && child.nativeView) {
|
||||
if (traceEnabled) {
|
||||
traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents);
|
||||
}
|
||||
this._nativeView.addView(child._nativeView, atIndex);
|
||||
this._nativeView.addView(child.nativeView, atIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
8
tns-core-modules/ui/core/view.d.ts
vendored
8
tns-core-modules/ui/core/view.d.ts
vendored
@@ -126,11 +126,6 @@ declare module "ui/core/view" {
|
||||
* A View occupies a rectangular area on the screen and is responsible for drawing and layouting of all UI components within.
|
||||
*/
|
||||
export abstract class View extends ViewBase implements ApplyXmlAttributes {
|
||||
/**
|
||||
* Get the nativeView created for this object.
|
||||
*/
|
||||
public nativeView: any;
|
||||
|
||||
/**
|
||||
* Gets the android-specific native instance that lies behind this proxy. Will be available if running on an Android platform.
|
||||
*/
|
||||
@@ -609,9 +604,6 @@ declare module "ui/core/view" {
|
||||
_onDetached(force?: boolean): void;
|
||||
_createUI(): void;
|
||||
|
||||
_shouldApplyStyleHandlers();
|
||||
// _checkMetadataOnPropertyChanged(metadata: dependencyObservable.PropertyMetadata);
|
||||
|
||||
_updateLayout(): void;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user