GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — hhristov/recycle native view android by hshristov · Pull Request #3885 · NativeScript/NativeScript

hhristov/recycle native view android #3885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
vchimev merged 4 commits into master from hhristov/recycle-native-view-android
Mar 28, 2017

Uh oh!

There was an error while loading. Please reload this page.

Merged

hhristov/recycle native view android #3885

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
f2898f8
NativeView recycled for android
Mar 28, 2017
c18a76c
rename:
Mar 28, 2017
84e726e
Resolving comments
Mar 28, 2017
e6250e7
Disable recycling of native views
Mar 28, 2017
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 4 additions & 7 deletions 11 apps/app/ui-tests-app/app.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ application.on(application.lowMemoryEvent, function (args: application.Applicati
});

application.on(application.uncaughtErrorEvent, function (args: application.UnhandledErrorEventData) {
if (args.android) {
// For Android applications, args.android is NativeScriptError.
console.log("### NativeScriptError: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is NativeScriptError.
console.log("### NativeScriptError: " + args.ios);
}
console.log("### NativeScriptError: " + args.error);
console.log("### nativeException: " + (<any>args.error).nativeException);
console.log("### stackTace: " + (<any>args.error).stackTrace);
console.log("### stack: " + args.error.stack);
});

application.setCssFileName("ui-tests-app/app.css");
Expand Down
12 changes: 5 additions & 7 deletions 12 apps/app/ui-tests-app/mainPage.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ var oldExamples: Map<string, string> = new Map<string, string>();

export function pageLoaded(args: EventData) {
let page = <Page>args.object;
let view = require("ui/core/view");
let wrapLayout = <WrapLayout>view.getViewById(page, "wrapLayoutWithExamples");

let wrapLayout = page.getViewById<WrapLayout>("wrapLayoutWithExamples");
examples.set("action-bar", "action-bar/main-page");
examples.set("bindings", "bindings/main-page");
examples.set("css", "css/main-page");
Expand Down Expand Up @@ -46,8 +44,8 @@ export function pageLoaded(args: EventData) {
let viewModel = new MainPageViewModel(wrapLayout, examples);
page.bindingContext = viewModel;

var parent = page.getViewById('parentLayout');
var searchBar = page.getViewById('textView');
var parent = page.getViewById('parentLayout');
var searchBar = page.getViewById('textView');

if (parent.android) {
parent.android.setFocusableInTouchMode(true);
Expand All @@ -57,7 +55,7 @@ export function pageLoaded(args: EventData) {

refresh();
}

// should be removes
export function refresh() {
oldExamples.set("actStyle", "action-bar/all");
Expand Down Expand Up @@ -217,7 +215,7 @@ export class MainPageViewModel extends observable.Observable {
}

btn.style.color = new colorModule.Color(this.colors[count++ % 3]);
btn.on(buttonModule.Button.tapEvent, function(eventData) {
btn.on(buttonModule.Button.tapEvent, function (eventData) {
let text = btn.text;
this.loadExample(text);
}, this);
Expand Down
4 changes: 2 additions & 2 deletions 4 tests/app/TKUnit.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,13 @@ export var wait = function (seconds: number) {
}, seconds, false);
};

export var waitUntilReady = function (isReady: () => boolean, timeoutSec: number = 20, shouldThrow: boolean = true) {
export var waitUntilReady = function (isReady: () => boolean, timeoutSec: number = 3, shouldThrow: boolean = true) {
if (!isReady) {
return;
}

if (Application.ios) {
var waitTime = 20 / 1000;
const waitTime = 20 / 1000;
var totalWaitTime = 0;
while (true) {
utils.ios.getter(NSRunLoop, NSRunLoop.currentRunLoop).runUntilDate(<any>NSDate.dateWithTimeIntervalSinceNow(waitTime));
Expand Down
6 changes: 5 additions & 1 deletion 6 tests/app/testRunner.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,12 @@ function printRunTestStats() {
page.style.backgroundColor = unsetValue;
page.content = stack;
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
6 changes: 3 additions & 3 deletions 6 tests/app/ui/action-bar/action-bar-tests.android.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function test_actionItem_visibility() {
actionItem.text = "Test";
const page = actionTestsCommon.createPageAndNavigate();
page.actionBar.actionItems.addItem(actionItem);
const toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;
const menu = toolbar.getMenu();

TKUnit.assertTrue(menu.hasVisibleItems(), "Visibility does not work");
Expand All @@ -25,7 +25,7 @@ export function test_navigationButton_visibility() {
const page = actionTestsCommon.createPageAndNavigate();
page.actionBar.navigationButton = actionItem;

const toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeView;

TKUnit.assertNotNull(toolbar.getNavigationIcon(), "Visibility does not work");
actionItem.visibility = Visibility.collapse;
Expand Down Expand Up @@ -72,4 +72,4 @@ export function test_add_actionItem_with_actionView_propagates_context() {
TKUnit.assertNull(actionButton._context, "Action button context should be null before added");
actionItem.actionView = actionButton;
TKUnit.assertNotNull(actionButton._context, "Action button context should not be null after add");
}
}
4 changes: 2 additions & 2 deletions 4 tests/app/ui/core/bindable/bindable-tests.ts
Show comments
View file
Open in desktop
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
2 changes: 1 addition & 1 deletion 2 tests/app/ui/layouts/common-layout-tests.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function percent_support_nativeLayoutParams_are_correct(test: testModule.

test.waitUntilTestElementLayoutIsValid();

let lp = getNativeLayoutParams(btn._nativeView);
let lp = getNativeLayoutParams(btn.nativeView);
TKUnit.assertEqual(lp.width, 100, "width");
TKUnit.assertEqual(lp.widthPercent, -1, "widthPercent");
TKUnit.assertEqual(lp.height, 100, "height");
Expand Down
1 change: 1 addition & 0 deletions 1 tests/app/ui/layouts/flexbox-layout-tests.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export function testFlexboxPage() {
function view(id: string) {
return <View>page.getViewById(id);
}
TKUnit.waitUntilReady(() => page.isLayoutValid);
isLeftOf(view("six"), view("one"));
isAbove(view("one"), view("scrollview"));
isAbove(view("title"), view("firstlabel"));
Expand Down
94 changes: 41 additions & 53 deletions 94 tests/app/ui/layouts/layout-helper.android.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {Button} from "tns-core-modules/ui/button";
import {StackLayout} from "tns-core-modules/ui/layouts/stack-layout";
import {GridLayout} from "tns-core-modules/ui/layouts/grid-layout";
import { Button } from "tns-core-modules/ui/button";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
import { GridLayout } from "tns-core-modules/ui/layouts/grid-layout";

import * as utils from "tns-core-modules/utils/utils";
import * as TKUnit from "../../TKUnit";
import * as def from "./layout-helper";

var DELTA = 0.1;

class NativeButton extends android.widget.Button {
private owner: def.MeasuredView;

constructor(context: android.content.Context, owner: def.MeasuredView) {
class NativeButton extends android.widget.Button {
constructor(context: android.content.Context, public owner: def.MeasuredView) {
super(context);
this.owner = owner;
return global.__native(this);
}

Expand All @@ -31,11 +28,8 @@ class NativeButton extends android.widget.Button {
}

class NativeStackLayout extends org.nativescript.widgets.StackLayout {
private owner: def.MeasuredView;

constructor(context: android.content.Context, owner: def.MeasuredView) {
constructor(context: android.content.Context, public owner: def.MeasuredView) {
super(context);
this.owner = owner;
return global.__native(this);
}

Expand All @@ -53,11 +47,8 @@ class NativeStackLayout extends org.nativescript.widgets.StackLayout {
}

class NativeGridLayout extends org.nativescript.widgets.GridLayout {
private owner: def.MeasuredView;

constructor(context: android.content.Context, owner: def.MeasuredView) {
constructor(context: android.content.Context, public owner: def.MeasuredView) {
super(context);
this.owner = owner;
return global.__native(this);
}

Expand All @@ -75,19 +66,18 @@ class NativeGridLayout extends org.nativescript.widgets.GridLayout {
}

export class MyButton extends Button implements def.MyButton {
private _layout: android.view.View;
nativeView: NativeButton;

get android(): android.view.View {
return this._layout;
public createNativeView() {
return new NativeButton(this._context, this);
}

get _nativeView(): android.view.View {
return this._layout;
public initNativeView(): void {
this.nativeView.owner = this;
}

public _createNativeView() {
this._layout = new NativeButton(this._context, this);
return this._layout;
public disposeNativeView() {
this.nativeView.owner = undefined;
}

public measureCount: number = 0;
Expand All @@ -112,36 +102,35 @@ export class MyButton extends Button implements def.MyButton {
}

get layoutWidth(): number {
return this._layout.getWidth();
return this.nativeView.getWidth();
}

get layoutHeight(): number {
return this._layout.getHeight();
return this.nativeView.getHeight();
}

get layoutLeft(): number {
return this._layout.getLeft();
return this.nativeView.getLeft();
}

get layoutTop(): number {
return this._layout.getTop();
return this.nativeView.getTop();
}
}

export class MyStackLayout extends StackLayout implements def.MyStackLayout {
private _layout: android.view.View;
nativeView: NativeStackLayout;

get android(): android.view.View {
return this._layout;
public createNativeView() {
return new NativeStackLayout(this._context, this);
}

get _nativeView(): android.view.View {
return this._layout;
public initNativeView(): void {
this.nativeView.owner = this;
}

public _createNativeView() {
this._layout = new NativeStackLayout(this._context, this);
return this._layout;
public disposeNativeView() {
this.nativeView.owner = undefined;
}

public measureCount: number = 0;
Expand All @@ -166,36 +155,35 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
}

get layoutWidth(): number {
return this._layout.getWidth();
return this.nativeView.getWidth();
}

get layoutHeight(): number {
return this._layout.getHeight();
return this.nativeView.getHeight();
}

get layoutLeft(): number {
return this._layout.getLeft();
return this.nativeView.getLeft();
}

get layoutTop(): number {
return this._layout.getTop();
return this.nativeView.getTop();
}
}

export class MyGridLayout extends GridLayout implements def.MyGridLayout {
private _layout: android.view.View;
nativeView: NativeGridLayout;

get android(): android.view.View {
return this._layout;
public createNativeView() {
return new NativeGridLayout(this._context, this);
}

get _nativeView(): android.view.View {
return this._layout;
public initNativeView(): void {
this.nativeView.owner = this;
}

public _createNativeView() {
this._layout = new NativeGridLayout(this._context, this);
return this._layout;
public disposeNativeView() {
this.nativeView.owner = undefined;
}

public measureCount: number = 0;
Expand All @@ -220,19 +208,19 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout {
}

get layoutWidth(): number {
return this._layout.getWidth();
return this.nativeView.getWidth();
}

get layoutHeight(): number {
return this._layout.getHeight();
return this.nativeView.getHeight();
}

get layoutLeft(): number {
return this._layout.getLeft();
return this.nativeView.getLeft();
}

get layoutTop(): number {
return this._layout.getTop();
return this.nativeView.getTop();
}
}

Expand All @@ -258,4 +246,4 @@ export function dp(value: number): number {

export function dip(value: number): number {
return utils.layout.toDevicePixels(value);
}
}
8 changes: 4 additions & 4 deletions 8 tests/app/ui/list-picker/list-picker-tests-native.android.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as listPickerModule from "tns-core-modules/ui/list-picker";

export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): number {
var maxValue = listPicker.android.getMaxValue();
var maxValue = listPicker.nativeView.getMaxValue();

if (listPicker.items.length === 0 && maxValue === 0) {
return 0;
Expand All @@ -12,6 +12,6 @@ export function getNativeItemsCount(listPicker: listPickerModule.ListPicker): nu

export function selectNativeItem(listPicker: listPickerModule.ListPicker, index: number): void {
var oldIndex = listPicker.selectedIndex;
listPicker.android.setValue(index);
(<any>listPicker)._valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
}
listPicker.nativeView.setValue(index);
listPicker.nativeView.valueChangedListener.onValueChange(listPicker.android, oldIndex, index);
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.