When application start is called we don't set Frame to be styleScope

Added requestLayout for TextView
Round desiredSize in nativeMeasure
This commit is contained in:
Hristo Hristov
2018-01-09 13:17:50 +02:00
parent 8df8d754ab
commit 3384112ce8
9 changed files with 55 additions and 53 deletions

View File

@@ -2,6 +2,7 @@
import * as TKUnit from "./TKUnit";
import { messageType } from "tns-core-modules/trace";
import { topmost, Frame } from "tns-core-modules/ui/frame";
import { Page } from "tns-core-modules/ui/page";
import { TextView } from "tns-core-modules/ui/text-view";
import { Button } from "tns-core-modules/ui/button";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
@@ -282,7 +283,7 @@ function printRunTestStats() {
let finalMessage = `\n` +
`=== ALL TESTS COMPLETE ===\n` +
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
`DURATION: ${totalTime} ms\n` +
`DURATION: ${totalTime} ms\n` +
`=== END OF TESTS ===\n`;
TKUnit.write(finalMessage, messageType.info);
@@ -341,23 +342,24 @@ function showReportPage(finalMessage: string) {
messageContainer.text = finalMessage;
stack.addChild(messageContainer);
const page = topmost().currentPage;
page.id = unsetValue;
page.className = unsetValue;
page.bindingContext = unsetValue;
page.style.color = unsetValue;
page.backgroundColor = "white";
page.content = stack;
messageContainer.focus();
page.style.fontSize = 11;
if (page.android) {
setTimeout(() => {
messageContainer.dismissSoftInput();
(<android.view.View>messageContainer.nativeViewProtected).scrollTo(0, 0);
}, 10);
}
}
topmost().navigate({
create: () => {
const page = new Page();
page.content = stack;
messageContainer.focus();
page.style.fontSize = 11;
if (page.android) {
setTimeout(() => {
messageContainer.dismissSoftInput();
(<android.view.View>messageContainer.nativeViewProtected).scrollTo(0, 0);
}, 500);
}
return page;
},
clearHistory: true
});
}
function startLog(): void {
let testsName: string = this.name;

View File

@@ -118,7 +118,13 @@ class IOSApplication implements IOSApplicationDefinition {
this._rootView = rootView;
const controller = getViewController(rootView);
this._window.rootViewController = controller;
rootView._setupAsRootView({});
if (createRootFrame) {
// Don't setup as styleScopeHost
rootView._setupUI({});
} else {
// setup view as styleScopeHost
rootView._setupAsRootView({});
}
this._window.makeKeyAndVisible();
}

View File

@@ -592,6 +592,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
public requestLayout(): void {
this._isLayoutValid = false;
super.requestLayout();
}
public abstract onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;

View File

@@ -57,11 +57,6 @@ export class View extends ViewCommon {
super.requestLayout();
this._privateFlags |= PFLAG_FORCE_LAYOUT;
const parent = this.parent;
if (parent) {
parent.requestLayout();
}
const nativeView = this.nativeViewProtected;
if (nativeView) {
nativeView.setNeedsLayout();
@@ -346,7 +341,6 @@ export class View extends ViewCommon {
}
protected _hideNativeModalView(parent: View) {
parent.requestLayout();
const parentController = parent.viewController;
const animated = (<any>this.viewController).animated;
parentController.dismissModalViewControllerAnimated(animated);
@@ -589,13 +583,6 @@ const majorVersion = iosUtils.MajorVersion;
export namespace ios {
export function updateConstraints(controller: UIViewController, owner: View): void {
const root = controller.view;
root.autoresizesSubviews = false;
// const view = controller.view.subviews.length > 0 ? controller.view.subviews[0] : null;
// if (view) {
// view.translatesAutoresizingMaskIntoConstraints = false;
// }
if (!root.safeAreaLayoutGuide) {
const layoutGuide = (<any>root).safeAreaLayoutGuide = UILayoutGuide.alloc().init();
root.addLayoutGuide(layoutGuide);

View File

@@ -175,7 +175,6 @@ export function _setAndroidFragmentTransitions(
}
}
initDefaultAnimations(manager);
setupDefaultAnimations(newEntry, new DefaultTransition(0, null));
printTransitions(currentEntry);

View File

@@ -142,7 +142,6 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
if (frame) {
frame._removeView(page);
} else {
console.log(`---- Removing enrty that was not added to Frame: ${removed.fragmentTag}`);
page._tearDownUI(true);
}
}

View File

@@ -1,6 +1,6 @@
// Definitions.
import {
AndroidFrame as AndroidFrameDefinition, BackstackEntry, NavigationEntry,
AndroidFrame as AndroidFrameDefinition, BackstackEntry, NavigationEntry,
NavigationTransition, AndroidFragmentCallbacks, AndroidActivityCallbacks
} from ".";
import { Page } from "../page";
@@ -8,7 +8,7 @@ import { Page } from "../page";
// Types.
import * as application from "../../application";
import {
FrameBase, NavigationContext, stack, goBack, View, Observable, topmost,
FrameBase, NavigationContext, stack, goBack, View, Observable, topmost,
traceEnabled, traceWrite, traceCategories
} from "./frame-common";
@@ -65,8 +65,8 @@ export function reloadPage(): void {
return;
}
}
frame.navigate(newEntry);
frame.navigate(newEntry);
}
}
@@ -185,7 +185,7 @@ export class Frame extends FrameBase {
if (!entry.recreated) {
clearEntry(entry);
}
if (current && !current.recreated) {
clearEntry(current);
}
@@ -317,7 +317,7 @@ export class Frame extends FrameBase {
if (removed.fragment) {
_clearEntry(removed);
}
removed.fragment = null;
removed.viewSavedState = null;
}
@@ -661,7 +661,7 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
}
// Load page here even if root view is not loaded yet.
// Otherwiaw it will show as blank,
// Otherwise it will show as blank,
// The case is Tab->Frame->Page activity recreated, fragments are
// created before Tab loads its items.
// TODO: addCheck if the fragment is visible so we don't load pages
@@ -927,7 +927,14 @@ function setActivityContent(activity: android.app.Activity, savedInstanceState:
}
// Initialize native visual tree;
rootView._setupAsRootView(activity);
if (shouldCreateRootFrame) {
// Don't setup as styleScopeHost
rootView._setupUI(activity);
} else {
// setup view as styleScopeHost
rootView._setupAsRootView(activity);
}
activity.setContentView(rootView.nativeViewProtected, new org.nativescript.widgets.CommonLayoutParams());
}

View File

@@ -6,12 +6,14 @@ import {
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
Length, _updateCharactersInRangeReplacementString, Color, layout
} from "../editable-text-base";
import { ios } from "../../utils/utils";
import { profile } from "../../profiling";
export * from "../editable-text-base";
class UITextViewDelegateImpl extends NSObject implements UIScrollViewDelegate, UITextViewDelegate {
public static ObjCProtocols = [UITextViewDelegate, UIScrollViewDelegate];
class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
public static ObjCProtocols = [UITextViewDelegate];
private _owner: WeakRef<TextView>;
@@ -31,7 +33,7 @@ class UITextViewDelegateImpl extends NSObject implements UIScrollViewDelegate, U
}
public textViewDidBeginEditing(textView: UITextView): void {
const owner = this._owner.get();
const owner = this._owner.get();
if (owner) {
owner._isEditing = true;
owner.notify({ eventName: TextView.focusEvent, object: owner });
@@ -57,6 +59,7 @@ class UITextViewDelegateImpl extends NSObject implements UIScrollViewDelegate, U
if (owner.updateTextTrigger === "textChanged") {
textProperty.nativeValueChange(owner, textView.text);
}
owner.requestLayout();
}
}
@@ -101,9 +104,9 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
constructor() {
super();
this.nativeViewProtected = this._ios = UITextView.new();
if (!this._ios.font) {
this._ios.font = UIFont.systemFontOfSize(12);
const textView = this.nativeViewProtected = this._ios = UITextView.new();
if (!textView.font) {
textView.font = UIFont.systemFontOfSize(12);
}
this._delegate = UITextViewDelegateImpl.initWithOwner(new WeakRef(this));
}
@@ -123,10 +126,6 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
return this._ios;
}
// get nativeView(): UITextView {
// return this._ios;
// }
public _refreshHintState(hint: string, text: string) {
if (this.formattedText) {
return;
@@ -182,6 +181,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
this._isShowingHint = false;
this._refreshColor();
this._setNativeText();
this.requestLayout();
}
[textProperty.getDefault](): string {

View File

@@ -3,6 +3,7 @@ import {
write as traceWrite, categories as traceCategories, messageType as traceMessageType
} from "../trace";
import { layout as layoutCommon } from "./utils-common";
export * from "./utils-common";
let mainScreenScale;
@@ -38,8 +39,8 @@ export module layout {
height: heightMode === 0 /* layout.UNSPECIFIED */ ? Number.POSITIVE_INFINITY : toDeviceIndependentPixels(height)
});
nativeSize.width = toDevicePixels(nativeSize.width);
nativeSize.height = toDevicePixels(nativeSize.height);
nativeSize.width = layoutCommon.round(toDevicePixels(nativeSize.width));
nativeSize.height = layoutCommon.round(toDevicePixels(nativeSize.height));
return nativeSize;
}
}