From 82e9c67d3398c376be1641c5f23bf82a492a48c3 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Sat, 25 Nov 2023 19:04:01 +0000 Subject: [PATCH] feat(core): initRootView event (#10442) launchEvent is not triggered at the same moment on iOS and Android. iOS is firing after setting the rootView while Android is firing before. Consequently if you need an event for when the rootView is set (to read/write root css variables) you need this event. [skip ci] --- packages/core/application/application-common.ts | 4 +++- packages/core/application/application-interfaces.ts | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/application/application-common.ts b/packages/core/application/application-common.ts index 8ee5aaf23..71a76c522 100644 --- a/packages/core/application/application-common.ts +++ b/packages/core/application/application-common.ts @@ -12,7 +12,7 @@ import type { Frame } from '../ui/frame'; import type { NavigationEntry } from '../ui/frame/frame-interfaces'; import type { StyleScope } from '../ui/styling/style-scope'; import type { AndroidApplication as IAndroidApplication, iOSApplication as IiOSApplication } from './'; -import type { ApplicationEventData, CssChangedEventData, DiscardedErrorEventData, FontScaleChangedEventData, LaunchEventData, LoadAppCSSEventData, NativeScriptError, OrientationChangedEventData, SystemAppearanceChangedEventData, UnhandledErrorEventData } from './application-interfaces'; +import type { ApplicationEventData, CssChangedEventData, DiscardedErrorEventData, FontScaleChangedEventData, InitRootViewEventData, LaunchEventData, LoadAppCSSEventData, NativeScriptError, OrientationChangedEventData, SystemAppearanceChangedEventData, UnhandledErrorEventData } from './application-interfaces'; // prettier-ignore const ORIENTATION_CSS_CLASSES = [ @@ -125,6 +125,7 @@ export class ApplicationCommon { readonly livesyncEvent = 'livesync'; readonly loadAppCssEvent = 'loadAppCss'; readonly cssChangedEvent = 'cssChanged'; + readonly initRootViewEvent = 'initRootView'; // Expose statically for backwards compat on AndroidApplication.on etc. /** @@ -368,6 +369,7 @@ export class ApplicationCommon { this.setRootViewCSSClasses(rootView); initAccessibilityCssHelper(); initAccessibilityFontScale(); + this.notify({ eventName: this.initRootViewEvent, rootView }); } /** diff --git a/packages/core/application/application-interfaces.ts b/packages/core/application/application-interfaces.ts index 4580b36e2..a56c212ab 100644 --- a/packages/core/application/application-interfaces.ts +++ b/packages/core/application/application-interfaces.ts @@ -117,6 +117,13 @@ export interface CssChangedEventData extends ApplicationEventData { cssText?: string; } +/** + * Event data containing information about application css change. + */ +export interface InitRootViewEventData extends ApplicationEventData { + rootView: View; +} + /** * Data for the Android activity events. */