| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ import { UnhandledErrorEventData, iOSApplication, AndroidApplication, CssChanged | |||
| 21 | 21 | ||
| 22 | 22 | export const launchEvent = "launch"; | |
| 23 | 23 | export const suspendEvent = "suspend"; | |
| 24 | + export const displayedEvent = "displayed"; | ||
| 24 | 25 | export const resumeEvent = "resume"; | |
| 25 | 26 | export const exitEvent = "exit"; | |
| 26 | 27 | export const lowMemoryEvent = "lowMemory"; | |
@@ -45,6 +46,7 @@ export let ios = undefined; | |||
| 45 | 46 | export const on: typeof events.on = events.on.bind(events); | |
| 46 | 47 | export const off: typeof events.off = events.off.bind(events); | |
| 47 | 48 | export const notify: typeof events.notify = events.notify.bind(events); | |
| 49 | + export const hasListeners: typeof events.hasListeners = events.hasListeners.bind(events); | ||
| 48 | 50 | ||
| 49 | 51 | let app: iOSApplication | AndroidApplication; | |
| 50 | 52 | export function setApplication(instance: iOSApplication | AndroidApplication): void { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ | |||
| 4 | 4 | } from "."; | |
| 5 | 5 | ||
| 6 | 6 | import { | |
| 7 | - notify, lowMemoryEvent, orientationChangedEvent, suspendEvent, resumeEvent, | ||
| 7 | + notify, hasListeners, lowMemoryEvent, orientationChangedEvent, suspendEvent, resumeEvent, displayedEvent, | ||
| 8 | 8 | setApplication, livesync, Observable | |
| 9 | 9 | } from "./application-common"; | |
| 10 | 10 | ||
@@ -181,7 +181,19 @@ function initLifecycleCallbacks() { | |||
| 181 | 181 | androidApp.startActivity = activity; | |
| 182 | 182 | } | |
| 183 | 183 | ||
| 184 | - androidApp.notify(<AndroidActivityBundleEventData>{ eventName: ActivityCreated, object: androidApp, activity: activity, bundle: savedInstanceState }); | ||
| 184 | + androidApp.notify(<AndroidActivityBundleEventData>{ eventName: ActivityCreated, object: androidApp, activity, bundle: savedInstanceState }); | ||
| 185 | + | ||
| 186 | + if (hasListeners(displayedEvent)) { | ||
| 187 | + let rootView = activity.findViewById((<any>android).R.id.content); | ||
| 188 | + let onGlobalLayoutListener = new android.view.ViewTreeObserver.OnGlobalLayoutListener({ | ||
| 189 | + onGlobalLayout() { | ||
| 190 | + notify({ eventName: displayedEvent, object: androidApp, activity }); | ||
| 191 | + let viewTreeObserver = rootView.getViewTreeObserver(); | ||
| 192 | + viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener); | ||
| 193 | + } | ||
| 194 | + }); | ||
| 195 | + rootView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); | ||
| 196 | + } | ||
| 185 | 197 | }, | |
| 186 | 198 | ||
| 187 | 199 | onActivityDestroyed: function (activity: android.app.Activity) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,11 @@ import { NavigationEntry, View, Observable, EventData } from "../ui/frame"; | |||
| 11 | 11 | */ | |
| 12 | 12 | export var launchEvent: string; | |
| 13 | 13 | ||
| 14 | + /** | ||
| 15 | + * String value used when hooking to displayed event. | ||
| 16 | + */ | ||
| 17 | + export var displayedEvent: string; | ||
| 18 | + | ||
| 14 | 19 | /** | |
| 15 | 20 | * String value used when hooking to uncaughtError event. | |
| 16 | 21 | */ | |
@@ -189,6 +194,13 @@ export function hasListeners(eventName: string): boolean; | |||
| 189 | 194 | */ | |
| 190 | 195 | export function on(event: "launch", callback: (args: LaunchEventData) => void, thisArg?: any); | |
| 191 | 196 | ||
| 197 | + /** | ||
| 198 | + * This event is raised after the application has performed most of its startup actions. | ||
| 199 | + * Its intent is to be suitable for measuring app startup times. | ||
| 200 | + * @experimental | ||
| 201 | + */ | ||
| 202 | + export function on(event: "displayed", callback: (args: EventData) => void, thisArg?: any); | ||
| 203 | + | ||
| 192 | 204 | /** | |
| 193 | 205 | * This event is raised when the Application is suspended. | |
| 194 | 206 | */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import { | |
| 4 | 4 | notify, launchEvent, resumeEvent, suspendEvent, exitEvent, lowMemoryEvent, | |
| 5 | - orientationChangedEvent, setApplication, livesync | ||
| 5 | + orientationChangedEvent, setApplication, livesync, displayedEvent | ||
| 6 | 6 | } from "./application-common"; | |
| 7 | 7 | ||
| 8 | 8 | // First reexport so that app module is initialized. | |
@@ -16,6 +16,8 @@ class Responder extends UIResponder { | |||
| 16 | 16 | // | |
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | + let displayedOnce = false; | ||
| 20 | + | ||
| 19 | 21 | class Window extends UIWindow { | |
| 20 | 22 | public content; | |
| 21 | 23 | ||
@@ -138,7 +140,13 @@ class IOSApplication implements IOSApplicationDefinition { | |||
| 138 | 140 | } | |
| 139 | 141 | ||
| 140 | 142 | private didBecomeActive(notification: NSNotification) { | |
| 141 | - notify(<ApplicationEventData>{ eventName: resumeEvent, object: this, ios: utils.ios.getter(UIApplication, UIApplication.sharedApplication) }); | ||
| 143 | + let ios = utils.ios.getter(UIApplication, UIApplication.sharedApplication); | ||
| 144 | + let object = this; | ||
| 145 | + notify(<ApplicationEventData>{ eventName: resumeEvent, object, ios }); | ||
| 146 | + if (!displayedOnce) { | ||
| 147 | + notify(<ApplicationEventData>{ eventName: displayedEvent, object, ios }); | ||
| 148 | + displayedOnce = true; | ||
| 149 | + } | ||
| 142 | 150 | } | |
| 143 | 151 | ||
| 144 | 152 | private didEnterBackground(notification: NSNotification) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments