Revision: 2682
http://sourceforge.net/p/swingme/code/2682
Author: yuranet
Date: 2023-01-24 15:50:05 +0000 (Tue, 24 Jan 2023)
Log Message:
-----------
fix title color when white page is opened in dark theme
Modified Paths:
--------------
iOSME/src/net/yura/ios/WebViewController.java
Modified: iOSME/src/net/yura/ios/WebViewController.java
===================================================================
--- iOSME/src/net/yura/ios/WebViewController.java 2023-01-24 14:56:43 UTC (rev 2681)
+++ iOSME/src/net/yura/ios/WebViewController.java 2023-01-24 15:50:05 UTC (rev 2682)
@@ -5,8 +5,10 @@
import apple.foundation.NSData;
import apple.foundation.NSError;
import apple.foundation.NSURL;
+import apple.uikit.UINavigationBarAppearance;
import apple.uikit.UIScreen;
import apple.uikit.UIViewController;
+import apple.uikit.enums.UIUserInterfaceStyle;
import apple.uikit.enums.UIViewAutoresizing;
import apple.webkit.WKNavigation;
import apple.webkit.WKUserContentController;
@@ -104,6 +106,7 @@
// we want to load text as UTF-8, as by default iOS seems to use some other encoding
NSData data = NSData.dataWithContentsOfURL(htmlFileUrl);
myWebView.loadDataMIMETypeCharacterEncodingNameBaseURL(data, "text/plain", "UTF-8", mainBundle.resourceURL());
+ setTitle(name);
}
else {
myWebView.loadFileURLAllowingReadAccessToURL(htmlFileUrl, mainBundle.resourceURL());
@@ -129,7 +132,10 @@
@Override
public void call_evaluateJavaScriptCompletionHandler(Object title, NSError error) {
if (error == null) {
- setTitle(String.valueOf(title));
+ String titleString = String.valueOf(title);
+ if (!"".equals(titleString)) {
+ setTitle(titleString);
+ }
}
else {
System.err.println("Error getting title: " + error);
@@ -137,5 +143,22 @@
}
});
}
+
+ // if we are in dark mode, check if page is white, as we may get white title on white background
+ if (traitCollection().userInterfaceStyle() == UIUserInterfaceStyle.Dark) {
+ myWebView.evaluateJavaScriptCompletionHandler("window.getComputedStyle(document.body, null).getPropertyValue('background-color')", new WKWebView.Block_evaluateJavaScriptCompletionHandler() {
+ @Override
+ public void call_evaluateJavaScriptCompletionHandler(Object color, NSError error) {
+ // if the background is hard coded to white
+ if ("rgb(255, 255, 255)".equals(color)) {
+ // we do NOT want the 'TransparentBackground' as then we will get white title on white background
+ UINavigationBarAppearance appearance = UINavigationBarAppearance.alloc().init();
+ appearance.configureWithOpaqueBackground();
+ //appearance.setTitleTextAttributes((NSDictionary<String, ?>) NSDictionary.dictionaryWithObjectForKey(UIColor.blackColor(), UIKit.NSForegroundColorAttributeName()));
+ navigationItem().setScrollEdgeAppearance(appearance);
+ }
+ }
+ });
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|