Skip to content

Commit

Permalink
fix(ios): application.displayedEvent does not depend on trace to fire (
Browse files Browse the repository at this point in the history
  • Loading branch information
manoldonev authored Apr 17, 2019
1 parent f0146f0 commit 4e56c89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
30 changes: 12 additions & 18 deletions tests/app/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@ else {

import * as application from "tns-core-modules/application";

// Specify custom UIApplicationDelegate.
/*
class MyDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {
console.log("applicationWillFinishLaunchingWithOptions: " + launchOptions)
return true;
}
applicationDidBecomeActive(application: UIApplication): void {
console.log("applicationDidBecomeActive: " + application)
}
}
application.ios.delegate = MyDelegate;
*/

if (application.ios) {
// Observe application notifications.
application.ios.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, (notification: NSNotification) => {
Expand All @@ -34,6 +16,18 @@ if (application.ios) {
}

// Common events for both Android and iOS.
application.on(application.displayedEvent, function (args: application.ApplicationEventData) {
(<any>global).isDisplayedEventFired = true;

if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("Activity: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("UIApplication: " + args.ios);
}
});

application.on(application.launchEvent, function (args: application.ApplicationEventData) {
if (args.android) {
// For Android applications, args.android is an android.content.Intent class.
Expand Down
9 changes: 7 additions & 2 deletions tests/app/application/application-tests-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ if (app.android) {

import * as TKUnit from "../TKUnit";

export var testInitialized = function () {
export function testInitialized() {
if (platform.device.os === platform.platformNames.android) {
// we have the android defined
TKUnit.assert(app.android, "Application module not properly intialized");
} else if (platform.device.os === platform.platformNames.ios) {
TKUnit.assert(app.ios, "Application module not properly intialized");
}
}
}

export function testDisplayedEvent() {
// global.isDisplayedEventFired flag is set in app.ts application.displayedEvent handler
TKUnit.assert((<any>global).isDisplayedEventFired, "application.displayedEvent not fired");
}
4 changes: 2 additions & 2 deletions tns-core-modules/application/application.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createViewFromEntry } from "../ui/builder";
import { ios as iosView, View } from "../ui/core/view";
import { Frame, NavigationEntry } from "../ui/frame";
import { ios } from "../utils/utils";
import { profile, level as profilingLevel, Level } from "../profiling";
import { profile } from "../profiling";

const getVisibleViewController = ios.getVisibleViewController;

Expand Down Expand Up @@ -133,7 +133,7 @@ class IOSApplication implements IOSApplicationDefinition {

@profile
private didFinishLaunchingWithOptions(notification: NSNotification) {
if (!displayedOnce && profilingLevel() >= Level.lifecycle) {
if (!displayedOnce) {
displayedLinkTarget = CADisplayLinkTarget.new();
displayedLink = CADisplayLink.displayLinkWithTargetSelector(displayedLinkTarget, "onDisplayed");
displayedLink.addToRunLoopForMode(NSRunLoop.mainRunLoop, NSDefaultRunLoopMode);
Expand Down

0 comments on commit 4e56c89

Please sign in to comment.