mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
feat(css-classes): add system appearance CSS class to modal root view
This commit is contained in:
@ -41,7 +41,13 @@ import {
|
|||||||
UnhandledErrorEventData
|
UnhandledErrorEventData
|
||||||
} from "./application";
|
} from "./application";
|
||||||
|
|
||||||
import { CLASS_PREFIX, pushToRootViewCssClasses, removeFromRootViewCssClasses } from "../css/system-classes";
|
import {
|
||||||
|
CLASS_PREFIX,
|
||||||
|
pushToRootViewCssClasses,
|
||||||
|
removeFromModalRootViewCssClasses,
|
||||||
|
removeFromRootViewCssClasses,
|
||||||
|
pushToModalRootViewCssClasses
|
||||||
|
} from "../css/system-classes";
|
||||||
import { DeviceOrientation, SystemAppearance } from "../ui/enums/enums";
|
import { DeviceOrientation, SystemAppearance } from "../ui/enums/enums";
|
||||||
|
|
||||||
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
||||||
@ -133,11 +139,13 @@ export function loadAppCss(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function applyCssClass(rootView: View, cssClass: string) {
|
function applyCssClass(rootView: View, cssClass: string) {
|
||||||
|
pushToModalRootViewCssClasses(cssClass);
|
||||||
pushToRootViewCssClasses(cssClass);
|
pushToRootViewCssClasses(cssClass);
|
||||||
rootView.cssClasses.add(cssClass);
|
rootView.cssClasses.add(cssClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeCssClass(rootView: View, cssClass: string) {
|
function removeCssClass(rootView: View, cssClass: string) {
|
||||||
|
removeFromModalRootViewCssClasses(cssClass);
|
||||||
removeFromRootViewCssClasses(cssClass);
|
removeFromRootViewCssClasses(cssClass);
|
||||||
rootView.cssClasses.delete(cssClass);
|
rootView.cssClasses.delete(cssClass);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import { Builder } from "../ui/builder";
|
|||||||
import {
|
import {
|
||||||
CLASS_PREFIX,
|
CLASS_PREFIX,
|
||||||
getRootViewCssClasses,
|
getRootViewCssClasses,
|
||||||
|
pushToModalRootViewCssClasses,
|
||||||
pushToRootViewCssClasses
|
pushToRootViewCssClasses
|
||||||
} from "../css/system-classes";
|
} from "../css/system-classes";
|
||||||
|
|
||||||
@ -496,6 +497,7 @@ function setRootViewCssClasses(rootView: View): void {
|
|||||||
function setRootViewSystemAppearanceCssClass(rootView: View): void {
|
function setRootViewSystemAppearanceCssClass(rootView: View): void {
|
||||||
if (majorVersion >= 13) {
|
if (majorVersion >= 13) {
|
||||||
const systemAppearanceCssClass = `${CLASS_PREFIX}${iosApp.systemAppearance}`;
|
const systemAppearanceCssClass = `${CLASS_PREFIX}${iosApp.systemAppearance}`;
|
||||||
|
pushToModalRootViewCssClasses(systemAppearanceCssClass);
|
||||||
pushToRootViewCssClasses(systemAppearanceCssClass);
|
pushToRootViewCssClasses(systemAppearanceCssClass);
|
||||||
rootView.cssClasses.add(systemAppearanceCssClass);
|
rootView.cssClasses.add(systemAppearanceCssClass);
|
||||||
}
|
}
|
||||||
|
10
nativescript-core/css/system-classes.d.ts
vendored
10
nativescript-core/css/system-classes.d.ts
vendored
@ -10,7 +10,7 @@ export const CLASS_PREFIX: string;
|
|||||||
/**
|
/**
|
||||||
* Gets CSS system class for modal root view.
|
* Gets CSS system class for modal root view.
|
||||||
*/
|
*/
|
||||||
export function getModalRootViewCssClass(): string;
|
export function getModalRootViewCssClasses(): string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets CSS system classes for root view.
|
* Gets CSS system classes for root view.
|
||||||
@ -18,7 +18,13 @@ export function getModalRootViewCssClass(): string;
|
|||||||
export function getRootViewCssClasses(): string[];
|
export function getRootViewCssClasses(): string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends new CSS class to the system classes and returns the new length of the array.
|
* Appends new CSS class to the modal root view system classes and returns the new length of the array.
|
||||||
|
* @param value New CSS system class.
|
||||||
|
*/
|
||||||
|
export function pushToModalRootViewCssClasses(value: string): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends new CSS class to the root view system classes and returns the new length of the array.
|
||||||
* @param value New CSS system class.
|
* @param value New CSS system class.
|
||||||
*/
|
*/
|
||||||
export function pushToRootViewCssClasses(value: string): number;
|
export function pushToRootViewCssClasses(value: string): number;
|
||||||
|
@ -3,30 +3,42 @@ const ROOT = "root";
|
|||||||
|
|
||||||
export const CLASS_PREFIX = "ns-";
|
export const CLASS_PREFIX = "ns-";
|
||||||
|
|
||||||
const modalRootViewCssClass = `${CLASS_PREFIX}${MODAL}`;
|
const modalRootViewCssClasses = [`${CLASS_PREFIX}${MODAL}`];
|
||||||
const rootViewCssClasses = [`${CLASS_PREFIX}${ROOT}`];
|
const rootViewCssClasses = [`${CLASS_PREFIX}${ROOT}`];
|
||||||
|
|
||||||
export function getModalRootViewCssClass(): string {
|
function removeFromCssClasses(cssClasses: string[], value: string) {
|
||||||
return modalRootViewCssClass;
|
const index = cssClasses.indexOf(value);
|
||||||
|
let removedElement;
|
||||||
|
if (index > -1) {
|
||||||
|
removedElement = cssClasses.splice(index, 1);
|
||||||
|
}
|
||||||
|
return removedElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getModalRootViewCssClasses(): string[] {
|
||||||
|
return modalRootViewCssClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRootViewCssClasses(): string[] {
|
export function getRootViewCssClasses(): string[] {
|
||||||
return rootViewCssClasses;
|
return rootViewCssClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function pushToModalRootViewCssClasses(value: string): number {
|
||||||
|
modalRootViewCssClasses.push(value);
|
||||||
|
|
||||||
|
return rootViewCssClasses.length;
|
||||||
|
}
|
||||||
|
|
||||||
export function pushToRootViewCssClasses(value: string): number {
|
export function pushToRootViewCssClasses(value: string): number {
|
||||||
rootViewCssClasses.push(value);
|
rootViewCssClasses.push(value);
|
||||||
|
|
||||||
return rootViewCssClasses.length;
|
return rootViewCssClasses.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeFromModalRootViewCssClasses(value: string): string {
|
||||||
|
return removeFromCssClasses(modalRootViewCssClasses, value);
|
||||||
|
}
|
||||||
|
|
||||||
export function removeFromRootViewCssClasses(value: string): string {
|
export function removeFromRootViewCssClasses(value: string): string {
|
||||||
const index = rootViewCssClasses.indexOf(value);
|
return removeFromCssClasses(rootViewCssClasses, value);
|
||||||
let removedElement;
|
|
||||||
|
|
||||||
if (index > -1) {
|
|
||||||
removedElement = rootViewCssClasses.splice(index, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return removedElement;
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { Page } from "../../page";
|
|||||||
|
|
||||||
// Types.
|
// Types.
|
||||||
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, Style, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from "../properties";
|
import { Property, CssProperty, CssAnimationProperty, InheritedProperty, Style, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, initNativeView } from "../properties";
|
||||||
import { getModalRootViewCssClass, getRootViewCssClasses } from "../../../css/system-classes";
|
import { getModalRootViewCssClasses, getRootViewCssClasses } from "../../../css/system-classes";
|
||||||
import { Source } from "../../../utils/debug";
|
import { Source } from "../../../utils/debug";
|
||||||
import { Binding, BindingOptions, Observable, WrappedValue, PropertyChangeData, traceEnabled, traceWrite, traceCategories } from "../bindable";
|
import { Binding, BindingOptions, Observable, WrappedValue, PropertyChangeData, traceEnabled, traceWrite, traceCategories } from "../bindable";
|
||||||
import { isIOS, isAndroid } from "../../../platform";
|
import { isIOS, isAndroid } from "../../../platform";
|
||||||
@ -1040,16 +1040,16 @@ export const classNameProperty = new Property<ViewBase, string>({
|
|||||||
valueChanged(view: ViewBase, oldValue: string, newValue: string) {
|
valueChanged(view: ViewBase, oldValue: string, newValue: string) {
|
||||||
const cssClasses = view.cssClasses;
|
const cssClasses = view.cssClasses;
|
||||||
|
|
||||||
const modalViewCssClass = getModalRootViewCssClass();
|
const modalViewCssClasses = getModalRootViewCssClasses();
|
||||||
const rootViewCssClasses = getRootViewCssClasses();
|
const rootViewCssClasses = getRootViewCssClasses();
|
||||||
|
|
||||||
const shouldAddModalRootViewCssClass = cssClasses.has(modalViewCssClass);
|
const shouldAddModalRootViewCssClasses = cssClasses.has(modalViewCssClasses[0]);
|
||||||
const shouldAddRootViewCssClasses = cssClasses.has(rootViewCssClasses[0]);
|
const shouldAddRootViewCssClasses = cssClasses.has(rootViewCssClasses[0]);
|
||||||
|
|
||||||
cssClasses.clear();
|
cssClasses.clear();
|
||||||
|
|
||||||
if (shouldAddModalRootViewCssClass) {
|
if (shouldAddModalRootViewCssClasses) {
|
||||||
cssClasses.add(modalViewCssClass);
|
modalViewCssClasses.forEach(c => cssClasses.add(c));
|
||||||
} else if (shouldAddRootViewCssClasses) {
|
} else if (shouldAddRootViewCssClasses) {
|
||||||
rootViewCssClasses.forEach(c => cssClasses.add(c));
|
rootViewCssClasses.forEach(c => cssClasses.add(c));
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
fromString as gestureFromString
|
fromString as gestureFromString
|
||||||
} from "../../gestures";
|
} from "../../gestures";
|
||||||
|
|
||||||
import { getModalRootViewCssClass } from "../../../css/system-classes";
|
import { getModalRootViewCssClasses } from "../../../css/system-classes";
|
||||||
import { Builder } from "../../builder";
|
import { Builder } from "../../builder";
|
||||||
import { sanitizeModuleName } from "../../builder/module-name-sanitizer";
|
import { sanitizeModuleName } from "../../builder/module-name-sanitizer";
|
||||||
import { StyleScope } from "../../styling/style-scope";
|
import { StyleScope } from "../../styling/style-scope";
|
||||||
@ -371,7 +371,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
|||||||
protected _showNativeModalView(parent: ViewCommon, options: ShowModalOptions) {
|
protected _showNativeModalView(parent: ViewCommon, options: ShowModalOptions) {
|
||||||
_rootModalViews.push(this);
|
_rootModalViews.push(this);
|
||||||
|
|
||||||
const modalRootViewCssClass = getModalRootViewCssClass();
|
const modalRootViewCssClass = getModalRootViewCssClasses()[0];
|
||||||
this.cssClasses.add(modalRootViewCssClass);
|
this.cssClasses.add(modalRootViewCssClass);
|
||||||
|
|
||||||
parent._modal = this;
|
parent._modal = this;
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
} from "../../styling/style-properties";
|
} from "../../styling/style-properties";
|
||||||
|
|
||||||
import { Background, ad as androidBackground } from "../../styling/background";
|
import { Background, ad as androidBackground } from "../../styling/background";
|
||||||
|
import { getModalRootViewCssClasses } from "../../../css/system-classes";
|
||||||
import { profile } from "../../../profiling";
|
import { profile } from "../../../profiling";
|
||||||
import { topmost } from "../../frame/frame-stack";
|
import { topmost } from "../../frame/frame-stack";
|
||||||
import { AndroidActivityBackPressedEventData, android as androidApp } from "../../../application";
|
import { AndroidActivityBackPressedEventData, android as androidApp } from "../../../application";
|
||||||
@ -633,6 +634,13 @@ export class View extends ViewCommon {
|
|||||||
}
|
}
|
||||||
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
|
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
|
||||||
super._showNativeModalView(parent, options);
|
super._showNativeModalView(parent, options);
|
||||||
|
|
||||||
|
const modalRootViewCssClasses = getModalRootViewCssClasses();
|
||||||
|
if (modalRootViewCssClasses.length > 1) {
|
||||||
|
const modalRootViewSystemAppearanceCssClass = getModalRootViewCssClasses()[1];
|
||||||
|
this.cssClasses.add(modalRootViewSystemAppearanceCssClass);
|
||||||
|
}
|
||||||
|
|
||||||
initializeDialogFragment();
|
initializeDialogFragment();
|
||||||
|
|
||||||
const df = new DialogFragment();
|
const df = new DialogFragment();
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
} from "./view-common";
|
} from "./view-common";
|
||||||
|
|
||||||
import { ios as iosBackground, Background } from "../../styling/background";
|
import { ios as iosBackground, Background } from "../../styling/background";
|
||||||
|
import { getModalRootViewCssClasses } from "../../../css/system-classes";
|
||||||
import { ios as iosUtils } from "../../../utils/utils";
|
import { ios as iosUtils } from "../../../utils/utils";
|
||||||
import {
|
import {
|
||||||
Visibility,
|
Visibility,
|
||||||
@ -398,7 +399,15 @@ export class View extends ViewCommon {
|
|||||||
|
|
||||||
this._setupAsRootView({});
|
this._setupAsRootView({});
|
||||||
|
|
||||||
|
|
||||||
super._showNativeModalView(parentWithController, options);
|
super._showNativeModalView(parentWithController, options);
|
||||||
|
|
||||||
|
const modalRootViewCssClasses = getModalRootViewCssClasses();
|
||||||
|
if (majorVersion >= 13 && modalRootViewCssClasses.length > 1) {
|
||||||
|
const modalRootViewSystemAppearanceCssClass = getModalRootViewCssClasses()[1];
|
||||||
|
this.cssClasses.add(modalRootViewSystemAppearanceCssClass);
|
||||||
|
}
|
||||||
|
|
||||||
let controller = this.viewController;
|
let controller = this.viewController;
|
||||||
if (!controller) {
|
if (!controller) {
|
||||||
const nativeView = this.ios || this.nativeViewProtected;
|
const nativeView = this.ios || this.nativeViewProtected;
|
||||||
|
@ -20,7 +20,12 @@ import {
|
|||||||
|
|
||||||
// TODO: Remove this and get it from global to decouple builder for angular
|
// TODO: Remove this and get it from global to decouple builder for angular
|
||||||
import { Builder } from "../builder";
|
import { Builder } from "../builder";
|
||||||
import { CLASS_PREFIX, getRootViewCssClasses, pushToRootViewCssClasses } from "../../css/system-classes";
|
import {
|
||||||
|
CLASS_PREFIX,
|
||||||
|
getRootViewCssClasses,
|
||||||
|
pushToModalRootViewCssClasses,
|
||||||
|
pushToRootViewCssClasses
|
||||||
|
} from "../../css/system-classes";
|
||||||
import { device } from "../../platform/platform";
|
import { device } from "../../platform/platform";
|
||||||
import { profile } from "../../profiling";
|
import { profile } from "../../profiling";
|
||||||
|
|
||||||
@ -1342,6 +1347,8 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
|
|||||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${ANDROID_PLATFORM}`);
|
pushToRootViewCssClasses(`${CLASS_PREFIX}${ANDROID_PLATFORM}`);
|
||||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${deviceType}`);
|
pushToRootViewCssClasses(`${CLASS_PREFIX}${deviceType}`);
|
||||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${application.android.orientation}`);
|
pushToRootViewCssClasses(`${CLASS_PREFIX}${application.android.orientation}`);
|
||||||
|
|
||||||
|
pushToModalRootViewCssClasses(`${CLASS_PREFIX}${application.android.systemAppearance}`);
|
||||||
pushToRootViewCssClasses(`${CLASS_PREFIX}${application.android.systemAppearance}`);
|
pushToRootViewCssClasses(`${CLASS_PREFIX}${application.android.systemAppearance}`);
|
||||||
|
|
||||||
const rootViewCssClasses = getRootViewCssClasses();
|
const rootViewCssClasses = getRootViewCssClasses();
|
||||||
|
Reference in New Issue
Block a user