-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/1260 Detecting and Cleaning Galleries #8119
Feature/1260 Detecting and Cleaning Galleries #8119
Conversation
…cting and cleaning galleries
@@ -332,12 +332,12 @@ class BlockquoteTagProcessor: HtmlTagProcessor { | |||
if !matched { | |||
return (parsedString, nil) | |||
} | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
@@ -6,7 +6,7 @@ import WordPressShared | |||
/// HTML tags that require special handling before the text is shown in a UITextView. | |||
/// | |||
class WPRichTextFormatter { | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
@@ -332,12 +332,12 @@ class BlockquoteTagProcessor: HtmlTagProcessor { | |||
if !matched { | |||
return (parsedString, nil) | |||
} | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
@@ -6,7 +6,7 @@ import WordPressShared | |||
/// HTML tags that require special handling before the text is shown in a UITextView. | |||
/// | |||
class WPRichTextFormatter { | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
…, new ReaderGalleryCell for use in WPRichTextGallery
let cell : ReaderGalleryCell | ||
let attachment : WPTextAttachment | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
|
||
struct GalleryMedia { | ||
let cell : ReaderGalleryCell | ||
let attachment : WPTextAttachment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
} | ||
|
||
struct GalleryMedia { | ||
let cell : ReaderGalleryCell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
|
||
} | ||
|
||
extension WPRichTextGallery : UICollectionViewDelegateFlowLayout { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
|
||
collectionView.reloadData() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | ||
let rightInset = CGFloat(8.0) | ||
let rightExtraContent = CGFloat(8.0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
extension WPRichTextGallery : UICollectionViewDelegateFlowLayout { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
return cell | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
let media = GalleryMedia(cell: cell, attachment: attachment) | ||
mediaArray.append(media) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Gallery is now in the pull request. Still to do: zoomed in gallery, pagination for inline gallery, clean up code, support for image subtitle. |
…troller to work with gallery, delegate functions, changes to WPRichTextGallery to make it all work
more clean up, fix collectionview sizing a bit (needs better sizing for showing edges of past and previous cards and some attention to iPad)
} | ||
|
||
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | ||
scrollToPage(scrollView, withVelocity: CGPoint(x:0, y:0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
page = max(page, 0) | ||
let newOffset: CGFloat = CGFloat(page) * (cellWidth + cellPadding) | ||
|
||
scrollView.setContentOffset(CGPoint(x:newOffset, y:0), animated: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
|
||
fileprivate var collectionView: UICollectionView | ||
var captionLabel : UILabel? | ||
var pageLabel : UILabel? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
}() | ||
|
||
fileprivate var collectionView: UICollectionView | ||
var captionLabel : UILabel? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
var contentURL: URL? | ||
var linkURL: URL? | ||
|
||
var cellSize : CGFloat = 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)
|
||
scrollView.setContentOffset(CGPoint(x:newOffset, y:0), animated: true) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
page = max(page, 0) | ||
let newOffset: CGFloat = CGFloat(page) * (cellWidth + cellPadding) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
func scrollToPage(_ scrollView: UIScrollView, withVelocity velocity: CGPoint) { | ||
let cellWidth: CGFloat = cellSize | ||
let cellPadding: CGFloat = 8 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { | ||
scrollToPage(scrollView, withVelocity: velocity) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
/* In case the user scrolls for a long swipe, the scroll view should animate to the nearest page when the scrollview decelerated. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Howdy @autojeff 👋 You've been busy!
I've taken an early peek through the code so far. I've noted a few things and made a few suggestions.
I also had a couple of questions.
I did take a peek at the UI but I know there are things you're still looking at there so I'm holding my comments. :)
I'm happy to chat about any of the comments I've made or clarify anything that might not be clear. Just let me know.
@@ -12,4 +12,10 @@ extension Array { | |||
} | |||
} | |||
} | |||
|
|||
//Safely returns an index from an array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is //Safely
is missing a /
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aerych Do you mean like this? "/// Safely"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! :)
// | ||
// Created by Jeff Jacka on 11/11/17. | ||
// Copyright © 2017 WordPress. All rights reserved. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid this sort of header comment.
|
||
@IBOutlet weak var galleryImageView: UIImageView! | ||
|
||
override func awakeFromNib() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove this overridden method if all it will do is call the super implementation.
// | ||
// Created by Jeff Jacka on 11/12/17. | ||
// Copyright © 2017 WordPress. All rights reserved. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before about file header comments.
} | ||
|
||
dataSource = self | ||
// Do any additional setup after loading the view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we could clean up boilerplate comments like this one.
|
||
//Replace Div with Gallery tag | ||
content = RegEx.galleryDivStart.stringByReplacingMatches(in: content, options: .reportCompletion, range: NSRange(location: 0, length: content.count), withTemplate: galleryStart) | ||
content = RegEx.galleryDivEnd.stringByReplacingMatches(in: content, options: .reportCompletion, range: NSRange(location: 0, length: content.count), withTemplate: galleryEnd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the use of regular expressions to handle string replacement rather than have it handled by the Scanner. Was there a particular reason that made regex a better choice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking behind this was to the keep the logic a bit more simple. This function scanForGalleryBy(galleryType : String, inString : String)
only scans and identifies where a gallery should start and end. Then clean it up with the RegEx, rather than using another Scanner. It could be done in one go, but this felt like a safe, reliable option to me.
|
||
// Trailing BR Tags | ||
static let trailingBRTags = try! NSRegularExpression(pattern: "(\\s*<br\\s*(/?)\\s*>\\s*)+$", options: .caseInsensitive) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove the newly added returns?
|
||
func contentRatio() -> CGFloat { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need the white space between the method definition and body here and above.
|
||
if galleriesFound <= 0 { | ||
//check for gallery | ||
galleryScanner.scanUpTo(galleryType, into: &tempStr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if
and else
blocks share some similarity in the way the start. Maybe there is an opportunity for a small refactor to reuse some code?
@@ -102,8 +109,10 @@ - (void)viewDidLoad | |||
[tgr1 requireGestureRecognizerToFail:tgr2]; | |||
[self.scrollView addGestureRecognizer:tgr1]; | |||
|
|||
self.flingableViewHandler = [[FlingableViewHandler alloc] initWithTargetView:self.scrollView]; | |||
self.flingableViewHandler.delegate = self; | |||
if (!self.galleryMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since galleryMode
is only flagging whether the FlingableViewHandle
should be used, it might be nice to rename it according to how its used. Then if we extend WPImageViewController
in the future and add more init
s, the flag could be reused in a new context. Make sense?
…, fix labels not showing up until swiped
fileprivate func handleSwipeGesture(_ recognizer: UISwipeGestureRecognizer) { | ||
|
||
isActive = false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
@objc | ||
fileprivate func handleSwipeGesture(_ recognizer: UISwipeGestureRecognizer) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
targetView.addGestureRecognizer(panGestureRecognizer) | ||
isActive = true | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
//Allow swipe gestures to pass through first | ||
panGestureRecognizer.require(toFail: leftSwipe) | ||
panGestureRecognizer.require(toFail: rightSwipe) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeGesture(_:))) | ||
leftSwipe.direction = .left | ||
targetView.addGestureRecognizer(leftSwipe) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
@@ -43,11 +43,31 @@ class FlingableViewHandler: NSObject { | |||
animator = UIDynamicAnimator(referenceView: targetView.superview!) | |||
|
|||
super.init() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
fix gallery padding so they align correctly
} | ||
|
||
extension WPRichTextGallery: UICollectionViewDelegateFlowLayout { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
collectionView.showsHorizontalScrollIndicator = false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
setupCollectionView() | ||
setupLabels() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
override open var frame: CGRect { | ||
didSet { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just been reviewing this, but don't quite have time to go through it all right now – so I'll finish up later.
Functionally, this seems to work pretty well! The galleries are parsed out, I can view the images and flick through them, which is great. I've added bunch code comments - a lot of it is style or naming or organization, rather than fundamental issues. Hopefully it's all useful, but let me know if you have any questions!
Two functional issues I did see:
- I think it'd be good if we set the background colour behind the gallery to black, otherwise you see it when you scroll to the edge:
Also the status bar is black-on-black there – again, you can see it when you scroll off. We should probably hide it altogether or make it lightContent
style.
- I think it's largely down to
UIPageViewController
, but you can see the images appear / disappear as you scroll, which is a little jarring. It'd be nice if those transitions happen offscreen:
@@ -1076,6 +1076,16 @@ extension ReaderDetailViewController: WPRichContentViewDelegate { | |||
|
|||
present(controller, animated: true, completion: nil) | |||
} | |||
|
|||
func richContentView(_ richContentView: WPRichContentView, didReceiveGalleryAction image: [WPTextAttachment], indexTapped index: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second parameter name here feels slightly confusing, I think. didReceiveGalleryAction
doesn't really explain what the parameter contains, and the inner name is image
but it looks like it contains an array of images (plural)? How about didReceiveGalleryActionWithImages images: [WPTextAttachment]
?
/// | ||
/// - Return: A WPGalleryPageViewController instance. | ||
/// | ||
open class func controllerWithImages(_ images: [WPTextAttachment], selectedIndex: Int) -> WPGalleryPageViewController { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in Swift 3 / 4, this might be best named something like controller(with images: [WPTextAttachment], selectedIndex: Int)
In fact, we could probably add a default value for selected index (= 0
?) to allow it to be omitted?
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
if let initalVC = imageViewControllerForIndex(index: initialIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: initalVC
-> initialVC
dataSource = self | ||
} | ||
|
||
func imageViewControllerForIndex(index: Int) -> WPImageViewController? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift's API guidelines (as far as I know) recommend against duplicating parameter names like this – something like imageViewController(for index: Int)
or imageViewControllerFor(index: Int)
would be a better fit, I think.
return nil | ||
} | ||
|
||
let urlString = imageAttachment.attributes?["data-large-file"] ?? imageAttachment.src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to pull "data-large-file"
out into a constant.
@@ -5,6 +5,7 @@ import WordPressShared | |||
|
|||
@objc protocol WPRichContentViewDelegate: UITextViewDelegate { | |||
func richContentView(_ richContentView: WPRichContentView, didReceiveImageAction image: WPRichTextImage) | |||
func richContentView(_ richContentView: WPRichContentView, didReceiveGalleryAction image: [WPTextAttachment], indexTapped index: Int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comment about the name of this method.
@@ -283,6 +286,48 @@ extension WPRichContentView: WPTextAttachmentManagerDelegate { | |||
return img | |||
} | |||
|
|||
func galleryForAttachment(_ attachment: WPTextAttachment) -> WPRichTextGallery { | |||
|
|||
let width: CGFloat = attachment.width > 0 ? attachment.width : self.bounds.width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can omit self.
here.
let formatter = WPRichTextFormatter() | ||
let (_, attachments) = formatter.processAndExtractTags(content) | ||
|
||
gallery.imageAttachments = attachments.filter({ (attachment) -> Bool in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could condense this if you like, to attachments.filter({ $0.tagName == "img" })
let layout: UICollectionViewFlowLayout = { | ||
let layout = UICollectionViewFlowLayout() | ||
layout.scrollDirection = .horizontal | ||
layout.minimumInteritemSpacing = 8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use a constant for these values – or should this be using cellPadding
?
} | ||
} | ||
} | ||
var handleGalleryTapped : ((_ selectedIndex: Int, _ galleryImages: [WPTextAttachment]) -> ())? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but there shouldn't be a space before a :
here. Also -> Void
is preferred over -> ()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I added a few more comments! Let me know if you have any questions 👍
let source = WPTableImageSource(maxSize: self.maxDisplaySize) | ||
source?.delegate = self | ||
source?.forceLargerSizeWhenFetching = false | ||
source?.photonQuality = 65 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a constant for this – looks like WPRichContentView
has one in its Constants
struct.
/// | ||
|
||
fileprivate let galleryCellIdentifier = "ReaderGalleryCell" | ||
fileprivate let contentUrlKey = "contentUrl" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These identifiers could be grouped together in a struct or enum.
setupCollectionView() | ||
setupLabels() | ||
|
||
collectionView.isPrefetchingEnabled = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just go in setupCollectionView
?
aCoder.encode(footerStack, forKey: UIStackView.classNameWithoutNamespaces()) | ||
|
||
if let url = contentURL { | ||
aCoder.encode(url, forKey: "contentURL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the constant keys defined at the top of the file here - contentUrlKey
, etc.
extension WPRichTextGallery: UICollectionViewDelegateFlowLayout { | ||
|
||
func setOffsetIfNeeded() { | ||
//TODO: Still Needs Fixing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still valid? What's the issue exactly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, you made a nice gif of the issue I'm having with the gallery UICollectionView so a few things need to be changed in this area. The problem I am having is that when my gallery gets it frame from the UIRichContentView/TextView it is respecting the contentInset from that textView, however this causes issues with the UICollectionView because from the design I have attempted to build it should probably be the full width of the app to prevent that disappearing issue you showed here (https://user-images.githubusercontent.com/4780/32897805-738be56a-cade-11e7-80b3-3d1aa4b5845a.gif). So I think I have a two options, change the design or stretch the frame to be the width of the screen, use contentInsets to handle some of the padding, this should make the disappearing issue go away. Would love some feedback/opinions on what the best options here might be from both a design and development standpoint.
/// | ||
|
||
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { | ||
scrollToPage(scrollView, withVelocity: velocity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, rather than calling setContentOffset
from this method, you should set targetContentOffset
to the offset that you calculate – this will result in a smoother deceleration, instead of stopping in the wrong place and then animating to the correct one.
} | ||
|
||
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | ||
scrollToPage(scrollView, withVelocity: CGPoint(x: 0, y: 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary if scrollViewWillEndDragging
is implemented and sets an adjusted offset?
/// | ||
/// - Returns: The formatted string. | ||
/// | ||
public class func normalizeGallery(_ string : String) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, no space before :
var tempStr: NSString? = "" | ||
|
||
var divCounter = 0 | ||
var galleriesFound : Int = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, no space before :
return content | ||
} | ||
|
||
private class func scanForGalleryBy(galleryType : String, inString : String) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to break this method down at all, to make it a little easier to follow? Can we add some tests?
…tionary to store WPImageViewControllers in use
|
||
setupCollectionView() | ||
setupLabels() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
aCoder.encode(viewHeight, forKey: viewHeightKey) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
if let url = linkURL { | ||
aCoder.encode(url, forKey: linkUrlKey) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
if let url = contentURL { | ||
aCoder.encode(url, forKey: contentUrlKey) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
aCoder.encode(collectionView, forKey: UICollectionView.classNameWithoutNamespaces()) | ||
aCoder.encode(footerStack, forKey: UIStackView.classNameWithoutNamespaces()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
extension WPGalleryPageViewController : UIPageViewControllerDelegate { | ||
|
||
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
} | ||
|
||
extension WPGalleryPageViewController : UIPageViewControllerDelegate { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
guard let index = imageViewControllers[imageVC] else { | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
guard let imageVC = viewController as? WPImageViewController else { | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
guard let imageVC = viewController as? WPImageViewController else { | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Closing. |
#1260 …detecting and cleaning galleries
Fixes #
Remove deprecated characters.count
To test:
Detection for gallery markup
Needs review: @aerych