Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark mode support #47

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions MarkdownView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
7D3D278923BC75DC0059D330 /* main_dark.css in Resources */ = {isa = PBXBuildFile; fileRef = 7D3D278823BC75DC0059D330 /* main_dark.css */; };
7D3D278B23BC763C0059D330 /* index_dark.html in Resources */ = {isa = PBXBuildFile; fileRef = 7D3D278A23BC763C0059D330 /* index_dark.html */; };
FC9CC4C51EC43FA90013238C /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = FC9CC4BD1EC43FA90013238C /* index.html */; };
FC9CC4C61EC43FA90013238C /* main.css in Resources */ = {isa = PBXBuildFile; fileRef = FC9CC4BE1EC43FA90013238C /* main.css */; };
FC9CC4C71EC43FA90013238C /* main.js in Resources */ = {isa = PBXBuildFile; fileRef = FC9CC4BF1EC43FA90013238C /* main.js */; };
Expand All @@ -15,6 +17,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7D3D278823BC75DC0059D330 /* main_dark.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = main_dark.css; sourceTree = "<group>"; };
7D3D278A23BC763C0059D330 /* index_dark.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = index_dark.html; sourceTree = "<group>"; };
FC9CC4BD1EC43FA90013238C /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = index.html; path = webassets/dist/index.html; sourceTree = SOURCE_ROOT; };
FC9CC4BE1EC43FA90013238C /* main.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = main.css; path = webassets/dist/main.css; sourceTree = SOURCE_ROOT; };
FC9CC4BF1EC43FA90013238C /* main.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = main.js; path = webassets/dist/main.js; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -67,6 +71,8 @@
children = (
FC9CC4BD1EC43FA90013238C /* index.html */,
FC9CC4BE1EC43FA90013238C /* main.css */,
7D3D278A23BC763C0059D330 /* index_dark.html */,
7D3D278823BC75DC0059D330 /* main_dark.css */,
FC9CC4BF1EC43FA90013238C /* main.js */,
);
name = Assets;
Expand Down Expand Up @@ -125,6 +131,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = FCA0500B1EC41211001DAD5F;
Expand All @@ -144,6 +151,8 @@
files = (
FC9CC4C61EC43FA90013238C /* main.css in Resources */,
FC9CC4C51EC43FA90013238C /* index.html in Resources */,
7D3D278B23BC763C0059D330 /* index_dark.html in Resources */,
7D3D278923BC75DC0059D330 /* main_dark.css in Resources */,
FC9CC4C71EC43FA90013238C /* main.js in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 2 additions & 2 deletions MarkdownView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<string>6.1</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.3</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
14 changes: 12 additions & 2 deletions MarkdownView/MarkdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import WebKit

- Note: [How to get height of entire document with javascript](https://stackoverflow.com/questions/1145850/how-to-get-height-of-entire-document-with-javascript)
*/

open class MarkdownView: UIView {

private var webView: WKWebView?


public var isDarkUIStyle = false

fileprivate var intrinsicContentHeight: CGFloat? {
didSet {
Expand Down Expand Up @@ -53,10 +57,16 @@ open class MarkdownView: UIView {

let bundle = Bundle(for: MarkdownView.self)

var htmlName = "index"

if isDarkUIStyle {
htmlName = "index_dark"
}

let htmlURL: URL? =
bundle.url(forResource: "index",
bundle.url(forResource: htmlName,
withExtension: "html") ??
bundle.url(forResource: "index",
bundle.url(forResource: htmlName,
withExtension: "html",
subdirectory: "MarkdownView.bundle")

Expand Down
13 changes: 13 additions & 0 deletions MarkdownView/index_dark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="./main_dark.css" />
<script src="./main.js"></script>
</head>
<body>
<div class="container" id="contents"></div>
</body>
</html>
Loading