Skip to content

Commit 5967667

Browse files
author
Pedro Aim
committed
copy resources to package bundle
1 parent bca620f commit 5967667

9 files changed

Lines changed: 39 additions & 19 deletions

File tree

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ let package = Package(
2424
.target(
2525
name: "TheRichTextEditor",
2626
dependencies: [],
27-
resources: [.process("main.js"), .process("main.html")]),
27+
path: nil,
28+
resources: [.copy("Resources/main.js"), .copy("Resources/main.html")]),
2829
.testTarget(
2930
name: "TheRichTextEditorTests",
3031
dependencies: ["TheRichTextEditor"]),

Sources/TheRichTextEditor/Assets.xcassets/indent.imageset/Contents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scale" : "1x"
66
},
77
{
8-
"filename" : "indent.png",
8+
"filename" : "left-indent.png",
99
"idiom" : "universal",
1010
"scale" : "2x"
1111
},
Binary file not shown.
5.68 KB
Loading
File renamed without changes.
File renamed without changes.

Sources/TheRichTextEditor/TheRichTextEditor.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public class TheRichTextEditor: UIView, WKScriptMessageHandler, WKNavigationDele
8585
}
8686

8787
func setup() {
88-
guard let scriptPath = Bundle.main.path(forResource: "main", ofType: "js"),
88+
guard let scriptPath = Bundle.module.path(forResource: "main", ofType: "js"),
8989
let scriptContent = try? String(contentsOfFile: scriptPath, encoding: String.Encoding.utf8),
90-
let htmlPath = Bundle.main.path(forResource: "main", ofType: "html"),
90+
let htmlPath = Bundle.module.path(forResource: "main", ofType: "html"),
9191
let html = try? String(contentsOfFile: htmlPath, encoding: String.Encoding.utf8)
9292
else {
9393
fatalError("Unable to find javscript/html for text editor")
@@ -131,6 +131,15 @@ public class TheRichTextEditor: UIView, WKScriptMessageHandler, WKNavigationDele
131131

132132
webView.loadHTMLString(html, baseURL: Bundle.main.bundleURL)
133133
}
134+
135+
public func setColors(background: UIColor, icons: UIColor) {
136+
guard let customWebview = webView as? CustomWebview else {
137+
return
138+
}
139+
140+
customWebview.myTintColor = icons
141+
customWebview.myBackgroundColor = background
142+
}
134143

135144
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
136145
switch message.name {
@@ -141,7 +150,6 @@ public class TheRichTextEditor: UIView, WKScriptMessageHandler, WKNavigationDele
141150
case TheRichTextEditor.heightDidChange:
142151
guard let height = message.body as? CGFloat else { return }
143152
if (height + 20 != self.height) {
144-
print(self.height)
145153
self.height = height + 20
146154
delegate?.heightDidChange()
147155
}

Sources/TheRichTextEditor/Views/AccessoryUICollectionViewCell.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<objects>
1111
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1212
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
13-
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="jVD-uD-E95" customClass="AccessoryUICollectionViewCell" customModule="ShareExtension" customModuleProvider="target">
13+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="jVD-uD-E95" customClass="AccessoryUICollectionViewCell" customModule="TheRichTextEditor">
1414
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
1515
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1616
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="aa0-hX-eT4">
@@ -30,7 +30,7 @@
3030
</constraints>
3131
</collectionViewCellContentView>
3232
<connections>
33-
<outlet property="iconImageView" destination="62T-xA-NgZ" id="piK-hT-QZa"/>
33+
<outlet property="iconImageView" destination="62T-xA-NgZ" id="BiN-ge-7Gb"/>
3434
</connections>
3535
<point key="canvasLocation" x="-239" y="55"/>
3636
</collectionViewCell>

Sources/TheRichTextEditor/Views/CustomWebview.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,31 @@ class CustomWebview: WKWebView {
6565
var image: UIImage {
6666
switch(self) {
6767
case .bold:
68-
return UIImage(named: "bold")!
68+
return UIImage(named: "bold", in: .module, compatibleWith: nil)!
6969
case .italic:
70-
return UIImage(named: "italic")!
70+
return UIImage(named: "italic", in: .module, compatibleWith: nil)!
7171
case .textAlignLeft:
72-
return UIImage(named: "alignLeft")!
72+
return UIImage(named: "alignLeft", in: .module, compatibleWith: nil)!
7373
case .textAlignCenter:
74-
return UIImage(named: "alignCenter")!
74+
return UIImage(named: "alignCenter", in: .module, compatibleWith: nil)!
7575
case .textAlignRight:
76-
return UIImage(named: "alignRight")!
76+
return UIImage(named: "alignRight", in: .module, compatibleWith: nil)!
7777
case .indent:
78-
return UIImage(named: "indent")!
78+
return UIImage(named: "indent", in: .module, compatibleWith: nil)!
7979
case .outdent:
80-
return UIImage(named: "outdent")!
80+
return UIImage(named: "outdent", in: .module, compatibleWith: nil)!
8181
case .clear:
82-
return UIImage(named: "clear")!
82+
return UIImage(named: "clear", in: .module, compatibleWith: nil)!
8383
case .undo:
84-
return UIImage(named: "undo")!
84+
return UIImage(named: "undo", in: .module, compatibleWith: nil)!
8585
case .redo:
86-
return UIImage(named: "redo")!
86+
return UIImage(named: "redo", in: .module, compatibleWith: nil)!
8787
}
8888
}
8989
}
9090
weak var toolbarDelegate: WebviewToolbarDelegate? = nil
91+
var myBackgroundColor: UIColor? = nil
92+
var myTintColor: UIColor? = nil
9193
var enableAccessoryView = true
9294
var accessoryView: UIView? = nil
9395
var modifiers: [Modifier] = [.bold, .italic, .textAlignRight, .textAlignCenter, .textAlignLeft, .indent, .outdent, .clear, .undo, .redo]
@@ -100,14 +102,18 @@ class CustomWebview: WKWebView {
100102
layout.scrollDirection = .horizontal
101103

102104
let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: 100, height: 50), collectionViewLayout: layout)
103-
//collectionView.backgroundColor = theme.background
105+
if #available(iOS 13.0, *) {
106+
collectionView.backgroundColor = myBackgroundColor ?? .systemBackground
107+
} else {
108+
collectionView.backgroundColor = myBackgroundColor ?? .lightGray
109+
}
104110
collectionView.dataSource = self
105111
collectionView.delegate = self
106112
collectionView.isScrollEnabled = true
107113
collectionView.bounces = false
108114
collectionView.showsHorizontalScrollIndicator = false
109115

110-
let accessoryNib = UINib(nibName: "AccessoryUICollectionViewCell", bundle: nil)
116+
let accessoryNib = UINib(nibName: "AccessoryUICollectionViewCell", bundle: .module)
111117
collectionView.register(accessoryNib, forCellWithReuseIdentifier: "accessoryCell")
112118

113119
accessoryView = collectionView
@@ -130,6 +136,11 @@ extension CustomWebview: UICollectionViewDataSource, UICollectionViewDelegate, U
130136

131137
let collectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: "accessoryCell", for: indexPath) as! AccessoryUICollectionViewCell
132138
collectionCell.iconImageView.image = modifier.image
139+
if #available(iOS 13.0, *) {
140+
collectionCell.iconImageView.tintColor = myTintColor ?? .systemFill
141+
} else {
142+
collectionCell.iconImageView.tintColor = myTintColor ?? .darkText
143+
}
133144
return collectionCell
134145
}
135146

0 commit comments

Comments
 (0)