From 539fd1eb293241dc067bfdcc77613b0eb67b099f Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Mon, 16 Nov 2020 06:57:58 +0100 Subject: [PATCH 1/3] fix(core): notify object now optional (#9032) --- packages/core/data/observable/index.d.ts | 9 ++++++++- packages/core/data/observable/index.ts | 15 +++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/core/data/observable/index.d.ts b/packages/core/data/observable/index.d.ts index 77c0f19ed..4cb017139 100644 --- a/packages/core/data/observable/index.d.ts +++ b/packages/core/data/observable/index.d.ts @@ -12,6 +12,13 @@ export interface EventData { object: Observable; } + +export interface NotifyData extends Partial { + eventName: string; + object?: Observable; +} + + /** * Data for the "propertyChange" event. */ @@ -136,7 +143,7 @@ export class Observable { * Notifies all the registered listeners for the event provided in the data.eventName. * @param data The data associated with the event. */ - notify(data: T): void; + notify(data: T): void; /** * Notifies all the registered listeners for the property change event. diff --git a/packages/core/data/observable/index.ts b/packages/core/data/observable/index.ts index 4b198d7df..64e8026ce 100644 --- a/packages/core/data/observable/index.ts +++ b/packages/core/data/observable/index.ts @@ -5,6 +5,11 @@ export interface EventData { object: Observable; } +export interface NotifyData extends Partial { + eventName: string; + object?: Observable; +} + export interface PropertyChangeData extends EventData { propertyName: string; value: any; @@ -262,16 +267,18 @@ export class Observable implements ObservableDefinition { } } - public notify(data: T): void { + public notify(data: T): void { + const eventData = data as EventData; + eventData.object = eventData.object || this; const eventClass = this.constructor.name; - this._globalNotify(eventClass, 'First', data); + this._globalNotify(eventClass, 'First', eventData); const observers = >this._observers[data.eventName]; if (observers) { - Observable._handleEvent(observers, data); + Observable._handleEvent(observers, eventData); } - this._globalNotify(eventClass, '', data); + this._globalNotify(eventClass, '', eventData); } private static _handleEvent(observers: Array, data: T): void { From 1769de903392ab14ffb6c366ab86dc24b5289e81 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Thu, 19 Nov 2020 18:07:51 -0300 Subject: [PATCH 2/3] feat(android): setInterval closer to web spec (#9044) --- apps/automated/src/timer/timer-tests.ts | 34 +++++++++++++++++++++++++ packages/core/timer/index.android.ts | 8 ++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/apps/automated/src/timer/timer-tests.ts b/apps/automated/src/timer/timer-tests.ts index 99c633828..4f8f10bbb 100644 --- a/apps/automated/src/timer/timer-tests.ts +++ b/apps/automated/src/timer/timer-tests.ts @@ -171,6 +171,40 @@ export function test_setInterval_callbackCalledWithExtraArgs(done) { ); } +export function test_setInterval_callbackNotDelayedByBusyWork() { + let calls = 0; + + let firstCall = true; + const id = timer.setInterval(() => { + calls++; + if (firstCall) { + firstCall = false; + TKUnit.wait(0.025); + } + }, 50); + + TKUnit.wait(0.11); + timer.clearInterval(id); + TKUnit.assertEqual(calls, 2, 'Callback should be called multiple times with busy wait'); +} + +export function test_setInterval_callbackSkippedByBusyWork() { + let calls = 0; + + let firstCall = true; + const id = timer.setInterval(() => { + calls++; + if (firstCall) { + firstCall = false; + TKUnit.wait(0.051); + } + }, 50); + + TKUnit.wait(0.16); + timer.clearInterval(id); + TKUnit.assertEqual(calls, 2, 'Callback should be called skipped when it takes too long to process'); +} + export function test_setInterval_callbackShouldBeCleared(done) { const start = TKUnit.time(); // >> timer-set-interval diff --git a/packages/core/timer/index.android.ts b/packages/core/timer/index.android.ts index 06d42d958..8bf793113 100644 --- a/packages/core/timer/index.android.ts +++ b/packages/core/timer/index.android.ts @@ -58,12 +58,16 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb const handler = timeoutHandler; const invoke = () => callback(...args); const zoneBound = zonedCallback(invoke); + const startOffset = milliseconds > 0 ? Date.now() % milliseconds : 0; + function nextCallMs() { + return milliseconds > 0 ? milliseconds - ((Date.now() - startOffset) % milliseconds) : milliseconds; + } const runnable = new java.lang.Runnable({ run: () => { zoneBound(); if (timeoutCallbacks[id]) { - handler.postDelayed(runnable, long(milliseconds)); + handler.postDelayed(runnable, long(nextCallMs())); } }, }); @@ -72,7 +76,7 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb timeoutCallbacks[id] = runnable; } - timeoutHandler.postDelayed(runnable, long(milliseconds)); + timeoutHandler.postDelayed(runnable, long(nextCallMs())); return id; } From bd7c686aaf55d26b2b483905bd5e0a453429cabd Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Thu, 19 Nov 2020 22:02:32 -0300 Subject: [PATCH 3/3] feat(core): allow app to start without a root view (#9056) --- packages/core/application/application-interfaces.ts | 2 +- packages/core/application/index.android.ts | 2 +- packages/core/application/index.d.ts | 3 ++- packages/core/application/index.ios.ts | 4 +++- packages/core/ui/frame/index.android.ts | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/core/application/application-interfaces.ts b/packages/core/application/application-interfaces.ts index 9427f68a4..13ea7fa5c 100644 --- a/packages/core/application/application-interfaces.ts +++ b/packages/core/application/application-interfaces.ts @@ -20,7 +20,7 @@ export interface ApplicationEventData extends EventData { } export interface LaunchEventData extends ApplicationEventData { - root?: View; + root?: View | null; savedInstanceState?: any /* android.os.Bundle */; } diff --git a/packages/core/application/index.android.ts b/packages/core/application/index.android.ts index c3dbacd38..50ce16597 100644 --- a/packages/core/application/index.android.ts +++ b/packages/core/application/index.android.ts @@ -191,7 +191,7 @@ export function addCss(cssText: string, attributeScoped?: boolean): void { const CALLBACKS = '_callbacks'; export function _resetRootView(entry?: NavigationEntry | string): void { - const activity = androidApp.foregroundActivity; + const activity = androidApp.foregroundActivity || androidApp.startActivity; if (!activity) { throw new Error('Cannot find android activity.'); } diff --git a/packages/core/application/index.d.ts b/packages/core/application/index.d.ts index d2cb041a4..07416d5f8 100644 --- a/packages/core/application/index.d.ts +++ b/packages/core/application/index.d.ts @@ -103,8 +103,9 @@ export interface LaunchEventData extends ApplicationEventData { /** * The root view for this Window on iOS or Activity for Android. * If not set a new Frame will be created as a root view in order to maintain backwards compatibility. + * If explicitly set to null, there will be no root view. */ - root?: View; + root?: View | null; savedInstanceState?: any /* android.os.Bundle */; } diff --git a/packages/core/application/index.ios.ts b/packages/core/application/index.ios.ts index e502b4758..f36cafb70 100644 --- a/packages/core/application/index.ios.ts +++ b/packages/core/application/index.ios.ts @@ -207,7 +207,9 @@ export class iOSApplication implements iOSApplicationDefinition { // this._window will be undefined when NS app is embedded in a native one if (this._window) { - this.setWindowContent(args.root); + if (args.root !== null) { + this.setWindowContent(args.root); + } } else { this._window = UIApplication.sharedApplication.delegate.window; } diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts index 9203131ee..ccfc3a918 100644 --- a/packages/core/ui/frame/index.android.ts +++ b/packages/core/ui/frame/index.android.ts @@ -1301,13 +1301,19 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks { if (!rootView) { const mainEntry = application.getMainEntry(); const intent = activity.getIntent(); + // useful for integrations that would like to set rootView asynchronously after app launch + let shouldRootViewBeEmpty = false; if (fireLaunchEvent) { // entry point for Angular and Vue frameworks rootView = notifyLaunch(intent, savedInstanceState, null); + shouldRootViewBeEmpty = rootView === null; } if (!rootView) { + if (shouldRootViewBeEmpty) { + return; + } // entry point for NS Core if (!mainEntry) { // Also handles scenarios with Angular and Vue where the notifyLaunch didn't return a root view.