This is an automated email from the ASF dual-hosted git repository.

dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new 0dd2c855 feat: SplashScreen Background Color preference support (#1411)
0dd2c855 is described below

commit 0dd2c855d0cc0ae3195732c9ff07bf1b2aff3265
Author: Darryl Pogue <dar...@dpogue.ca>
AuthorDate: Thu Mar 28 22:12:58 2024 -0700

    feat: SplashScreen Background Color preference support (#1411)
    
    Closes #1254.
---
 CordovaLib/Classes/Public/CDVViewController.m      | 15 ++++-
 lib/prepare.js                                     | 69 +++++++++++++++++-----
 .../Contents.json                                  | 15 +++++
 .../__PROJECT_NAME__/CDVLaunchScreen.storyboard    |  4 +-
 .../Contents.json                                  | 15 +++++
 5 files changed, 100 insertions(+), 18 deletions(-)

diff --git a/CordovaLib/Classes/Public/CDVViewController.m 
b/CordovaLib/Classes/Public/CDVViewController.m
index dd8ba165..6f85bb3b 100644
--- a/CordovaLib/Classes/Public/CDVViewController.m
+++ b/CordovaLib/Classes/Public/CDVViewController.m
@@ -29,6 +29,14 @@
 #import <Cordova/NSDictionary+CordovaPreferences.h>
 #import "CDVCommandDelegateImpl.h"
 
+UIColor* defaultBackgroundColor(void) {
+    if (@available(iOS 13.0, *)) {
+        return UIColor.systemBackgroundColor;
+    } else {
+        return UIColor.whiteColor;
+    }
+}
+
 @interface CDVViewController () <CDVWebViewEngineConfigurationDelegate> { }
 
 @property (nonatomic, readwrite, strong) NSXMLParser* configParser;
@@ -293,9 +301,12 @@
     }
     // /////////////////
 
-    UIColor* bgColor = [UIColor colorNamed:@"BackgroundColor"] ?: 
UIColor.whiteColor;
-    [self.launchView setBackgroundColor:bgColor];
+    UIColor* bgDefault = defaultBackgroundColor();
+    UIColor* bgColor = [UIColor colorNamed:@"BackgroundColor"] ?: bgDefault;
+    UIColor* bgSplash = [UIColor colorNamed:@"SplashScreenBackgroundColor"] ?: 
bgColor;
+
     [self.webView setBackgroundColor:bgColor];
+    [self.launchView setBackgroundColor:bgSplash];
 }
 
 -(void)viewWillAppear:(BOOL)animated
diff --git a/lib/prepare.js b/lib/prepare.js
index cfaab02c..df88fd6c 100644
--- a/lib/prepare.js
+++ b/lib/prepare.js
@@ -467,6 +467,21 @@ function getBackgroundColorDir (projectRoot, 
platformProjDir) {
     }
 }
 
+/**
+ * Returns the directory for the SplashScreenBackgroundColor.colorset asset, or
+ * null if no xcassets exist.
+ *
+ * @param  {string} projectRoot        The project's root directory
+ * @param  {string} platformProjDir    The platform's project directory
+ */
+function getSplashScreenBackgroundColorDir (projectRoot, platformProjDir) {
+    if (folderExists(path.join(projectRoot, platformProjDir, 
'Assets.xcassets/'))) {
+        return path.join(platformProjDir, 'Assets.xcassets', 
'SplashScreenBackgroundColor.colorset');
+    } else {
+        return null;
+    }
+}
+
 function colorPreferenceToComponents (pref) {
     if (!pref || 
!pref.match(/^(#[0-9A-Fa-f]{3}|(0x|#)([0-9A-Fa-f]{2})?[0-9A-Fa-f]{6})$/)) {
         return {
@@ -517,11 +532,12 @@ function colorPreferenceToComponents (pref) {
  * @param {Object} locations A dictionary containing useful location paths
  */
 function updateBackgroundColor (cordovaProject, locations) {
+    const platformProjDir = path.relative(cordovaProject.root, 
locations.xcodeCordovaProj);
+
     const pref = cordovaProject.projectConfig.getPreference('BackgroundColor', 
'ios') || '';
+    const splashPref = 
cordovaProject.projectConfig.getPreference('SplashScreenBackgroundColor', 
'ios') || pref;
 
-    const platformProjDir = path.relative(cordovaProject.root, 
locations.xcodeCordovaProj);
     const backgroundColorDir = getBackgroundColorDir(cordovaProject.root, 
platformProjDir);
-
     if (backgroundColorDir) {
         const contentsJSON = {
             colors: [{
@@ -538,6 +554,24 @@ function updateBackgroundColor (cordovaProject, locations) 
{
         fs.writeFileSync(path.join(cordovaProject.root, backgroundColorDir, 
'Contents.json'),
             JSON.stringify(contentsJSON, null, 2));
     }
+
+    const splashBackgroundColorDir = 
getSplashScreenBackgroundColorDir(cordovaProject.root, platformProjDir);
+    if (splashBackgroundColorDir) {
+        const contentsJSON = {
+            colors: [{
+                idiom: 'universal',
+                color: colorPreferenceToComponents(splashPref)
+            }],
+            info: {
+                author: 'Xcode',
+                version: 1
+            }
+        };
+
+        events.emit('verbose', 'Updating Splash Screen Background Color color 
set Contents.json');
+        fs.writeFileSync(path.join(cordovaProject.root, 
splashBackgroundColorDir, 'Contents.json'),
+            JSON.stringify(contentsJSON, null, 2));
+    }
 }
 
 /**
@@ -549,24 +583,31 @@ function updateBackgroundColor (cordovaProject, 
locations) {
  */
 function cleanBackgroundColor (projectRoot, projectConfig, locations) {
     const platformProjDir = path.relative(projectRoot, 
locations.xcodeCordovaProj);
-    const backgroundColorDir = getBackgroundColorDir(projectRoot, 
platformProjDir);
 
-    if (backgroundColorDir) {
-        const contentsJSON = {
-            colors: [{
-                idiom: 'universal',
-                color: colorPreferenceToComponents(null)
-            }],
-            info: {
-                author: 'Xcode',
-                version: 1
-            }
-        };
+    const contentsJSON = {
+        colors: [{
+            idiom: 'universal',
+            color: colorPreferenceToComponents(null)
+        }],
+        info: {
+            author: 'Xcode',
+            version: 1
+        }
+    };
 
+    const backgroundColorDir = getBackgroundColorDir(projectRoot, 
platformProjDir);
+    if (backgroundColorDir) {
         events.emit('verbose', 'Cleaning Background Color color set 
Contents.json');
         fs.writeFileSync(path.join(projectRoot, backgroundColorDir, 
'Contents.json'),
             JSON.stringify(contentsJSON, null, 2));
     }
+
+    const splashBackgroundColorDir = 
getSplashScreenBackgroundColorDir(projectRoot, platformProjDir);
+    if (splashBackgroundColorDir) {
+        events.emit('verbose', 'Cleaning Splash Screen Background Color color 
set Contents.json');
+        fs.writeFileSync(path.join(projectRoot, splashBackgroundColorDir, 
'Contents.json'),
+            JSON.stringify(contentsJSON, null, 2));
+    }
 }
 
 function updateFileResources (cordovaProject, locations) {
diff --git 
a/templates/project/__PROJECT_NAME__/Assets.xcassets/SplashScreenBackgroundColor.colorset/Contents.json
 
b/templates/project/__PROJECT_NAME__/Assets.xcassets/SplashScreenBackgroundColor.colorset/Contents.json
new file mode 100644
index 00000000..462830f8
--- /dev/null
+++ 
b/templates/project/__PROJECT_NAME__/Assets.xcassets/SplashScreenBackgroundColor.colorset/Contents.json
@@ -0,0 +1,15 @@
+{
+  "colors" : [
+    {
+      "color" : {
+        "platform" : "ios",
+        "reference" : "systemBackgroundColor"
+      },
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/templates/project/__PROJECT_NAME__/CDVLaunchScreen.storyboard 
b/templates/project/__PROJECT_NAME__/CDVLaunchScreen.storyboard
index 924392e3..be89abe1 100644
--- a/templates/project/__PROJECT_NAME__/CDVLaunchScreen.storyboard
+++ b/templates/project/__PROJECT_NAME__/CDVLaunchScreen.storyboard
@@ -42,7 +42,7 @@
                                 <rect key="frame" x="0.0" y="0.0" width="414" 
height="896"/>
                             </imageView>
                         </subviews>
-                        <color key="backgroundColor" name="BackgroundColor"/>
+                        <color key="backgroundColor" 
name="SplashScreenBackgroundColor"/>
                         <constraints>
                             <constraint firstAttribute="trailing" 
secondItem="2ns-9I-Qjs" secondAttribute="trailing" id="FZL-3Z-NFz"/>
                             <constraint firstItem="2ns-9I-Qjs" 
firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" 
id="L9l-pw-wXj"/>
@@ -58,7 +58,7 @@
     </scenes>
     <resources>
         <image name="LaunchStoryboard" width="1366" height="1366"/>
-        <namedColor name="BackgroundColor">
+        <namedColor name="SplashScreenBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" 
customColorSpace="genericGamma22GrayColorSpace"/>
         </namedColor>
     </resources>
diff --git 
a/tests/spec/unit/fixtures/ios-config-xml/SampleApp/Assets.xcassets/SplashScreenBackgroundColor.colorset/Contents.json
 
b/tests/spec/unit/fixtures/ios-config-xml/SampleApp/Assets.xcassets/SplashScreenBackgroundColor.colorset/Contents.json
new file mode 100644
index 00000000..462830f8
--- /dev/null
+++ 
b/tests/spec/unit/fixtures/ios-config-xml/SampleApp/Assets.xcassets/SplashScreenBackgroundColor.colorset/Contents.json
@@ -0,0 +1,15 @@
+{
+  "colors" : [
+    {
+      "color" : {
+        "platform" : "ios",
+        "reference" : "systemBackgroundColor"
+      },
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to