mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(android): check for root view on configuration changed (#7944)
This commit is contained in:

committed by
Manol Donev

parent
08e23bcc3b
commit
135aeffdf1
@ -143,6 +143,10 @@ function removeCssClass(rootView: View, cssClass: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void {
|
export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void {
|
||||||
|
if (!rootView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`;
|
const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`;
|
||||||
if (!rootView.cssClasses.has(newOrientationCssClass)) {
|
if (!rootView.cssClasses.has(newOrientationCssClass)) {
|
||||||
ORIENTATION_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
|
ORIENTATION_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
|
||||||
@ -152,6 +156,10 @@ export function orientationChanged(rootView: View, newOrientation: "portrait" |
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function systemAppearanceChanged(rootView: View, newSystemAppearance: "dark" | "light"): void {
|
export function systemAppearanceChanged(rootView: View, newSystemAppearance: "dark" | "light"): void {
|
||||||
|
if (!rootView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`;
|
const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`;
|
||||||
if (!rootView.cssClasses.has(newSystemAppearanceCssClass)) {
|
if (!rootView.cssClasses.has(newSystemAppearanceCssClass)) {
|
||||||
SYSTEM_APPEARANCE_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
|
SYSTEM_APPEARANCE_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
|
||||||
|
@ -413,11 +413,12 @@ function initComponentCallbacks() {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
onConfigurationChanged: profile("onConfigurationChanged", function (newConfiguration: android.content.res.Configuration) {
|
onConfigurationChanged: profile("onConfigurationChanged", function (newConfiguration: android.content.res.Configuration) {
|
||||||
|
const rootView = getRootView();
|
||||||
const newOrientation = getOrientationValue(newConfiguration);
|
const newOrientation = getOrientationValue(newConfiguration);
|
||||||
|
|
||||||
if (androidApp.orientation !== newOrientation) {
|
if (androidApp.orientation !== newOrientation) {
|
||||||
androidApp.orientation = newOrientation;
|
androidApp.orientation = newOrientation;
|
||||||
orientationChanged(getRootView(), newOrientation);
|
orientationChanged(rootView, newOrientation);
|
||||||
|
|
||||||
notify(<OrientationChangedEventData>{
|
notify(<OrientationChangedEventData>{
|
||||||
eventName: orientationChangedEvent,
|
eventName: orientationChangedEvent,
|
||||||
@ -433,7 +434,7 @@ function initComponentCallbacks() {
|
|||||||
|
|
||||||
if (androidApp.systemAppearance !== newSystemAppearance) {
|
if (androidApp.systemAppearance !== newSystemAppearance) {
|
||||||
androidApp.systemAppearance = newSystemAppearance;
|
androidApp.systemAppearance = newSystemAppearance;
|
||||||
systemAppearanceChanged(getRootView(), newSystemAppearance);
|
systemAppearanceChanged(rootView, newSystemAppearance);
|
||||||
|
|
||||||
notify(<SystemAppearanceChangedEventData>{
|
notify(<SystemAppearanceChangedEventData>{
|
||||||
eventName: systemAppearanceChangedEvent,
|
eventName: systemAppearanceChangedEvent,
|
||||||
|
Reference in New Issue
Block a user