Skip to content

Commit 3384112

Browse files
Hristo HristovHristo Hristov
authored andcommitted
When application start is called we don't set Frame to be styleScope
Added requestLayout for TextView Round desiredSize in nativeMeasure
1 parent 8df8d75 commit 3384112

File tree

9 files changed

+55
-53
lines changed

9 files changed

+55
-53
lines changed

tests/app/testRunner.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as TKUnit from "./TKUnit";
33
import { messageType } from "tns-core-modules/trace";
44
import { topmost, Frame } from "tns-core-modules/ui/frame";
5+
import { Page } from "tns-core-modules/ui/page";
56
import { TextView } from "tns-core-modules/ui/text-view";
67
import { Button } from "tns-core-modules/ui/button";
78
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
@@ -282,7 +283,7 @@ function printRunTestStats() {
282283
let finalMessage = `\n` +
283284
`=== ALL TESTS COMPLETE ===\n` +
284285
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
285-
`DURATION: ${totalTime} ms\n` +
286+
`DURATION: ${totalTime} ms\n` +
286287
`=== END OF TESTS ===\n`;
287288

288289
TKUnit.write(finalMessage, messageType.info);
@@ -341,23 +342,24 @@ function showReportPage(finalMessage: string) {
341342
messageContainer.text = finalMessage;
342343
stack.addChild(messageContainer);
343344

344-
const page = topmost().currentPage;
345-
page.id = unsetValue;
346-
page.className = unsetValue;
347-
page.bindingContext = unsetValue;
348-
page.style.color = unsetValue;
349-
page.backgroundColor = "white";
350-
page.content = stack;
351-
messageContainer.focus();
352-
page.style.fontSize = 11;
353-
if (page.android) {
354-
setTimeout(() => {
355-
messageContainer.dismissSoftInput();
356-
(<android.view.View>messageContainer.nativeViewProtected).scrollTo(0, 0);
357-
}, 10);
358-
}
359-
}
345+
topmost().navigate({
346+
create: () => {
347+
const page = new Page();
348+
page.content = stack;
349+
messageContainer.focus();
350+
page.style.fontSize = 11;
351+
if (page.android) {
352+
setTimeout(() => {
353+
messageContainer.dismissSoftInput();
354+
(<android.view.View>messageContainer.nativeViewProtected).scrollTo(0, 0);
355+
}, 500);
356+
}
360357

358+
return page;
359+
},
360+
clearHistory: true
361+
});
362+
}
361363

362364
function startLog(): void {
363365
let testsName: string = this.name;

tns-core-modules/application/application.ios.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ class IOSApplication implements IOSApplicationDefinition {
118118
this._rootView = rootView;
119119
const controller = getViewController(rootView);
120120
this._window.rootViewController = controller;
121-
rootView._setupAsRootView({});
121+
if (createRootFrame) {
122+
// Don't setup as styleScopeHost
123+
rootView._setupUI({});
124+
} else {
125+
// setup view as styleScopeHost
126+
rootView._setupAsRootView({});
127+
}
122128
this._window.makeKeyAndVisible();
123129
}
124130

tns-core-modules/ui/core/view/view-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
592592

593593
public requestLayout(): void {
594594
this._isLayoutValid = false;
595+
super.requestLayout();
595596
}
596597

597598
public abstract onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void;

tns-core-modules/ui/core/view/view.ios.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ export class View extends ViewCommon {
5757
super.requestLayout();
5858
this._privateFlags |= PFLAG_FORCE_LAYOUT;
5959

60-
const parent = this.parent;
61-
if (parent) {
62-
parent.requestLayout();
63-
}
64-
6560
const nativeView = this.nativeViewProtected;
6661
if (nativeView) {
6762
nativeView.setNeedsLayout();
@@ -346,7 +341,6 @@ export class View extends ViewCommon {
346341
}
347342

348343
protected _hideNativeModalView(parent: View) {
349-
parent.requestLayout();
350344
const parentController = parent.viewController;
351345
const animated = (<any>this.viewController).animated;
352346
parentController.dismissModalViewControllerAnimated(animated);
@@ -589,13 +583,6 @@ const majorVersion = iosUtils.MajorVersion;
589583
export namespace ios {
590584
export function updateConstraints(controller: UIViewController, owner: View): void {
591585
const root = controller.view;
592-
root.autoresizesSubviews = false;
593-
594-
// const view = controller.view.subviews.length > 0 ? controller.view.subviews[0] : null;
595-
// if (view) {
596-
// view.translatesAutoresizingMaskIntoConstraints = false;
597-
// }
598-
599586
if (!root.safeAreaLayoutGuide) {
600587
const layoutGuide = (<any>root).safeAreaLayoutGuide = UILayoutGuide.alloc().init();
601588
root.addLayoutGuide(layoutGuide);

tns-core-modules/ui/frame/fragment.transitions.android.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ export function _setAndroidFragmentTransitions(
175175
}
176176
}
177177

178-
initDefaultAnimations(manager);
179178
setupDefaultAnimations(newEntry, new DefaultTransition(0, null));
180179

181180
printTransitions(currentEntry);

tns-core-modules/ui/frame/frame-common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
142142
if (frame) {
143143
frame._removeView(page);
144144
} else {
145-
console.log(`---- Removing enrty that was not added to Frame: ${removed.fragmentTag}`);
146145
page._tearDownUI(true);
147146
}
148147
}

tns-core-modules/ui/frame/frame.android.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Definitions.
22
import {
3-
AndroidFrame as AndroidFrameDefinition, BackstackEntry, NavigationEntry,
3+
AndroidFrame as AndroidFrameDefinition, BackstackEntry, NavigationEntry,
44
NavigationTransition, AndroidFragmentCallbacks, AndroidActivityCallbacks
55
} from ".";
66
import { Page } from "../page";
77

88
// Types.
99
import * as application from "../../application";
1010
import {
11-
FrameBase, NavigationContext, stack, goBack, View, Observable, topmost,
11+
FrameBase, NavigationContext, stack, goBack, View, Observable, topmost,
1212
traceEnabled, traceWrite, traceCategories
1313
} from "./frame-common";
1414

@@ -65,8 +65,8 @@ export function reloadPage(): void {
6565
return;
6666
}
6767
}
68-
69-
frame.navigate(newEntry);
68+
69+
frame.navigate(newEntry);
7070
}
7171
}
7272

@@ -185,7 +185,7 @@ export class Frame extends FrameBase {
185185
if (!entry.recreated) {
186186
clearEntry(entry);
187187
}
188-
188+
189189
if (current && !current.recreated) {
190190
clearEntry(current);
191191
}
@@ -317,7 +317,7 @@ export class Frame extends FrameBase {
317317
if (removed.fragment) {
318318
_clearEntry(removed);
319319
}
320-
320+
321321
removed.fragment = null;
322322
removed.viewSavedState = null;
323323
}
@@ -661,7 +661,7 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
661661
}
662662

663663
// Load page here even if root view is not loaded yet.
664-
// Otherwiaw it will show as blank,
664+
// Otherwise it will show as blank,
665665
// The case is Tab->Frame->Page activity recreated, fragments are
666666
// created before Tab loads its items.
667667
// TODO: addCheck if the fragment is visible so we don't load pages
@@ -927,7 +927,14 @@ function setActivityContent(activity: android.app.Activity, savedInstanceState:
927927
}
928928

929929
// Initialize native visual tree;
930-
rootView._setupAsRootView(activity);
930+
if (shouldCreateRootFrame) {
931+
// Don't setup as styleScopeHost
932+
rootView._setupUI(activity);
933+
} else {
934+
// setup view as styleScopeHost
935+
rootView._setupAsRootView(activity);
936+
}
937+
931938
activity.setContentView(rootView.nativeViewProtected, new org.nativescript.widgets.CommonLayoutParams());
932939
}
933940

tns-core-modules/ui/text-view/text-view.ios.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import {
66
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
77
Length, _updateCharactersInRangeReplacementString, Color, layout
88
} from "../editable-text-base";
9+
10+
import { ios } from "../../utils/utils";
911
import { profile } from "../../profiling";
1012

1113
export * from "../editable-text-base";
1214

13-
class UITextViewDelegateImpl extends NSObject implements UIScrollViewDelegate, UITextViewDelegate {
14-
public static ObjCProtocols = [UITextViewDelegate, UIScrollViewDelegate];
15+
class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
16+
public static ObjCProtocols = [UITextViewDelegate];
1517

1618
private _owner: WeakRef<TextView>;
1719

@@ -31,7 +33,7 @@ class UITextViewDelegateImpl extends NSObject implements UIScrollViewDelegate, U
3133
}
3234

3335
public textViewDidBeginEditing(textView: UITextView): void {
34-
const owner = this._owner.get();
36+
const owner = this._owner.get();
3537
if (owner) {
3638
owner._isEditing = true;
3739
owner.notify({ eventName: TextView.focusEvent, object: owner });
@@ -57,6 +59,7 @@ class UITextViewDelegateImpl extends NSObject implements UIScrollViewDelegate, U
5759
if (owner.updateTextTrigger === "textChanged") {
5860
textProperty.nativeValueChange(owner, textView.text);
5961
}
62+
owner.requestLayout();
6063
}
6164
}
6265

@@ -101,9 +104,9 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
101104
constructor() {
102105
super();
103106

104-
this.nativeViewProtected = this._ios = UITextView.new();
105-
if (!this._ios.font) {
106-
this._ios.font = UIFont.systemFontOfSize(12);
107+
const textView = this.nativeViewProtected = this._ios = UITextView.new();
108+
if (!textView.font) {
109+
textView.font = UIFont.systemFontOfSize(12);
107110
}
108111
this._delegate = UITextViewDelegateImpl.initWithOwner(new WeakRef(this));
109112
}
@@ -123,10 +126,6 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
123126
return this._ios;
124127
}
125128

126-
// get nativeView(): UITextView {
127-
// return this._ios;
128-
// }
129-
130129
public _refreshHintState(hint: string, text: string) {
131130
if (this.formattedText) {
132131
return;
@@ -182,6 +181,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
182181
this._isShowingHint = false;
183182
this._refreshColor();
184183
this._setNativeText();
184+
this.requestLayout();
185185
}
186186

187187
[textProperty.getDefault](): string {

tns-core-modules/utils/utils.ios.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
write as traceWrite, categories as traceCategories, messageType as traceMessageType
44
} from "../trace";
55

6+
import { layout as layoutCommon } from "./utils-common";
67
export * from "./utils-common";
78

89
let mainScreenScale;
@@ -38,8 +39,8 @@ export module layout {
3839
height: heightMode === 0 /* layout.UNSPECIFIED */ ? Number.POSITIVE_INFINITY : toDeviceIndependentPixels(height)
3940
});
4041

41-
nativeSize.width = toDevicePixels(nativeSize.width);
42-
nativeSize.height = toDevicePixels(nativeSize.height);
42+
nativeSize.width = layoutCommon.round(toDevicePixels(nativeSize.width));
43+
nativeSize.height = layoutCommon.round(toDevicePixels(nativeSize.height));
4344
return nativeSize;
4445
}
4546
}

0 commit comments

Comments
 (0)