Skip to content

Commit ffef90a

Browse files
committed
preparing for rebase
1 parent ffda595 commit ffef90a

3 files changed

Lines changed: 150 additions & 6 deletions

File tree

Example/Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ PODS:
8989
- Prelude (~> 3.0)
9090
- PlaygroundVCHelpers (0.0.2)
9191
- Prelude (3.0.0)
92-
- SDWebImage (5.12.1):
93-
- SDWebImage/Core (= 5.12.1)
94-
- SDWebImage/Core (5.12.1)
92+
- SDWebImage (5.12.2):
93+
- SDWebImage/Core (= 5.12.2)
94+
- SDWebImage/Core (5.12.2)
9595
- Slippers/Core (0.1.1)
9696

9797
DEPENDENCIES:
@@ -133,13 +133,13 @@ CHECKOUT OPTIONS:
133133
:commit: b18c46a4d4f833fbea79930783225b988c7621b0
134134
:git: https://github.com/LithoByte/flex-data-source
135135
fuikit:
136-
:commit: 3d8e64ed509d23bf46f8cb31eaa1fcd13d00645a
136+
:commit: 5ca748d86d04756bcc448f12d3c11afa2403af75
137137
:git: https://github.com/LithoByte/fuikit
138138
FunNet:
139139
:commit: cc221683fff2984b2a06518133567c1ac5658edc
140140
:git: https://github.com/LithoByte/funnet
141141
LithoOperators:
142-
:commit: e1203c96bfd693bc3579b6080439e2580716d9e4
142+
:commit: 443b07ee450cda946647da8f9e7414b5628b4800
143143
:git: https://github.com/LithoByte/LithoOperators
144144
LithoUtils:
145145
:commit: a636308969618cab4fcd50e5ed1c362a0ab1e3e3
@@ -160,7 +160,7 @@ SPEC CHECKSUMS:
160160
LUX: a0a8013d109a4d4887f75fcc91637221e6749abb
161161
PlaygroundVCHelpers: c7cc8994d2851ebd1590217101b4c6888d1c9cc8
162162
Prelude: fe4cc0fd961d34edf48fe6b04d05c863449efb0a
163-
SDWebImage: 4dc3e42d9ec0c1028b960a33ac6b637bb432207b
163+
SDWebImage: 240e5c12b592fb1268c1d03b8c90d90e8c2ffe82
164164
Slippers: 5a3c6f24a556a59a091e2cb60e588472827be87c
165165

166166
PODFILE CHECKSUM: 1b66245eee991810fd91d285a3d3eeb51952bc85
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// LUXImageTableViewCell.swift
3+
// LUX
4+
//
5+
// Created by Calvin Collins on 12/3/21.
6+
//
7+
8+
import UIKit
9+
import SDWebImage
10+
import Prelude
11+
import LithoOperators
12+
13+
open class LUXImageTableViewCell: UITableViewCell {
14+
@IBOutlet weak public var contentImageView: UIImageView?
15+
@IBOutlet weak public var imageTopMargin: NSLayoutConstraint?
16+
@IBOutlet weak public var imageLeadingMargin: NSLayoutConstraint?
17+
@IBOutlet weak public var imageTrailingMargin: NSLayoutConstraint?
18+
@IBOutlet weak public var imageBottomMargin: NSLayoutConstraint?
19+
@IBOutlet weak public var imageHeightConstraint: NSLayoutConstraint?
20+
@IBOutlet weak public var imageWidthConstraint: NSLayoutConstraint?
21+
22+
/**
23+
* The LUX provided XIB for this class does not include this constraint, as it could conflict with width/height constraints.
24+
* It is provided here for storing an aspect ratio constraint, or for subclasses that want to use it as an outlet.
25+
* If you'd like to use aspect ratio instead of width/height, we recommend looking at the code in bindUrlStringToCell, or
26+
* just using bindUrlString.
27+
*/
28+
@IBOutlet weak public var aspectRatioConstraint: NSLayoutConstraint?
29+
30+
open override func awakeFromNib() {
31+
super.awakeFromNib()
32+
// Initialization code
33+
}
34+
}
35+
36+
public func bindUrlString<CellType>(to imageView: UIImageView?,
37+
from urlString: String,
38+
storingConstraintIn kp: WritableKeyPath<CellType, NSLayoutConstraint?>,
39+
on cell: CellType)
40+
where CellType: UITableViewCell {
41+
if let url = URL(string: urlString) {
42+
imageView?.sd_setImage(with: url, completed: { image, _, _, _ in
43+
let tableView = cell.superview as? UITableView
44+
tableView?.beginUpdates()
45+
46+
cell |> set(kp, applyRatioImageConstraint(to: imageView, for: image, removing: cell[keyPath: kp]))
47+
48+
tableView?.endUpdates()
49+
})
50+
}
51+
}
52+
53+
public func bindUrlStringToCell(_ cell: LUXImageTableViewCell, urlString: String) {
54+
if let url = URL(string: urlString) {
55+
cell.contentImageView?.sd_setImage(with: url, completed: { image, _, _, _ in
56+
if let imageView = cell.contentImageView {
57+
cell.imageHeightConstraint ?> imageView.removeConstraint(_:)
58+
cell.imageWidthConstraint ?> imageView.removeConstraint(_:)
59+
}
60+
61+
let tableView = cell.superview as? UITableView
62+
tableView?.beginUpdates()
63+
64+
cell.aspectRatioConstraint = applyRatioImageConstraint(to: cell.contentImageView, for: image, removing: cell.aspectRatioConstraint)
65+
66+
tableView?.endUpdates()
67+
})
68+
}
69+
}
70+
71+
public func applyRatioImageConstraint(to imageView: UIImageView?, for image: UIImage?, removing oldConstraint: NSLayoutConstraint?) -> NSLayoutConstraint? {
72+
if let imageView = imageView, let image = image {
73+
let imageSize = image.size
74+
let ratio = imageSize.height / imageSize.width
75+
76+
if let oldConstraint = oldConstraint {
77+
imageView.removeConstraint(oldConstraint)
78+
}
79+
80+
imageView.translatesAutoresizingMaskIntoConstraints = false
81+
82+
let newConstraint = NSLayoutConstraint(item: imageView,
83+
attribute: .height,
84+
relatedBy: .equal,
85+
toItem: imageView,
86+
attribute: .width,
87+
multiplier: ratio,
88+
constant: 0)
89+
imageView.addConstraint(newConstraint)
90+
NSLayoutConstraint.activate([newConstraint])
91+
92+
return newConstraint
93+
}
94+
95+
return nil
96+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19162" 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+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<objects>
11+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
12+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
13+
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="148" id="KGk-i7-Jjw" customClass="LUXImageTableViewCell" customModule="LUX" customModuleProvider="target">
14+
<rect key="frame" x="0.0" y="0.0" width="320" height="148"/>
15+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
16+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
17+
<rect key="frame" x="0.0" y="0.0" width="320" height="148"/>
18+
<autoresizingMask key="autoresizingMask"/>
19+
<subviews>
20+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="vQf-pT-LEy">
21+
<rect key="frame" x="10" y="10" width="300" height="128"/>
22+
<constraints>
23+
<constraint firstAttribute="height" constant="128" id="Bb4-NP-w2P"/>
24+
<constraint firstAttribute="width" constant="300" id="b9k-l3-zm2"/>
25+
</constraints>
26+
</imageView>
27+
</subviews>
28+
<constraints>
29+
<constraint firstAttribute="bottom" secondItem="vQf-pT-LEy" secondAttribute="bottom" constant="10" id="23G-aM-GLI"/>
30+
<constraint firstItem="vQf-pT-LEy" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="4wV-1l-Uhl"/>
31+
<constraint firstAttribute="trailing" secondItem="vQf-pT-LEy" secondAttribute="trailing" constant="10" id="RJH-Vc-agc"/>
32+
<constraint firstItem="vQf-pT-LEy" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="o0N-lF-K8h"/>
33+
</constraints>
34+
</tableViewCellContentView>
35+
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
36+
<connections>
37+
<outlet property="contentImageView" destination="vQf-pT-LEy" id="stL-n8-V0e"/>
38+
<outlet property="imageBottomMargin" destination="23G-aM-GLI" id="CPl-Gg-Fo4"/>
39+
<outlet property="imageHeightConstraint" destination="Bb4-NP-w2P" id="zjT-4s-ngA"/>
40+
<outlet property="imageLeadingMargin" destination="4wV-1l-Uhl" id="bBc-ta-vzz"/>
41+
<outlet property="imageTopMargin" destination="o0N-lF-K8h" id="46j-iw-S0t"/>
42+
<outlet property="imageTrailingMargin" destination="RJH-Vc-agc" id="yUi-n1-k4m"/>
43+
<outlet property="imageWidthConstraint" destination="b9k-l3-zm2" id="8Zh-Ny-v5u"/>
44+
</connections>
45+
<point key="canvasLocation" x="137.68115942028987" y="113.16964285714285"/>
46+
</tableViewCell>
47+
</objects>
48+
</document>

0 commit comments

Comments
 (0)