fix(ios): embed systemAppearance handling (#10219)

This commit is contained in:
Nathan Walker
2023-02-20 21:03:59 -08:00
committed by GitHub
parent fd35d6c19c
commit ee92512746

View File

@@ -206,6 +206,19 @@ export class iOSApplication implements iOSApplicationDefinition {
return this._rootView; return this._rootView;
} }
public setSystemAppearance(value: 'light' | 'dark' | null) {
if (this.systemAppearance !== value) {
this._systemAppearance = value;
systemAppearanceChanged(this.rootView, value);
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: iosApp.systemAppearance,
object: this,
});
}
}
public addNotificationObserver(notificationName: string, onReceiveCallback: (notification: NSNotification) => void): NotificationObserver { public addNotificationObserver(notificationName: string, onReceiveCallback: (notification: NSNotification) => void): NotificationObserver {
const observer = NotificationObserver.initWithCallback(onReceiveCallback); const observer = NotificationObserver.initWithCallback(onReceiveCallback);
NSNotificationCenter.defaultCenter.addObserverSelectorNameObject(observer, 'onReceive', notificationName, null); NSNotificationCenter.defaultCenter.addObserverSelectorNameObject(observer, 'onReceive', notificationName, null);
@@ -376,17 +389,7 @@ export class iOSApplication implements iOSApplicationDefinition {
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle; const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle); const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
if (this._systemAppearance !== newSystemAppearance) { this.setSystemAppearance(newSystemAppearance);
this._systemAppearance = newSystemAppearance;
systemAppearanceChanged(rootView, newSystemAppearance);
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: this._systemAppearance,
object: this,
});
}
}); });
} }
} }
@@ -475,16 +478,7 @@ export function run(entry?: string | NavigationEntry) {
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle; const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle); const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
if (this._systemAppearance !== newSystemAppearance) { iosApp.setSystemAppearance(newSystemAppearance);
this._systemAppearance = newSystemAppearance;
notify(<SystemAppearanceChangedEventData>{
eventName: systemAppearanceChangedEvent,
ios: this,
newValue: this._systemAppearance,
object: this,
});
}
}); });
iosApp.notifyAppStarted(); iosApp.notifyAppStarted();
} }