This commit is contained in:
metacryst
2026-01-09 11:14:27 -06:00
parent cf03c95664
commit 637c9e4674
2149 changed files with 527743 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
import Foundation
import Capacitor
@objc(SplashScreenPlugin)
public class SplashScreenPlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "SplashScreenPlugin"
public let jsName = "SplashScreen"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "hide", returnType: CAPPluginReturnPromise)
]
private var splashScreen: SplashScreen?
override public func load() {
if let view = bridge?.viewController?.view {
splashScreen = SplashScreen(parentView: view, config: splashScreenConfig())
splashScreen?.showOnLaunch()
}
}
// Show the splash screen
@objc public func show(_ call: CAPPluginCall) {
if let splash = splashScreen {
let settings = splashScreenSettings(from: call)
splash.show(settings: settings,
completion: {
call.resolve()
})
} else {
call.reject("Unable to show Splash Screen")
}
}
// Hide the splash screen
@objc public func hide(_ call: CAPPluginCall) {
if let splash = splashScreen {
let settings = splashScreenSettings(from: call)
splash.hide(settings: settings)
call.resolve()
} else {
call.reject("Unable to hide Splash Screen")
}
}
private func splashScreenSettings(from call: CAPPluginCall) -> SplashScreenSettings {
var settings = SplashScreenSettings()
if let showDuration = call.getInt("showDuration") {
settings.showDuration = showDuration
}
if let fadeInDuration = call.getInt("fadeInDuration") {
settings.fadeInDuration = fadeInDuration
}
if let fadeOutDuration = call.getInt("fadeOutDuration") {
settings.fadeOutDuration = fadeOutDuration
}
if let autoHide = call.getBool("autoHide") {
settings.autoHide = autoHide
}
return settings
}
private func splashScreenConfig() -> SplashScreenConfig {
var config = SplashScreenConfig()
if let backgroundColor = getConfig().getString("backgroundColor") {
config.backgroundColor = UIColor.capacitor.color(fromHex: backgroundColor)
}
if let spinnerStyle = getConfig().getString("iosSpinnerStyle") {
switch spinnerStyle.lowercased() {
case "small":
config.spinnerStyle = .medium
default:
config.spinnerStyle = .large
}
}
if let spinnerColor = getConfig().getString("spinnerColor") {
config.spinnerColor = UIColor.capacitor.color(fromHex: spinnerColor)
}
config.showSpinner = getConfig().getBoolean("showSpinner", config.showSpinner)
config.launchShowDuration = getConfig().getInt("launchShowDuration", config.launchShowDuration)
config.launchAutoHide = getConfig().getBoolean("launchAutoHide", config.launchAutoHide)
return config
}
}