Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Disable recycling of native views
createNativeView will set iOS nativeView if it is null/undefined
  • Loading branch information
Hristo Hristov authored and Hristo Hristov committed Mar 28, 2017
commit e6250e718a613baea83d2eeb8dc0d426ce4fdc9e
5 changes: 4 additions & 1 deletion tests/app/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ function printRunTestStats() {
messageContainer.focus();
page.style.fontSize = 11;
if (page.android) {
setTimeout(() => messageContainer.dismissSoftInput());
setTimeout(() => {
messageContainer.dismissSoftInput();
(<android.view.View>messageContainer.nativeView).scrollTo(0, 0);
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/app/ui/core/bindable/bindable-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export function test_BindingToDictionaryAtAppLevel() {
pageViewModel.set("testProperty", testPropertyName);
const dict = {};
dict[testPropertyName] = expectedValue;
appModule.resources["dict"] = dict;
appModule.getResources()["dict"] = dict;

const testFunc = function (views: Array<View>) {
const testLabel = <Label>(views[0]);
Expand All @@ -629,7 +629,7 @@ export function test_BindingConverterCalledEvenWithNullValue() {
const testPropertyValue = null;
const expectedValue = "collapsed";
pageViewModel.set("testProperty", testPropertyValue);
appModule.resources["converter"] = function (value) {
appModule.getResources()["converter"] = function (value) {
if (value) {
return "visible";
} else {
Expand Down
6 changes: 3 additions & 3 deletions tests/app/ui/list-view/list-view-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
return result;
};

app.resources["dateConverter"] = dateConverter;
app.getResources()["dateConverter"] = dateConverter;

var data = new observableArray.ObservableArray();
data.push({ date: new Date(2020, 2, 7) });
Expand Down Expand Up @@ -542,7 +542,7 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
return value;
}

app.resources["testConverter"] = testConverter;
app.getResources()["testConverter"] = testConverter;

var listViewModel = new observable.Observable();
listViewModel.set("items", [1, 2, 3]);
Expand Down Expand Up @@ -570,7 +570,7 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
return value;
}

app.resources["testConverter"] = testConverter;
app.getResources()["testConverter"] = testConverter;

var listViewModel = new observable.Observable();
listViewModel.set("items", [1, 2, 3]);
Expand Down
2 changes: 1 addition & 1 deletion tests/app/ui/repeater/repeater-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export function test_usingAppLevelConvertersInRepeaterItems() {
return result;
};

app.resources["dateConverter"] = dateConverter;
app.getResources()["dateConverter"] = dateConverter;

var data = new observableArray.ObservableArray();

Expand Down
8 changes: 4 additions & 4 deletions tns-core-modules/application/application-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function hasLaunched(): boolean {
export { Observable };

import { UnhandledErrorEventData, iOSApplication, AndroidApplication, CssChangedEventData } from ".";
import { NavigationEntry } from "../ui/frame";

export const launchEvent = "launch";
export const suspendEvent = "suspend";
Expand All @@ -30,10 +29,11 @@ export const orientationChangedEvent = "orientationChanged";

let cssFile: string = "app.css";

export let mainModule: string;
export let mainEntry: NavigationEntry;
let resources: any = {};

export let resources: any = {};
export function getResources() {
return resources;
}

export function setResources(res: any) {
resources = res;
Expand Down
12 changes: 7 additions & 5 deletions tns-core-modules/application/application.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,23 @@ const androidApp = new AndroidApplication();
exports.android = androidApp;
setApplication(androidApp);

let mainEntry: NavigationEntry;
let started = false;
export function start(entry?: NavigationEntry) {
export function start(entry?: NavigationEntry | string) {
if (started) {
throw new Error("Application is already started.");
}

started = true;
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
if (!androidApp.nativeApp) {
const nativeApp = getNativeApplication();
androidApp.init(nativeApp);
}
}

started = true;
if (entry) {
exports.mainEntry = entry;
}
export function getMainEntry() {
return mainEntry;
}

export function getNativeApplication(): android.app.Application {
Expand Down
18 changes: 7 additions & 11 deletions tns-core-modules/application/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,19 @@ export interface CssChangedEventData extends EventData {
}

/**
* The main page path (without the file extension) for the application starting from the application root.
* For example if you have page called "main.js" in a folder called "subFolder" and your root folder is "app" you can specify mainModule like this:
* var application = require("application");
* application.mainModule = "app/subFolder/main";
* application.start();
* Get main entry specified when calling start function.
*/
export var mainModule: string;
export function getMainEntry(): NavigationEntry;

/**
* The main navigation entry to be used when loading the main Page.
* Get application level static resources.
*/
export var mainEntry: NavigationEntry;
export function getResources(): any;

/**
* An application level static resources.
* Set application level static resources.
*/
export var resources: any;
export function setResources(res: any): void;

/**
* Sets application level static resources.
Expand Down Expand Up @@ -156,7 +152,7 @@ export function off(eventNames: string, callback?: any, thisArg?: any);
/**
* Call this method to start the application. Important: All code after this method call will not be executed!
*/
export function start(entry?: NavigationEntry);
export function start(entry?: NavigationEntry | string);

/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
Expand Down
18 changes: 10 additions & 8 deletions tns-core-modules/application/application.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,14 @@ const iosApp = new IOSApplication();
exports.ios = iosApp;
setApplication(iosApp);

let mainEntry: NavigationEntry;
function createRootView(v?: View) {
let rootView = v;
let frame: Frame;
let main: string | NavigationEntry;
if (!rootView) {
// try to navigate to the mainEntry/Module (if specified)
main = exports.mainEntry || exports.mainModule;
// try to navigate to the mainEntry (if specified)
main = mainEntry;
if (main) {
frame = new Frame();
frame.navigate(main);
Expand All @@ -209,12 +210,13 @@ function createRootView(v?: View) {
return rootView;
}

export function getMainEntry() {
return mainEntry;
}

let started: boolean = false;
exports.start = function (entry?: NavigationEntry) {
if (entry) {
exports.mainEntry = entry;
}

export function start(entry?: string | NavigationEntry) {
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
started = true;

if (!iosApp.nativeApp) {
Expand Down Expand Up @@ -246,4 +248,4 @@ global.__onLiveSync = function () {
}

livesync();
}
}
4 changes: 3 additions & 1 deletion tns-core-modules/ui/action-bar/action-bar.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ export class ActionBar extends ActionBarBase {
}

public initNativeView(): void {
super.initNativeView();
(<any>this.nativeView).menuItemClickListener.owner = this;
}

public disposeNativeView() {
(<any>this.nativeView).menuItemClickListener.owner = null;
super.disposeNativeView();
}

public onLoaded() {
Expand Down Expand Up @@ -365,7 +367,7 @@ export class ActionBar extends ActionBarBase {
}
}

ActionBar.prototype.recycleNativeView = true;
// ActionBar.prototype.recycleNativeView = true;

let defaultTitleTextColor: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class ActivityIndicatorBase extends View implements ActivityIndicatorDefi
public busy: boolean;
}

ActivityIndicatorBase.prototype.recycleNativeView = true;
// ActivityIndicatorBase.prototype.recycleNativeView = true;

export const busyProperty = new Property<ActivityIndicatorBase, boolean>({ name: "busy", defaultValue: false, valueConverter: booleanConverter });
busyProperty.register(ActivityIndicatorBase);
2 changes: 1 addition & 1 deletion tns-core-modules/ui/border/border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export class Border extends ContentView implements BorderDefinition {
}
}

Border.prototype.recycleNativeView = true;
// Border.prototype.recycleNativeView = true;
2 changes: 1 addition & 1 deletion tns-core-modules/ui/button/button-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export abstract class ButtonBase extends TextBase implements ButtonDefinition {
}
}

ButtonBase.prototype.recycleNativeView = true;
// ButtonBase.prototype.recycleNativeView = true;
2 changes: 2 additions & 0 deletions tns-core-modules/ui/button/button.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export class Button extends ButtonBase {

public initNativeView(): void {
(<any>this.nativeView).clickListener.owner = this;
super.initNativeView();
}

public disposeNativeView() {
(<any>this.nativeView).clickListener.owner = null;
super.disposeNativeView();
}

@PseudoClassHandler("normal", "highlighted", "pressed", "active")
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/content-view/content-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ export class ContentView extends CustomLayoutView implements ContentViewDefiniti
}
}

ContentView.prototype.recycleNativeView = true;
// ContentView.prototype.recycleNativeView = true;
7 changes: 4 additions & 3 deletions tns-core-modules/ui/core/bindable/bindable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ export class Binding {
let context = this.source && this.source.get && this.source.get() || global;
let model = {};
let addedProps = [];
for (let prop in application.resources) {
if (application.resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) {
context[prop] = application.resources[prop];
const resources = application.getResources();
for (let prop in resources) {
if (resources.hasOwnProperty(prop) && !context.hasOwnProperty(prop)) {
context[prop] = resources[prop];
addedProps.push(prop);
}
}
Expand Down
6 changes: 4 additions & 2 deletions tns-core-modules/ui/core/view-base/view-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
}
} else {
// TODO: Implement _createNativeView for iOS
this.createNativeView();
// this.nativeView = this._iosView = (<any>this)._nativeView;
const nativeView = this.createNativeView();
if (!currentNativeView && nativeView) {
this.nativeView = this._iosView = nativeView;
}
}

this.initNativeView();
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/date-picker/date-picker-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class DatePickerBase extends View implements DatePickerDefinition {
public date: Date;
}

DatePickerBase.prototype.recycleNativeView = true;
// DatePickerBase.prototype.recycleNativeView = true;

export const yearProperty = new Property<DatePickerBase, number>({ name: "year", valueConverter: (v) => parseInt(v) });
yearProperty.register(DatePickerBase);
Expand Down
2 changes: 2 additions & 0 deletions tns-core-modules/ui/date-picker/date-picker.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ export class DatePicker extends DatePickerBase {
}

public initNativeView(): void {
super.initNativeView();
(<any>this.nativeView).listener.owner = this;
}

public disposeNativeView() {
(<any>this.nativeView).listener.owner = null;
super.disposeNativeView();
}

private updateNativeDate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
}

public initNativeView(): void {
super.initNativeView();
const nativeView = this.nativeView;
(<any>nativeView).listener.owner = this;
this._keyListenerCache = nativeView.getKeyListener();
Expand Down
29 changes: 3 additions & 26 deletions tns-core-modules/ui/frame/frame.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,6 @@ export class Frame extends FrameBase {
}

public createNativeView() {
// TODO: probably memory leak.
// this._listener = new android.view.View.OnAttachStateChangeListener({
// onViewAttachedToWindow: this.onNativeViewAttachedToWindow.bind(this),
// onViewDetachedFromWindow: this.onNativeViewDetachedToWindow.bind(this)
// });

const root = new org.nativescript.widgets.ContentLayout(this._context);
if (this._containerViewId < 0) {
this._containerViewId = android.view.View.generateViewId();
Expand All @@ -304,31 +298,17 @@ export class Frame extends FrameBase {
}

public initNativeView(): void {
super.initNativeView();
this._android.rootViewGroup = this.nativeView;
this._android.rootViewGroup.setId(this._containerViewId);
// this._android.rootViewGroup.addOnAttachStateChangeListener(this._listener);
}

// public resetNativeView() {
// this._android.rootViewGroup.removeOnAttachStateChangeListener(this._listener);
// }

public disposeNativeView() {
// we should keep the reference to underlying native object, since frame can contain many pages.
this._android.rootViewGroup = null;
super.disposeNativeView();
}

// private onNativeViewAttachedToWindow(view: android.view.View): void {
// if (this._delayedNavigationEntry) {
// this._navigateCore(this._delayedNavigationEntry);
// this._delayedNavigationEntry = undefined;
// }
// }

// private onNativeViewDetachedToWindow(view: android.view.View): void {
// // unused for the moment.
// }

public _popFromFrameStack() {
if (!this._isInFrameStack) {
return;
Expand Down Expand Up @@ -795,10 +775,7 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
}

if (!rootView) {
navParam = application.mainEntry;
if (!navParam) {
navParam = application.mainModule;
}
navParam = application.getMainEntry();

if (navParam) {
frame = new Frame();
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/html-view/html-view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class HtmlViewBase extends View implements HtmlViewDefinition {
public html: string;
}

HtmlViewBase.prototype.recycleNativeView = true;
// HtmlViewBase.prototype.recycleNativeView = true;

// TODO: Can we use Label.ios optimization for affectsLayout???
export const htmlProperty = new Property<HtmlViewBase, string>({ name: "html", defaultValue: "", affectsLayout: true });
Expand Down
Loading