Skip to content

fix(android): check for root view on configuration changed #7944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tns-core-modules/application/application-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ function removeCssClass(rootView: View, cssClass: string) {
}

export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void {
if (!rootView) {
return;
}

const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`;
if (!rootView.cssClasses.has(newOrientationCssClass)) {
ORIENTATION_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
Expand All @@ -152,6 +156,10 @@ export function orientationChanged(rootView: View, newOrientation: "portrait" |
}

export function systemAppearanceChanged(rootView: View, newSystemAppearance: "dark" | "light"): void {
if (!rootView) {
return;
}

const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`;
if (!rootView.cssClasses.has(newSystemAppearanceCssClass)) {
SYSTEM_APPEARANCE_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
Expand Down
5 changes: 3 additions & 2 deletions tns-core-modules/application/application.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,12 @@ function initComponentCallbacks() {
}),

onConfigurationChanged: profile("onConfigurationChanged", function (newConfiguration: android.content.res.Configuration) {
const rootView = getRootView();
const newOrientation = getOrientationValue(newConfiguration);

if (androidApp.orientation !== newOrientation) {
androidApp.orientation = newOrientation;
orientationChanged(getRootView(), newOrientation);
orientationChanged(rootView, newOrientation);

notify(<OrientationChangedEventData>{
eventName: orientationChangedEvent,
Expand All @@ -433,7 +434,7 @@ function initComponentCallbacks() {

if (androidApp.systemAppearance !== newSystemAppearance) {
androidApp.systemAppearance = newSystemAppearance;
systemAppearanceChanged(getRootView(), newSystemAppearance);
systemAppearanceChanged(rootView, newSystemAppearance);

notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
Expand Down