From fc89548e12af661d3984160ebe5c4c2d99c6d622 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Wed, 30 Sep 2020 15:20:59 +0200 Subject: [PATCH] chore: Remove StatusBar plugin --- .../main/java/com/getcapacitor/Bridge.java | 2 - .../com/getcapacitor/plugin/StatusBar.java | 158 ------------------ core/src/core-plugin-definitions.ts | 81 --------- .../Capacitor/Plugins/DefaultPlugins.m | 9 - .../Capacitor/Plugins/StatusBar.swift | 98 ----------- 5 files changed, 348 deletions(-) delete mode 100644 android/capacitor/src/main/java/com/getcapacitor/plugin/StatusBar.java delete mode 100644 ios/Capacitor/Capacitor/Plugins/StatusBar.swift diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 95d1190d7..1bbc824d2 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -21,7 +21,6 @@ import com.getcapacitor.plugin.LocalNotifications; import com.getcapacitor.plugin.PushNotifications; import com.getcapacitor.plugin.SplashScreen; -import com.getcapacitor.plugin.StatusBar; import com.getcapacitor.plugin.background.BackgroundTask; import com.getcapacitor.util.HostMask; import java.io.File; @@ -387,7 +386,6 @@ private void registerAllPlugins() { this.registerPlugin(Keyboard.class); this.registerPlugin(PushNotifications.class); this.registerPlugin(SplashScreen.class); - this.registerPlugin(StatusBar.class); this.registerPlugin(com.getcapacitor.plugin.WebView.class); for (Class pluginClass : this.initialPlugins) { diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/StatusBar.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/StatusBar.java deleted file mode 100644 index 87804d26f..000000000 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/StatusBar.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.getcapacitor.plugin; - -import android.graphics.Color; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import com.getcapacitor.JSObject; -import com.getcapacitor.NativePlugin; -import com.getcapacitor.Plugin; -import com.getcapacitor.PluginCall; -import com.getcapacitor.PluginMethod; - -@NativePlugin -public class StatusBar extends Plugin { - private int currentStatusbarColor; - - @Override - public void load() { - // save initial color of the status bar - currentStatusbarColor = getActivity().getWindow().getStatusBarColor(); - } - - @PluginMethod - public void setStyle(final PluginCall call) { - final String style = call.getString("style"); - if (style == null) { - call.error("Style must be provided"); - return; - } - - getBridge() - .executeOnMainThread( - () -> { - Window window = getActivity().getWindow(); - View decorView = window.getDecorView(); - - int visibilityFlags = decorView.getSystemUiVisibility(); - - if (style.equals("DARK")) { - decorView.setSystemUiVisibility(visibilityFlags & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - } else { - decorView.setSystemUiVisibility(visibilityFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); - } - call.success(); - } - ); - } - - @PluginMethod - public void setBackgroundColor(final PluginCall call) { - final String color = call.getString("color"); - if (color == null) { - call.error("Color must be provided"); - return; - } - - getBridge() - .executeOnMainThread( - () -> { - Window window = getActivity().getWindow(); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - try { - final int parsedColor = Color.parseColor(color.toUpperCase()); - window.setStatusBarColor(parsedColor); - // update the local color field as well - currentStatusbarColor = parsedColor; - call.success(); - } catch (IllegalArgumentException ex) { - call.error("Invalid color provided. Must be a hex string (ex: #ff0000"); - } - } - ); - } - - @PluginMethod - public void hide(final PluginCall call) { - // Hide the status bar. - getBridge() - .executeOnMainThread( - () -> { - View decorView = getActivity().getWindow().getDecorView(); - int uiOptions = decorView.getSystemUiVisibility(); - uiOptions = uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN; - uiOptions = uiOptions & ~View.SYSTEM_UI_FLAG_VISIBLE; - decorView.setSystemUiVisibility(uiOptions); - call.success(); - } - ); - } - - @PluginMethod - public void show(final PluginCall call) { - // Show the status bar. - getBridge() - .executeOnMainThread( - () -> { - View decorView = getActivity().getWindow().getDecorView(); - int uiOptions = decorView.getSystemUiVisibility(); - uiOptions = uiOptions | View.SYSTEM_UI_FLAG_VISIBLE; - uiOptions = uiOptions & ~View.SYSTEM_UI_FLAG_FULLSCREEN; - decorView.setSystemUiVisibility(uiOptions); - call.success(); - } - ); - } - - @PluginMethod - public void getInfo(final PluginCall call) { - View decorView = getActivity().getWindow().getDecorView(); - Window window = getActivity().getWindow(); - - String style; - if ((decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) { - style = "LIGHT"; - } else { - style = "DARK"; - } - - JSObject data = new JSObject(); - data.put("visible", (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) != View.SYSTEM_UI_FLAG_FULLSCREEN); - data.put("style", style); - data.put("color", String.format("#%06X", (0xFFFFFF & window.getStatusBarColor()))); - data.put( - "overlays", - (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - ); - call.resolve(data); - } - - @PluginMethod - public void setOverlaysWebView(final PluginCall call) { - final Boolean overlays = call.getBoolean("overlay", true); - getBridge() - .executeOnMainThread( - () -> { - if (overlays) { - // Sets the layout to a fullscreen one that does not hide the actual status bar, so the webview is displayed behind it. - View decorView = getActivity().getWindow().getDecorView(); - int uiOptions = decorView.getSystemUiVisibility(); - uiOptions = uiOptions | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; - decorView.setSystemUiVisibility(uiOptions); - currentStatusbarColor = getActivity().getWindow().getStatusBarColor(); - getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT); - } else { - // Sets the layout to a normal one that displays the webview below the status bar. - View decorView = getActivity().getWindow().getDecorView(); - int uiOptions = decorView.getSystemUiVisibility(); - uiOptions = uiOptions & ~View.SYSTEM_UI_FLAG_LAYOUT_STABLE & ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; - decorView.setSystemUiVisibility(uiOptions); - // recover the previous color of the status bar - getActivity().getWindow().setStatusBarColor(currentStatusbarColor); - } - call.success(); - } - ); - } -} diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index f502eb667..eb3624a6a 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -9,7 +9,6 @@ export interface PluginRegistry { LocalNotifications: LocalNotificationsPlugin; PushNotifications: PushNotificationsPlugin; SplashScreen: SplashScreenPlugin; - StatusBar: StatusBarPlugin; WebView: WebViewPlugin; [pluginName: string]: { @@ -695,86 +694,6 @@ export interface SplashScreenHideOptions { // -export interface StatusBarPlugin extends Plugin { - /** - * Set the current style of the status bar - */ - setStyle(options: StatusBarStyleOptions): Promise; - /** - * Set the background color of the status bar - */ - setBackgroundColor(options: StatusBarBackgroundColorOptions): Promise; - /** - * Show the status bar - */ - show(options?: StatusBarAnimationOptions): Promise; - /** - * Hide the status bar - */ - hide(options?: StatusBarAnimationOptions): Promise; - /** - * Get info about the current state of the status bar - */ - getInfo(): Promise; - /** - * Set whether or not the status bar should overlay the webview to allow usage of the space - * around a device "notch" - */ - setOverlaysWebView(options: StatusBarOverlaysWebviewOptions): Promise; -} - -export interface StatusBarStyleOptions { - style: StatusBarStyle; -} - -export enum StatusBarStyle { - /** - * Light text for dark backgrounds. - */ - Dark = 'DARK', - /** - * Dark text for light backgrounds. - */ - Light = 'LIGHT', -} - -export interface StatusBarAnimationOptions { - /** - * iOS only. The type of status bar animation used when showing or hiding. - */ - animation: StatusBarAnimation; -} - -export enum StatusBarAnimation { - /** - * No animation during show/hide. - */ - None = 'NONE', - /** - * Slide animation during show/hide. - */ - Slide = 'SLIDE', - /** - * Fade animation during show/hide. - */ - Fade = 'FADE', -} - -export interface StatusBarBackgroundColorOptions { - color: string; -} - -export interface StatusBarInfoResult { - visible: boolean; - style: StatusBarStyle; - color?: string; - overlays?: boolean; -} - -export interface StatusBarOverlaysWebviewOptions { - overlay: boolean; -} - export interface WebViewPlugin extends Plugin { setServerBasePath(options: WebViewPath): Promise; getServerBasePath(): Promise; diff --git a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m index d60e977bc..af8e8bc87 100644 --- a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m +++ b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m @@ -66,15 +66,6 @@ CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise); ) -CAP_PLUGIN(CAPStatusBarPlugin, "StatusBar", - CAP_PLUGIN_METHOD(setStyle, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setBackgroundColor, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(getInfo, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setOverlaysWebView, CAPPluginReturnPromise); -) - CAP_PLUGIN(CAPWebViewPlugin, "WebView", CAP_PLUGIN_METHOD(setServerBasePath, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(getServerBasePath, CAPPluginReturnPromise); diff --git a/ios/Capacitor/Capacitor/Plugins/StatusBar.swift b/ios/Capacitor/Capacitor/Plugins/StatusBar.swift deleted file mode 100644 index 56fd13099..000000000 --- a/ios/Capacitor/Capacitor/Plugins/StatusBar.swift +++ /dev/null @@ -1,98 +0,0 @@ -import Foundation - -/** - * StatusBar plugin. Requires "View controller-based status bar appearance" to - * be "YES" in Info.plist - */ -@objc(CAPStatusBarPlugin) -public class CAPStatusBarPlugin: CAPPlugin { - - override public func load() { - NotificationCenter.default.addObserver(forName: CAPBridge.statusBarTappedNotification.name, object: .none, queue: .none) { [weak self] _ in - self?.bridge?.triggerJSEvent(eventName: "statusTap", target: "window") - } - } - - @objc func setStyle(_ call: CAPPluginCall) { - let options = call.options! - - if let style = options["style"] as? String { - if style == "DARK" { - bridge?.setStatusBarStyle(.lightContent) - } else if style == "LIGHT" { - if #available(iOS 13.0, *) { - bridge?.setStatusBarStyle(.darkContent) - } else { - bridge?.setStatusBarStyle(.default) - } - } - } - - call.success([:]) - } - - @objc func setBackgroundColor(_ call: CAPPluginCall) { - call.unimplemented() - } - - func setAnimation(_ call: CAPPluginCall) { - let animation = call.getString("animation", "SLIDE") - if animation == "FADE" { - bridge?.setStatusBarAnimation(.fade) - } else if animation == "NONE" { - bridge?.setStatusBarAnimation(.none) - } else { - bridge?.setStatusBarAnimation(.slide) - } - } - - @objc func hide(_ call: CAPPluginCall) { - setAnimation(call) - bridge?.setStatusBarVisible(false) - call.success() - } - - @objc func show(_ call: CAPPluginCall) { - setAnimation(call) - bridge?.setStatusBarVisible(true) - call.success() - } - - @objc func getInfo(_ call: CAPPluginCall) { - DispatchQueue.main.async { [weak self] in - guard let bridge = self?.bridge else { - return - } - let style: String - if #available(iOS 13.0, *) { - switch bridge.getStatusBarStyle() { - case .default: - if bridge.getUserInterfaceStyle() == UIUserInterfaceStyle.dark { - style = "DARK" - } else { - style = "LIGHT" - } - case .lightContent: - style = "DARK" - default: - style = "LIGHT" - } - } else { - if bridge.getStatusBarStyle() == .lightContent { - style = "DARK" - } else { - style = "LIGHT" - } - } - - call.success([ - "visible": bridge.getStatusBarVisible(), - "style": style - ]) - } - } - - @objc func setOverlaysWebView(_ call: CAPPluginCall) { - call.unimplemented() - } -}