Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

feat: support iOS 13+ dark mode #208

Open
wants to merge 5 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
4 changes: 2 additions & 2 deletions RichEditorView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RichEditorView"
s.version = "5.0.0"
s.version = "6.0.0"
s.summary = "Rich Text Editor for iOS written in Swift"
s.homepage = "https://github.com/cjwirth/RichEditorView"
s.license = 'BSD 3-clause'
Expand All @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'https://twitter.com/cjwirth'

s.platform = :ios, '8.0'
s.swift_version = '4.0'
s.swift_version = '5.0'
s.requires_arc = true

s.source_files = 'RichEditorView/Classes/*'
Expand Down
11 changes: 7 additions & 4 deletions RichEditorView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = FBA6AAEF1AD3EC9F00721644;
Expand Down Expand Up @@ -560,6 +561,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -602,6 +604,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -624,7 +627,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -642,7 +645,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.cjwirth.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -658,7 +661,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.cjwirth.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -670,7 +673,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.cjwirth.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
3 changes: 2 additions & 1 deletion RichEditorView/Assets/editor/rich_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.onload = function() {
RE.callback("ready");
};

RE.body = document.getElementsByTagName('body')[0];
RE.editor = document.getElementById('editor');

// Not universally supported, but seems to work in iOS 7 and 8
Expand Down Expand Up @@ -138,7 +139,7 @@ RE.setFontSize = function(size) {
};

RE.setBackgroundColor = function(color) {
RE.editor.style.backgroundColor = color;
RE.body.style.backgroundColor = color;
};

RE.setHeight = function(size) {
Expand Down
15 changes: 14 additions & 1 deletion RichEditorView/Assets/editor/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ html {
body {
min-height: 100%;
overflow: auto;
background-color: white;
}

@media (prefers-color-scheme: dark) {
body {
background-color: black;
}
}

body, h1, p {
Expand Down Expand Up @@ -55,7 +62,13 @@ div {
height: 100%;
overflow: auto;
display: block;
font-family: 'HelveticaNeue';
font-family: '-apple-system', 'HelveticaNeue';
color:#666666;
font-size: 12pt;
}

@media (prefers-color-scheme: dark) {
#editor {
color: white;
}
}
9 changes: 5 additions & 4 deletions RichEditorView/Classes/RichEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,19 @@ import UIKit
}

private func setup() {
backgroundColor = .red

webView.frame = bounds
webView.delegate = self
webView.keyboardDisplayRequiresUserAction = false
webView.scalesPageToFit = false
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
webView.dataDetectorTypes = UIDataDetectorTypes()
webView.backgroundColor = .white

webView.scrollView.isScrollEnabled = isScrollEnabled
webView.scrollView.bounces = false
webView.scrollView.delegate = self
webView.scrollView.clipsToBounds = false

webView.cjw_inputAccessoryView = nil

self.addSubview(webView)
Expand Down Expand Up @@ -234,6 +232,9 @@ import UIKit
}

public func setEditorBackgroundColor(_ color: UIColor) {
webView.backgroundColor = color
webView.scrollView.backgroundColor = color

runJS("RE.setBackgroundColor('\(color.hex)');")
}

Expand Down Expand Up @@ -368,7 +369,7 @@ import UIKit

// MARK: UIWebViewDelegate

public func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
public func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {

// Handle pre-defined editor actions
let callbackPrefix = "re-callback://"
Expand Down