Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 26 additions & 1 deletion apps/automated/src/ui/root-view/reset-root-view-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as TKUnit from '../../tk-unit';
import * as helper from '../../ui-helper';
import { Page, isAndroid, Frame, NavigationEntry, Application, TabView, TabViewItem } from '@nativescript/core';
import { Page, isAndroid, Frame, NavigationEntry, Application, TabView, TabViewItem, Label, Button, StackLayout, FormattedString, Span } from '@nativescript/core';

function waitUntilTabViewReady(page: Page, action: Function) {
helper.waitUntilNavigatedTo(page, action);
Expand Down Expand Up @@ -144,6 +144,31 @@ export function test_reset_during_tab_index_change() {
TKUnit.assertTrue(true);
}

export function test_reset_layout_with_transformed_text_to_frame() {
const label = new Label();
label.text = 'label';
label.textTransform = 'uppercase';

const formattedText = new FormattedString();
const span = new Span();
span.text = 'button';
formattedText.spans.push(span);
const button = new Button();
button.formattedText = formattedText;

const layoutRoot = new StackLayout();
layoutRoot.addChild(label);
layoutRoot.addChild(button);

Application.resetRootView({ create: () => layoutRoot });
TKUnit.waitUntilReady(() => layoutRoot.isLoaded);
TKUnit.assertEqual(Application.getRootView(), layoutRoot);

const testFrameRoot = createTestFrameRootEntry();
helper.waitUntilNavigatedTo(testFrameRoot.page, () => Application.resetRootView(testFrameRoot.entry));
TKUnit.assertEqual(Application.getRootView(), testFrameRoot.root);
}

export function tearDownModule() {
// reset the root to frame for other tests
const resetFrameRoot = createTestFrameRootEntry();
Expand Down
50 changes: 49 additions & 1 deletion apps/automated/src/ui/text-base/text-base-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as TKUnit from '../../tk-unit';
import * as helper from '../../ui-helper';
import { FormattedString, Label, Span, StackLayout } from '@nativescript/core';
import { Button, FormattedString, Label, Span, StackLayout, Utils } from '@nativescript/core';

export function test_native_font_size_with_a11y_font_scale() {
if (__APPLE__) {
Expand All @@ -21,3 +21,51 @@ export function test_native_font_size_with_a11y_font_scale() {
TKUnit.assertEqual(nativeFontSize, expectedNativeFontSize, 'View font size does not respect a11y font scaling');
}
}

function collectJsAndJavaGarbage() {
for (let i = 0; i < 3; i++) {
Utils.GC();
java.lang.System.gc();
java.lang.System.runFinalization();
TKUnit.wait(0.05);
}
}

function displayedText(view: Label | Button): string {
const nativeView = <android.widget.TextView>view.nativeTextViewProtected;

return nativeView.getTransformationMethod().getTransformation(nativeView.getText(), nativeView).toString();
}

export function test_android_text_transform_survives_garbage_collection() {
if (!__ANDROID__) {
return;
}

const label = new Label();
label.text = 'label';
label.textTransform = 'uppercase';

const span = new Span();
span.text = 'button';
const formattedText = new FormattedString();
formattedText.spans.push(span);
const button = new Button();
button.formattedText = formattedText;

const layout = new StackLayout();
layout.addChild(label);
layout.addChild(button);
helper.getCurrentPage().content = layout;
TKUnit.waitUntilReady(() => layout.isLoaded);

collectJsAndJavaGarbage();
label.text = 'changed';
span.text = 'span changed';
label.nativeViewProtected.requestLayout();
button.nativeViewProtected.requestLayout();
TKUnit.wait(0.05);

TKUnit.assertEqual(displayedText(label), 'CHANGED', 'label text-transform after garbage collection');
TKUnit.assertEqual(displayedText(button), 'span changed', 'button formatted text after garbage collection');
}
20 changes: 15 additions & 5 deletions packages/core/ui/text-base/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,30 @@ function initializeTextTransformation(): void {
@NativeClass
@Interfaces([android.text.method.TransformationMethod])
class TextTransformationImpl extends java.lang.Object implements android.text.method.TransformationMethod {
constructor(public textBase: TextBase) {
// Weak: the native text view holds this transformation, so a strong owner would be
// a cycle that only tearing down the view breaks.
public textBase: WeakRef<TextBase>;

constructor(textBase: TextBase) {
super();
this.textBase = new WeakRef(textBase);
}

public getTransformation(charSeq: any, view: android.view.View): any {
const textBase = this.textBase.deref();
if (!textBase) {
return charSeq;
}

// NOTE: Do we need to transform the new text here?
const formattedText = this.textBase.formattedText;
const formattedText = textBase.formattedText;
if (formattedText) {
return this.textBase.createFormattedTextNative(formattedText);
return textBase.createFormattedTextNative(formattedText);
} else {
const text = this.textBase.text;
const text = textBase.text;
const stringValue = isNullOrUndefined(text) ? '' : text.toString();

return getTransformedText(stringValue, this.textBase.textTransform);
return getTransformedText(stringValue, textBase.textTransform);
}
}

Expand Down
Loading