-
Notifications
You must be signed in to change notification settings - Fork 1
PostView
##Overview
The PostView is a view written with flexibility in mind, so that it can adjust its UI and functionality depending on whether it is in the FeedViewController, PostHistoryTableViewController, or LikedTableViewController. Because it has to support so much functionality, there is quite a lot of logic in the view.
##Project Files
###PostView.swift
The main component of a PostView is a Post. Based on the type attribute, which is of type ViewType (Feed, History, Liked), the UI of the PostView will adjust accordingly.
For example, we can see how the imageView adjusts:
- Feed:
avatarImageViewis round and ispost.user.imageURL(user's FB profile pic) - History and Liked:
avatarImageViewis square, is the song's album art
All taps on the PostView are handled by postViewPressed(sender: UIGestureRecognizer). It detects hits on the likedButton, addButton, avatarImageView. These methods rely on the delegate, of type PostViewDelegate.
One of the most interesting features of the PostView is it's playing animation. As a song is playing, a rectangle will grow from left to right, proportional to the song's progress. Scrubbing is also handled through this rectangle.
This functionality is achieved in drawRect, which draws a rectangle with the width proportional to progress, and changeProgress, which handles the pan gesture. Based on where the swipe ends, the x coordinate is extracted and is divided by the entire cell width to get the progress of the song.
###PostViewDelegate
@objc protocol PostViewDelegate {
optional func didTapAddButtonForPostView(postView: PostView)
optional func didLongPressOnCell(postView: PostView)
optional func didTapImageForPostView(postView: PostView)
}
LikedTableViewController, FeedTableViewController, and PostHistoryTableViewController all implement PostViewDelegate.
##Current State PostView is likely to change if we decide to redesign some of the feed. Right now, the "like" and "add" buttons are hard to click and a bit buggy. Those changes should reside mainly in the UI, so the structure of the PostView should stay relatively intact.
##External Sources