Skip to content

Commit 9c5b983

Browse files
committed
Cleaning up Xib loading for version 0.2.0
1 parent 96713ac commit 9c5b983

File tree

22 files changed

+444
-155
lines changed

22 files changed

+444
-155
lines changed

Example.SPM/SMLInkPreview-SPM-Example/SMLInkPreview-SPM-Example/Base.lproj/Main.storyboard

-24
This file was deleted.

Example.SPM/SMLInkPreview-SPM-Example/SMLInkPreview-SPM-Example/ViewController.swift

-19
This file was deleted.

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
name: "SMLinkPreview",
2020
dependencies: [],
2121
resources: [
22-
.copy("LinkPreview.xib")
22+
.process("LinkPreview.xib")
2323
]
2424
)
2525
// Currently the tests are in the Cocoapods example. Would be good to move them here or make them available here.
@@ -32,4 +32,4 @@ let package = Package(
3232
dependencies: [],
3333
resources: [.copy("README.md"), .copy("image.png")]
3434
)
35-
*/
35+
*/

Example.SPM/SMLInkPreview-SPM-Example/SMLInkPreview-SPM-Example.xcodeproj/project.pbxproj SMLinkPreview-SPM-Example/SMLinkPreview-SPM-Example.xcodeproj/project.pbxproj

+116-71
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "SMLinkPreview",
6+
"repositoryURL": "https://github.com/crspybits/SMLinkPreview",
7+
"state": {
8+
"branch": "master",
9+
"revision": "96713ace92f391f04a5783c78b1abe7cf10cd1f1",
10+
"version": null
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1210"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "8333E1D92568CAA700A5F79E"
18+
BuildableName = "SMLinkPreview-SPM-Example.app"
19+
BlueprintName = "SMLinkPreview-SPM-Example"
20+
ReferencedContainer = "container:SMLinkPreview-SPM-Example.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "8333E1D92568CAA700A5F79E"
48+
BuildableName = "SMLinkPreview-SPM-Example.app"
49+
BlueprintName = "SMLinkPreview-SPM-Example"
50+
ReferencedContainer = "container:SMLinkPreview-SPM-Example.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "8333E1D92568CAA700A5F79E"
65+
BuildableName = "SMLinkPreview-SPM-Example.app"
66+
BlueprintName = "SMLinkPreview-SPM-Example"
67+
ReferencedContainer = "container:SMLinkPreview-SPM-Example.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/chris/Desktop/NewSyncServer/Private/SMLinkPreview/APIKeys.plist

Example.SPM/SMLInkPreview-SPM-Example/SMLInkPreview-SPM-Example/AppDelegate.swift SMLinkPreview-SPM-Example/SMLinkPreview-SPM-Example/AppDelegate.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
//
22
// AppDelegate.swift
3-
// SMLInkPreview-SPM-Example
3+
// SMLinkPreview-SPM-Example
44
//
55
// Created by Christopher G Prince on 11/20/20.
66
//
77

88
import UIKit
9+
import SMLinkPreview
910

1011
@main
1112
class AppDelegate: UIResponder, UIApplicationDelegate {
12-
13-
14-
1513
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1614
// Override point for customization after application launch.
15+
1716
return true
1817
}
1918

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--View Controller-->
13+
<scene sceneID="ufC-wZ-h7g">
14+
<objects>
15+
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="SMLinkPreview_Example" customModuleProvider="target" sceneMemberID="viewController">
16+
<layoutGuides>
17+
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
18+
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
19+
</layoutGuides>
20+
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
22+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
23+
<subviews>
24+
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="rFU-sk-mew">
25+
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
26+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
27+
</tableView>
28+
</subviews>
29+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
30+
<constraints>
31+
<constraint firstAttribute="trailing" secondItem="rFU-sk-mew" secondAttribute="trailing" id="JL8-5K-s0h"/>
32+
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="rFU-sk-mew" secondAttribute="bottom" id="eDR-ek-jbp"/>
33+
<constraint firstItem="rFU-sk-mew" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="yO7-6u-kzG"/>
34+
<constraint firstItem="rFU-sk-mew" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" id="zYo-UG-JS1"/>
35+
</constraints>
36+
</view>
37+
<connections>
38+
<outlet property="tableView" destination="rFU-sk-mew" id="R78-Bk-vU7"/>
39+
</connections>
40+
</viewController>
41+
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
42+
</objects>
43+
<point key="canvasLocation" x="-239.19999999999999" y="60.719640179910051"/>
44+
</scene>
45+
</scenes>
46+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// LinkPreviewCell.swift
3+
// SMLinkPreview_Example
4+
//
5+
// Created by Christopher G Prince on 5/5/19.
6+
// Copyright © 2019 Spastic Muffin, LLC. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import SMLinkPreview
11+
12+
class LinkPreviewCell: UITableViewCell {
13+
static let verticalPadding:CGFloat = 20
14+
@IBOutlet weak var previewContainer: UIView!
15+
16+
override func awakeFromNib() {
17+
super.awakeFromNib()
18+
}
19+
20+
func setup(with linkPreview: LinkPreview) {
21+
previewContainer.subviews.forEach {$0.removeFromSuperview()}
22+
previewContainer.addSubview(linkPreview)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
6+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
8+
</dependencies>
9+
<objects>
10+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
11+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
12+
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="LinkPreviewCell" customModule="SMLinkPreview_SPM_Example" customModuleProvider="target">
13+
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
14+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
15+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
16+
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
17+
<autoresizingMask key="autoresizingMask"/>
18+
<subviews>
19+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="AYQ-5M-SCI">
20+
<rect key="frame" x="10" y="10" width="300" height="24"/>
21+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
22+
</view>
23+
</subviews>
24+
<constraints>
25+
<constraint firstItem="AYQ-5M-SCI" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="LQI-R9-eni"/>
26+
<constraint firstAttribute="bottom" secondItem="AYQ-5M-SCI" secondAttribute="bottom" constant="10" id="RUg-Dr-foD"/>
27+
<constraint firstItem="AYQ-5M-SCI" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="oVi-Mz-gpJ"/>
28+
<constraint firstAttribute="trailing" secondItem="AYQ-5M-SCI" secondAttribute="trailing" constant="10" id="zOd-fb-Sxy"/>
29+
</constraints>
30+
</tableViewCellContentView>
31+
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
32+
<connections>
33+
<outlet property="previewContainer" destination="AYQ-5M-SCI" id="Ria-Xh-dnL"/>
34+
</connections>
35+
<point key="canvasLocation" x="-77" y="42"/>
36+
</tableViewCell>
37+
</objects>
38+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// ViewController.swift
3+
// SMLinkPreview
4+
//
5+
// Created by crspybits on 04/20/2019.
6+
// Copyright (c) 2019 Spastic Muffin, LLC. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import SMLinkPreview
11+
12+
class ViewController: UIViewController {
13+
@IBOutlet weak var tableView: UITableView!
14+
var rowData = [LinkData]()
15+
var rowViews = [LinkPreview]()
16+
let reuseId = "ReuseId"
17+
18+
override func viewDidLoad() {
19+
super.viewDidLoad()
20+
21+
tableView.dataSource = self
22+
tableView.delegate = self
23+
tableView.register(UINib(nibName: "LinkPreviewCell", bundle: nil), forCellReuseIdentifier: reuseId)
24+
tableView.allowsSelection = false
25+
26+
func add(datum: LinkData, proportion: CGFloat = 1.0) {
27+
let preview = LinkPreview.create(with: datum)
28+
preview.heightAnchor.constraint(equalToConstant: preview.frame.height*proportion).isActive = true
29+
preview.widthAnchor.constraint(equalToConstant: preview.frame.width*proportion).isActive = true
30+
preview.translatesAutoresizingMaskIntoConstraints = false
31+
rowViews += [preview]
32+
}
33+
34+
let data0 = LinkData(url: URL(string: "http://www.cprince.com")!, title: "Home sweet home", description: "Welcome to my web page. Web pages are funny (they make me laugh). A store front for a person. An Internet presence. Information about yourself that every-internet-navigating person on the planet above age two can access. Is it the truth? Perhaps it’s Google-true?", image: URL(string: "http://cprince.com/WordPress/wp-content/uploads/2013/10/tree-225x300.jpg"), icon: URL(string: "https://cprince.com/WordPress/wp-content/uploads/2013/11/IMG_09254.jpg"))
35+
add(datum: data0, proportion: 0.75)
36+
37+
let data1 = LinkData(url: URL(string: "http://www.cprince.com")!, title: "Home sweet home", description: "Welcome to my web page. Web pages are funny (they make me laugh). A store front for a person. An Internet presence. Information about yourself that every-internet-navigating person on the planet above age two can access. Is it the truth? Perhaps it’s Google-true?", image: URL(string: "http://cprince.com/WordPress/wp-content/uploads/2013/10/tree-225x300.jpg"), icon: URL(string: "https://cprince.com/WordPress/wp-content/uploads/2013/11/IMG_09254.jpg"))
38+
rowData += [data1]
39+
40+
let data1b = LinkData(url: URL(string: "http://www.cprince.com")!, title: "Home sweet home and more text for the title", description: "Welcome to my web page. Web pages are funny (they make me laugh). A store front for a person. An Internet presence. Information about yourself that every-internet-navigating person on the planet above age two can access. Is it the truth? Perhaps it’s Google-true?", image: URL(string: "https://cprince.com/WordPress/wp-content/uploads/2013/10/tree-225x300.jpg"), icon: URL(string: "https://cprince.com/WordPress/wp-content/uploads/2013/11/IMG_09254.jpg"))
41+
rowData += [data1b]
42+
43+
let data2 = LinkData(url: URL(string: "http://www.cprince.com")!, title: nil, description: nil, image: nil, icon: nil)
44+
rowData += [data2]
45+
46+
let data3 = LinkData(url: URL(string: "http://www.cprince.com")!, title: nil, description: nil, image: nil, icon: URL(string: "https://cprince.com/WordPress/wp-content/uploads/2013/11/IMG_09254.jpg"))
47+
rowData += [data3]
48+
49+
let data4 = LinkData(url: URL(string: "http://www.cprince.com")!, title: "Home sweet home and more text for the title", description: nil, image: nil, icon: URL(string: "https://cprince.com/WordPress/wp-content/uploads/2013/11/IMG_09254.jpg"))
50+
rowData += [data4]
51+
52+
let data5 = LinkData(url: URL(string: "http://www.cprince.com")!, title: "Home sweet home and more text for the title", description: nil, image: nil, icon: nil)
53+
rowData += [data5]
54+
55+
for datum in rowData {
56+
add(datum: datum)
57+
}
58+
59+
PreviewManager.session.config = PreviewConfiguration(maxNumberTitleLines: 1)
60+
let data6 = LinkData(url: URL(string: "http://www.cprince.com")!, title: "Only a single line despite how much text I type because I forced it to be so.", description: nil, image: nil, icon: nil)
61+
add(datum: data6)
62+
PreviewManager.session.config = PreviewConfiguration()
63+
}
64+
}
65+
66+
extension ViewController : UITableViewDataSource, UITableViewDelegate {
67+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
68+
return rowViews.count
69+
}
70+
71+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
72+
73+
let cell = tableView.dequeueReusableCell(withIdentifier: reuseId, for: indexPath) as! LinkPreviewCell
74+
let preview = rowViews[indexPath.row]
75+
cell.setup(with: preview)
76+
77+
return cell
78+
}
79+
80+
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
81+
let preview = rowViews[indexPath.row]
82+
let height = preview.frame.height + LinkPreviewCell.verticalPadding
83+
return height
84+
}
85+
}

0 commit comments

Comments
 (0)