mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(ios): ease of use on explicit preferredStatusBarStyle
Allows statusBarStyle to be defined on any view for explicit per view control, whether presented in modal or not. Note: You must remove Info.plist key `UIViewControllerBasedStatusBarAppearance` It defaults to true when not present: https://developer.apple.com/documentation/bundleresources/information-property-list/uiviewcontrollerbasedstatusbarappearance Or you can explicitly set it to true: <key>UIViewControllerBasedStatusBarAppearance</key> <true/> False value will make this property have no effect.
This commit is contained in:
@@ -79,6 +79,10 @@ export interface ShowModalOptions {
|
|||||||
* height of the popup dialog
|
* height of the popup dialog
|
||||||
*/
|
*/
|
||||||
height?: number;
|
height?: number;
|
||||||
|
/**
|
||||||
|
* The preferred status bar style for the modal view
|
||||||
|
*/
|
||||||
|
statusBarStyle?: 'light' | 'dark';
|
||||||
};
|
};
|
||||||
android?: {
|
android?: {
|
||||||
/**
|
/**
|
||||||
|
|||||||
14
packages/core/ui/core/view/index.d.ts
vendored
14
packages/core/ui/core/view/index.d.ts
vendored
@@ -638,6 +638,20 @@ export abstract class View extends ViewCommon {
|
|||||||
*/
|
*/
|
||||||
cssType: string;
|
cssType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (iOS only) Gets or sets the status bar style for this view.
|
||||||
|
* Note: You must remove Info.plist key `UIViewControllerBasedStatusBarAppearance`
|
||||||
|
* It defaults to true when not present: https://developer.apple.com/documentation/bundleresources/information-property-list/uiviewcontrollerbasedstatusbarappearance
|
||||||
|
* Or you can explicitly set it to true:
|
||||||
|
* <key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
|
* <true/>
|
||||||
|
*
|
||||||
|
* False value will make this property have no effect.
|
||||||
|
*
|
||||||
|
* @nsProperty
|
||||||
|
*/
|
||||||
|
statusBarStyle: 'light' | 'dark';
|
||||||
|
|
||||||
cssClasses: Set<string>;
|
cssClasses: Set<string>;
|
||||||
cssPseudoClasses: Set<string>;
|
cssPseudoClasses: Set<string>;
|
||||||
|
|
||||||
|
|||||||
@@ -560,7 +560,8 @@ export class View extends ViewCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.ios && options.ios.presentationStyle) {
|
if (options.ios) {
|
||||||
|
if (options.ios.presentationStyle) {
|
||||||
const presentationStyle = options.ios.presentationStyle;
|
const presentationStyle = options.ios.presentationStyle;
|
||||||
controller.modalPresentationStyle = presentationStyle;
|
controller.modalPresentationStyle = presentationStyle;
|
||||||
|
|
||||||
@@ -568,6 +569,14 @@ export class View extends ViewCommon {
|
|||||||
this._setupPopoverControllerDelegate(controller, parent);
|
this._setupPopoverControllerDelegate(controller, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (options.ios.statusBarStyle) {
|
||||||
|
/**
|
||||||
|
* https://developer.apple.com/documentation/uikit/uiviewcontroller/modalpresentationcapturesstatusbarappearance
|
||||||
|
*/
|
||||||
|
controller.modalPresentationCapturesStatusBarAppearance = true;
|
||||||
|
this.statusBarStyle = options.ios.statusBarStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const cancelable = options.cancelable !== undefined ? !!options.cancelable : true;
|
const cancelable = options.cancelable !== undefined ? !!options.cancelable : true;
|
||||||
|
|
||||||
|
|||||||
@@ -997,6 +997,13 @@ export abstract class ViewCommon extends ViewBase {
|
|||||||
this._cssType = type.toLowerCase();
|
this._cssType = type.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get statusBarStyle(): 'light' | 'dark' {
|
||||||
|
return this.style.statusBarStyle;
|
||||||
|
}
|
||||||
|
set statusBarStyle(value: 'light' | 'dark') {
|
||||||
|
this.style.statusBarStyle = value;
|
||||||
|
}
|
||||||
|
|
||||||
get isLayoutRequired(): boolean {
|
get isLayoutRequired(): boolean {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,6 +127,20 @@ class UILayoutViewController extends UIViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
public get preferredStatusBarStyle(): UIStatusBarStyle {
|
||||||
|
const owner = this.owner?.deref();
|
||||||
|
if (owner) {
|
||||||
|
if (SDK_VERSION >= 13) {
|
||||||
|
return owner.statusBarStyle === 'dark' ? UIStatusBarStyle.DarkContent : UIStatusBarStyle.LightContent;
|
||||||
|
} else {
|
||||||
|
return owner.statusBarStyle === 'dark' ? UIStatusBarStyle.LightContent : UIStatusBarStyle.Default;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return UIStatusBarStyle.Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NativeClass
|
@NativeClass
|
||||||
|
|||||||
8
packages/core/ui/page/index.d.ts
vendored
8
packages/core/ui/page/index.d.ts
vendored
@@ -65,14 +65,6 @@ export declare class Page extends PageBase {
|
|||||||
*/
|
*/
|
||||||
public backgroundSpanUnderStatusBar: boolean;
|
public backgroundSpanUnderStatusBar: boolean;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets or sets the style of the status bar.
|
|
||||||
*
|
|
||||||
* @nsProperty
|
|
||||||
*/
|
|
||||||
// @ts-ignore
|
|
||||||
public statusBarStyle: 'light' | 'dark';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or sets the color of the status bar in Android.
|
* Gets or sets the color of the status bar in Android.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -349,7 +349,11 @@ class UIViewControllerImpl extends UIViewController {
|
|||||||
public get preferredStatusBarStyle(): UIStatusBarStyle {
|
public get preferredStatusBarStyle(): UIStatusBarStyle {
|
||||||
const owner = this._owner?.deref();
|
const owner = this._owner?.deref();
|
||||||
if (owner) {
|
if (owner) {
|
||||||
|
if (SDK_VERSION >= 13) {
|
||||||
|
return owner.statusBarStyle === 'dark' ? UIStatusBarStyle.DarkContent : UIStatusBarStyle.LightContent;
|
||||||
|
} else {
|
||||||
return owner.statusBarStyle === 'dark' ? UIStatusBarStyle.LightContent : UIStatusBarStyle.Default;
|
return owner.statusBarStyle === 'dark' ? UIStatusBarStyle.LightContent : UIStatusBarStyle.Default;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return UIStatusBarStyle.Default;
|
return UIStatusBarStyle.Default;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,13 +63,6 @@ export class PageBase extends ContentView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get statusBarStyle(): 'light' | 'dark' {
|
|
||||||
return this.style.statusBarStyle;
|
|
||||||
}
|
|
||||||
set statusBarStyle(value: 'light' | 'dark') {
|
|
||||||
this.style.statusBarStyle = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get androidStatusBarBackground(): Color {
|
public get androidStatusBarBackground(): Color {
|
||||||
return this.style.androidStatusBarBackground;
|
return this.style.androidStatusBarBackground;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user