layout on orientation change

This commit is contained in:
Ryan Nystrom
2017-06-26 21:27:56 -07:00
parent 65289645af
commit 2149a141ad
8 changed files with 57 additions and 18 deletions

View File

@@ -41,6 +41,7 @@ final class IssueCommentQuoteCell: UICollectionViewCell, ListBindable, Collapsib
override func layoutSubviews() {
super.layoutSubviews()
LayoutCollapsible(layer: overlay, view: contentView)
textView.reposition(width: contentView.bounds.width)
for (i, border) in borders.enumerated() {
border.frame = CGRect(
x: Styles.Sizes.gutter + (IssueCommentQuoteCell.borderWidth + Styles.Sizes.columnSpacing) * CGFloat(i),

View File

@@ -32,6 +32,7 @@ final class IssueCommentTextCell: UICollectionViewCell, ListBindable, Collapsibl
override func layoutSubviews() {
super.layoutSubviews()
LayoutCollapsible(layer: overlay, view: contentView)
textView.reposition(width: contentView.bounds.width)
}
// MARK: ListBindable

View File

@@ -52,6 +52,11 @@ final class IssuesViewController: UIViewController, ListAdapterDataSource, FeedD
navigationItem.rightBarButtonItem = rightItem
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
feed.viewWillTransition(to: size, with: coordinator)
}
// MARK: Private API
func onMore() {

View File

@@ -39,6 +39,11 @@ RepoNotificationsSectionControllerDelegate {
feed.adapter.dataSource = self
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
feed.viewWillTransition(to: size, with: coordinator)
}
// MARK: Private API
private func update(fromNetwork: Bool) {

View File

@@ -75,6 +75,14 @@ final class Feed {
}
}
func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
let layout = collectionView.collectionViewLayout
layout.invalidateLayout()
coordinator.animate(alongsideTransition: { _ in
layout.invalidateLayout()
})
}
// MARK: Private API
private func refresh() {

View File

@@ -84,15 +84,21 @@ final class NSAttributedStringSizing: NSObject, ListDiffable {
if let cache = _textSize[width] {
return cache
}
return computeSize(width).size
return computeSize(width)
}
private var _textViewSize = [CGFloat: CGSize]()
func textViewSize(_ width: CGFloat) -> CGSize {
if let cache = _textViewSize[width] {
return cache
}
return computeSize(width).viewSize
return textSize(width).resized(inset: inset)
}
func rect(_ width: CGFloat) -> CGRect {
let size = textSize(width)
return CGRect(
x: inset.left,
y: inset.top,
width: size.width - inset.left - inset.right,
height: size.height - inset.top - inset.bottom
)
}
func configure(textView: UITextView) {
@@ -148,7 +154,7 @@ final class NSAttributedStringSizing: NSObject, ListDiffable {
// MARK: Private API
@discardableResult
func computeSize(_ width: CGFloat) -> (size: CGSize, viewSize: CGSize) {
func computeSize(_ width: CGFloat) -> CGSize {
let insetWidth = width - inset.left - inset.right
textContainer.size = CGSize(width: insetWidth, height: 0)
@@ -159,11 +165,7 @@ final class NSAttributedStringSizing: NSObject, ListDiffable {
let size = bounds.size.snapped(scale: screenScale)
_textSize[width] = size
// adjust for the text view inset (contentInset + textContainerInset)
let viewSize = size.resized(inset: inset)
_textViewSize[width] = viewSize
return (size, viewSize)
return size
}
// MARK: ListDiffable

View File

@@ -23,6 +23,7 @@ final class AttributedStringView: UIView {
backgroundColor = .white
isOpaque = true
layer.contentsGravity = kCAGravityTopLeft
let tap = UITapGestureRecognizer(target: self, action: #selector(AttributedStringView.onTap(recognizer:)))
@@ -36,16 +37,32 @@ final class AttributedStringView: UIView {
// MARK: Public API
func configureAndSizeToFit(text: NSAttributedStringSizing, width: CGFloat) {
self.text = text
layer.contentsScale = text.screenScale
func reposition(width: CGFloat) {
guard let text = text else { return }
layer.contents = text.contents(width)
let rect = CGRect(origin: .zero, size: text.textViewSize(width))
frame = UIEdgeInsetsInsetRect(rect, text.inset)
}
func configureAndSizeToFit(text: NSAttributedStringSizing, width: CGFloat) {
self.text = text
layer.contentsScale = text.screenScale
reposition(width: width)
}
// override func draw(_ rect: CGRect) {
// guard let text = text,
// let image = text.contents(rect.width),
// let context = UIGraphicsGetCurrentContext()
// else { return }
// let textRect = text.rect(rect.width)
// context.saveGState()
// context.translateBy(x: 0, y: textRect.height)
// context.scaleBy(x: 1, y: -1)
// context.draw(image, in: textRect)
// context.restoreGState()
// }
// MARK: Private API
func onTap(recognizer: UITapGestureRecognizer) {

View File

@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>50</string>
<string>88</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>org-appextension-feature-password-management</string>