Skip to content

Commit 55da749

Browse files
edusperoniCopilot
andauthored
Merge remote-tracking branch 'origin/main' into fix/android-text-transformation-owner
# Conflicts: # packages/core/ui/text-base/index.android.ts Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2 parents 69c034b + e84973f commit 55da749

35 files changed

Lines changed: 785 additions & 205 deletions

File tree

‎apps/automated/src/navigation/transition-tests.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as helper from '../ui-helper';
2-
import { Color, Device, CoreTypes, Trace, SharedTransition, NavigationEntry, NavigationTransition, Page, platformNames, GridLayout } from '@nativescript/core';
2+
import * as TKUnit from '../tk-unit';
3+
import { Color, Device, CoreTypes, Trace, SharedTransition, NavigationEntry, NavigationTransition, Page, platformNames, GridLayout, Frame, Utils } from '@nativescript/core';
34
import { CustomTransition, CustomSharedElementPageTransition } from './custom-transition';
45

56
function _testTransition(navigationTransition: NavigationTransition) {
@@ -52,6 +53,45 @@ export function test_Transitions() {
5253
// helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, animated: false });
5354
}
5455

56+
function collectJsAndJavaGarbage() {
57+
for (let i = 0; i < 3; i++) {
58+
Utils.GC();
59+
java.lang.System.gc();
60+
java.lang.System.runFinalization();
61+
TKUnit.wait(0.05);
62+
}
63+
}
64+
65+
export function test_Transitions_SurviveGarbageCollectionBeforeGoingBack() {
66+
if (!__ANDROID__) {
67+
return;
68+
}
69+
70+
helper.navigate(() => {
71+
const page = new Page();
72+
page.id = 'TransitionsGcTestPage_MAIN';
73+
74+
return page;
75+
});
76+
77+
helper.navigateWithEntry({
78+
create: () => {
79+
const page = new Page();
80+
page.id = 'TransitionsGcTestPage_SECOND';
81+
82+
return page;
83+
},
84+
animated: true,
85+
transition: { name: 'slide', duration: 20 },
86+
});
87+
88+
// The back navigation reuses the transitions the forward one created.
89+
collectJsAndJavaGarbage();
90+
helper.goBack();
91+
92+
TKUnit.assertEqual(Frame.topmost().currentPage.id, 'TransitionsGcTestPage_MAIN', 'goBack should land on the first page');
93+
}
94+
5595
export function test_SharedElementTransitions(done) {
5696
const mainPage = helper.navigate(() => {
5797
const page = new Page();

‎apps/automated/src/timer/timer-tests.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as TKUnit from '../tk-unit';
22
import * as timer from '@nativescript/core/timer';
3+
import { Utils } from '@nativescript/core';
34

45
// >> timer-require
56
// require("globals");
@@ -51,7 +52,7 @@ export function test_setTimeout_extraArgs() {
5152
// << (hide)
5253
},
5354
0,
54-
rnd
55+
rnd,
5556
);
5657
// << timer-set-zero-args
5758

@@ -152,6 +153,25 @@ export function test_setInterval_callbackCalledDuringPeriod(done) {
152153
// << timer-set-expression
153154
}
154155

156+
export function test_setInterval_keepsFiringAcrossGarbageCollection(done) {
157+
let counter = 0;
158+
const id = timer.setInterval(() => {
159+
counter++;
160+
if (counter === 2) {
161+
for (let i = 0; i < 3; i++) {
162+
Utils.GC();
163+
if (__ANDROID__) {
164+
java.lang.System.gc();
165+
java.lang.System.runFinalization();
166+
}
167+
}
168+
} else if (counter === 4) {
169+
timer.clearInterval(id);
170+
done(null);
171+
}
172+
}, 20);
173+
}
174+
155175
export function test_setInterval_callbackCalledWithExtraArgs(done) {
156176
let counter: number = 0;
157177
const rnd: number = Math.random();
@@ -168,7 +188,7 @@ export function test_setInterval_callbackCalledWithExtraArgs(done) {
168188
}
169189
},
170190
250,
171-
rnd
191+
rnd,
172192
);
173193
}
174194

‎apps/automated/src/ui/list-picker/list-picker-tests.ts‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as TKUnit from '../../tk-unit';
22
import * as helper from '../../ui-helper';
3-
import { View, Application } from '@nativescript/core';
3+
import { View, Application, Utils } from '@nativescript/core';
44
import * as listPickerTestsNative from './list-picker-tests-native';
55

66
// >> article-require-listpicker-module
@@ -200,7 +200,7 @@ export var test_Android_WhenItemsAreEmptyNativeControlDoesNotShowZero = function
200200
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<View>) {
201201
var listPicker = <listPickerModule.ListPicker>views[0];
202202
var expectedValue = ' ';
203-
var actualValue = (listPicker.nativeViewProtected as any).editText.getText().toString();
203+
var actualValue = (listPicker as any)._editText.getText().toString();
204204
TKUnit.assertEqual(actualValue, expectedValue);
205205
});
206206
};
@@ -214,11 +214,30 @@ export var test_Android_WhenBoundToSingleElementArrayEditTextIsUpdatedProperly =
214214
var listPicker = <listPickerModule.ListPicker>views[0];
215215
listPicker.items = ['One'];
216216
var expectedValue = 'One';
217-
var actualValue = (listPicker.nativeViewProtected as any).editText.getText().toString();
217+
var actualValue = (listPicker as any)._editText.getText().toString();
218218
TKUnit.assertEqual(actualValue, expectedValue);
219219
});
220220
};
221221

222+
export function test_Android_EditTextIsUpdatedAfterGarbageCollection() {
223+
if (!Application.android) {
224+
return;
225+
}
226+
227+
helper.buildUIAndRunTest(_createListPicker(), function (views: Array<View>) {
228+
const listPicker = <listPickerModule.ListPicker>views[0];
229+
listPicker.items = ['One', 'Two'];
230+
for (let i = 0; i < 3; i++) {
231+
Utils.GC();
232+
java.lang.System.gc();
233+
java.lang.System.runFinalization();
234+
TKUnit.wait(0.05);
235+
}
236+
listPicker.selectedIndex = 1;
237+
TKUnit.assertEqual((listPicker as any)._editText.getText().toString(), 'Two');
238+
});
239+
}
240+
222241
export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = function () {
223242
if (!Application.android) {
224243
return;
@@ -229,7 +248,7 @@ export var test_Android_WhenSelectedIndexChangesEditTextIsUpdatedProperly = func
229248
listPicker.items = ['One', 'Two'];
230249
listPicker.selectedIndex = 1;
231250
var expectedValue = 'Two';
232-
var actualValue = (listPicker.nativeViewProtected as any).editText.getText().toString();
251+
var actualValue = (listPicker as any)._editText.getText().toString();
233252
TKUnit.assertEqual(actualValue, expectedValue);
234253
});
235254
};

‎packages/core/application/application.android.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,6 @@ const BroadcastReceiver = lazy(() => {
461461
constructor(onReceiveCallback: (context: android.content.Context, intent: android.content.Intent) => void) {
462462
super();
463463
this._onReceiveCallback = onReceiveCallback;
464-
465-
return global.__native(this);
466464
}
467465

468466
public onReceive(context: android.content.Context, intent: android.content.Intent) {
@@ -1335,8 +1333,6 @@ function ensureNativeClasses() {
13351333
class TNSAccessibilityDelegateImpl extends AccessibilityDelegate {
13361334
constructor() {
13371335
super();
1338-
1339-
return global.__native(this);
13401336
}
13411337

13421338
private getTnsView(androidView: android.view.View) {

‎packages/core/css-mediaquery/index.spec.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ describe('css-mediaquery', () => {
1818
features: [],
1919
},
2020
]);
21+
22+
expect(parseQuery('TV')).toEqual([
23+
{
24+
inverse: false,
25+
type: 'tv',
26+
features: [],
27+
},
28+
]);
29+
30+
expect(parseQuery('not speech')).toEqual([
31+
{
32+
inverse: true,
33+
type: 'speech',
34+
features: [],
35+
},
36+
]);
2137
});
2238

2339
it('should throw a SyntaxError when a media query is invalid', () => {
@@ -128,5 +144,35 @@ describe('css-mediaquery', () => {
128144
expect(matchQuery('not screen and (min-width: 48px)', { width: 24 })).toBe(true);
129145
});
130146
});
147+
148+
describe('Unknown and deprecated media types', () => {
149+
it('should return false for unknown and deprecated media types', () => {
150+
expect(matchQuery('tv', { type: MediaQueryType.screen })).toBe(false);
151+
expect(matchQuery('speech', { type: MediaQueryType.screen })).toBe(false);
152+
expect(matchQuery('handheld', { type: MediaQueryType.screen })).toBe(false);
153+
expect(matchQuery('projection', { type: MediaQueryType.screen })).toBe(false);
154+
expect(matchQuery('unknown', { type: MediaQueryType.screen })).toBe(false);
155+
expect(matchQuery('only tv', { type: MediaQueryType.screen })).toBe(false);
156+
expect(matchQuery('tv and (min-width: 100px)', { type: MediaQueryType.screen, width: 800 })).toBe(false);
157+
});
158+
159+
it('should return true when negating unknown or deprecated media types with `not`', () => {
160+
expect(matchQuery('not tv', { type: MediaQueryType.screen })).toBe(true);
161+
expect(matchQuery('not speech', { type: MediaQueryType.screen })).toBe(true);
162+
expect(matchQuery('not unknown', { type: MediaQueryType.screen })).toBe(true);
163+
expect(matchQuery('not tv and (min-width: 100px)', { type: MediaQueryType.screen, width: 800 })).toBe(true);
164+
});
165+
166+
it('should treat reserved media type keywords as never-matching (`not all`)', () => {
167+
expect(matchQuery('not only', { type: MediaQueryType.screen })).toBe(false);
168+
expect(matchQuery('not not', { type: MediaQueryType.screen })).toBe(false);
169+
expect(matchQuery('not and', { type: MediaQueryType.screen })).toBe(false);
170+
expect(matchQuery('not or', { type: MediaQueryType.screen })).toBe(false);
171+
expect(matchQuery('not layer', { type: MediaQueryType.screen })).toBe(false);
172+
expect(matchQuery('and', { type: MediaQueryType.screen })).toBe(false);
173+
expect(matchQuery('or', { type: MediaQueryType.screen })).toBe(false);
174+
expect(matchQuery('layer', { type: MediaQueryType.screen })).toBe(false);
175+
});
176+
});
131177
});
132178
});

‎packages/core/css-mediaquery/index.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const RE_MEDIA_QUERY = /^(?:(only|not)?\s*([_a-z][_a-z0-9-]*)|(\([^\)]+\)))(?:\s
1717
RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?\s*$/,
1818
RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?\s*$/;
1919

20+
const RESERVED_MEDIA_TYPES = new Set(['only', 'not', 'and', 'or', 'layer']);
21+
2022
export enum MediaQueryType {
2123
all = 'all',
2224
print = 'print',
@@ -37,7 +39,7 @@ export interface MediaQueryEnvironmentParams {
3739

3840
export interface MediaQueryExpression {
3941
inverse: boolean;
40-
type: MediaQueryType;
42+
type: MediaQueryType | string;
4143
features: MediaQueryFeature[];
4244
}
4345

@@ -135,9 +137,14 @@ export function parseQuery(mediaQuery: string): MediaQueryExpression[] {
135137
const type = captures[2];
136138
const featureString = ((captures[3] || '') + (captures[4] || '')).trim();
137139

140+
const mediaType = type ? type.toLowerCase() : MediaQueryType.all;
141+
if (RESERVED_MEDIA_TYPES.has(mediaType)) {
142+
return { inverse: true, type: MediaQueryType.all, features: [] };
143+
}
144+
138145
const expression: MediaQueryExpression = {
139146
inverse: !!modifier && modifier.toLowerCase() === 'not',
140-
type: MediaQueryType[type ? type.toLowerCase() : 'all'] ?? 'all',
147+
type: mediaType,
141148
features: [],
142149
};
143150

‎packages/core/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/core",
3-
"version": "9.1.5-next.1",
3+
"version": "9.1.5-next.2",
44
"description": "A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.",
55
"type": "module",
66
"main": "index",

‎packages/core/timer/index.android.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb
8686
}
8787

8888
const delay = Math.max(0, nextDueTime - now);
89-
handler.postDelayed(runnable, long(delay));
89+
// Not the enclosing `runnable`: a closure over it is a cycle through the runnable's native counterpart.
90+
handler.postDelayed(timeoutCallbacks[id], long(delay));
9091
}
9192
},
9293
});

‎packages/core/ui/action-bar/index.android.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ function initializeMenuItemClickListener(): void {
6868
class MenuItemClickListenerImpl extends java.lang.Object implements androidx.appcompat.widget.Toolbar.OnMenuItemClickListener {
6969
constructor(public owner: ActionBar) {
7070
super();
71-
72-
return global.__native(this);
7371
}
7472

7573
onMenuItemClick(item: android.view.MenuItem): boolean {

‎packages/core/ui/button/index.android.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ function initializeClickListener(): void {
2727
class ClickListenerImpl extends java.lang.Object implements android.view.View.OnClickListener {
2828
constructor(public owner: Button) {
2929
super();
30-
31-
return global.__native(this);
3230
}
3331

3432
public onClick(v: android.view.View): void {

0 commit comments

Comments
 (0)