FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ios): application.displayedEvent does not depend on trace to fire… · NativeScript/NativeScript@f6f7b51 · GitHub

Commit f6f7b51

Browse files
authored
fix(ios): application.displayedEvent does not depend on trace to fire (#7141)
1 parent 170d2a8 commit f6f7b51

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

‎tests/app/app/app.ts‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ else {
88

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

11-
// Specify custom UIApplicationDelegate.
12-
/*
13-
class MyDelegate extends UIResponder implements UIApplicationDelegate {
14-
public static ObjCProtocols = [UIApplicationDelegate];
15-
16-
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {
17-
console.log("applicationWillFinishLaunchingWithOptions: " + launchOptions)
18-
return true;
19-
}
20-
21-
applicationDidBecomeActive(application: UIApplication): void {
22-
console.log("applicationDidBecomeActive: " + application)
23-
}
24-
}
25-
26-
application.ios.delegate = MyDelegate;
27-
*/
28-
2911
if (application.ios) {
3012
// Observe application notifications.
3113
application.ios.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, (notification: NSNotification) => {
@@ -34,6 +16,18 @@ if (application.ios) {
3416
}
3517

3618
// Common events for both Android and iOS.
19+
application.on(application.displayedEvent, function (args: application.ApplicationEventData) {
20+
(<any>global).isDisplayedEventFired = true;
21+
22+
if (args.android) {
23+
// For Android applications, args.android is an android activity class.
24+
console.log("Activity: " + args.android);
25+
} else if (args.ios) {
26+
// For iOS applications, args.ios is UIApplication.
27+
console.log("UIApplication: " + args.ios);
28+
}
29+
});
30+
3731
application.on(application.launchEvent, function (args: application.ApplicationEventData) {
3832
if (args.android) {
3933
// For Android applications, args.android is an android.content.Intent class.

‎tests/app/application/application-tests-common.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ if (app.android) {
1313

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

16-
export var testInitialized = function () {
16+
export function testInitialized() {
1717
if (platform.device.os === platform.platformNames.android) {
1818
// we have the android defined
1919
TKUnit.assert(app.android, "Application module not properly intialized");
2020
} else if (platform.device.os === platform.platformNames.ios) {
2121
TKUnit.assert(app.ios, "Application module not properly intialized");
2222
}
23-
}
23+
}
24+
25+
export function testDisplayedEvent() {
26+
// global.isDisplayedEventFired flag is set in app.ts application.displayedEvent handler
27+
TKUnit.assert((<any>global).isDisplayedEventFired, "application.displayedEvent not fired");
28+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { createViewFromEntry } from "../ui/builder";
1919
import { ios as iosView, View } from "../ui/core/view";
2020
import { Frame, NavigationEntry } from "../ui/frame";
2121
import * as utils from "../utils/utils";
22-
import { profile, level as profilingLevel, Level } from "../profiling";
22+
import { profile } from "../profiling";
2323

2424
// NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430
2525
// TODO: Refactor the UIResponder to use Typescript extends when this issue is resolved:
@@ -131,7 +131,7 @@ class IOSApplication implements IOSApplicationDefinition {
131131

132132
@profile
133133
private didFinishLaunchingWithOptions(notification: NSNotification) {
134-
if (!displayedOnce && profilingLevel() >= Level.lifecycle) {
134+
if (!displayedOnce) {
135135
displayedLinkTarget = CADisplayLinkTarget.new();
136136
displayedLink = CADisplayLink.displayLinkWithTargetSelector(displayedLinkTarget, "onDisplayed");
137137
displayedLink.addToRunLoopForMode(NSRunLoop.mainRunLoop, NSDefaultRunLoopMode);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL