Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Stepkin committed May 4, 2016
1 parent 23bbe54 commit eb064a0
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 331 deletions.
22 changes: 0 additions & 22 deletions RAMReel/AppDelegate.swift

This file was deleted.

41 changes: 0 additions & 41 deletions RAMReel/Base.lproj/LaunchScreen.xib

This file was deleted.

83 changes: 0 additions & 83 deletions RAMReel/Base.lproj/Main.storyboard

This file was deleted.

15 changes: 7 additions & 8 deletions RAMReel/Framework/CollectionViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ class RAMCollectionViewLayout: UICollectionViewLayout {

internal override func collectionViewContentSize() -> CGSize {

if let collectionView = self.collectionView
{
let number = collectionView.numberOfItemsInSection(0)
let height = CGFloat(number) * itemHeight

let size = CGSize(width: collectionView.bounds.width, height: height)
return size
guard let collectionView = self.collectionView else {
return CGSize.zero
}

return CGSizeZero
let number = collectionView.numberOfItemsInSection(0)
let height = CGFloat(number) * itemHeight

let size = CGSize(width: collectionView.bounds.width, height: height)
return size

}
}
Expand Down
47 changes: 23 additions & 24 deletions RAMReel/Framework/CollectionViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,19 @@ public class CollectionViewWrapper

var selectedItem: DataType?
func indexCallback(idx: Int?) {
if let index = idx
where 0 <= index && index < data.count {
let item = data[index]
selectedItem = item

// TODO: Update cell appearance maybe?
// Toggle selected?
let indexPath = NSIndexPath(forItem: index, inSection: 0)
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell?.selected = true
}
else {
guard let index = idx where 0 <= index && index < data.count else {
selectedItem = nil
return
}

let item = data[index]
selectedItem = item

// TODO: Update cell appearance maybe?
// Toggle selected?
let indexPath = NSIndexPath(forItem: index, inSection: 0)
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell?.selected = true
}

// MARK Implementation of WrapperProtocol
Expand All @@ -183,12 +182,11 @@ public class CollectionViewWrapper

func cellAttributes(rect: CGRect) -> [UICollectionViewLayoutAttributes] {
let layout = collectionView.collectionViewLayout
if let attributes = layout.layoutAttributesForElementsInRect(rect)
{
return attributes
guard let attributes = layout.layoutAttributesForElementsInRect(rect) else {
return []
}

return []
return attributes
}

// MARK: Update & Adjust
Expand All @@ -201,13 +199,15 @@ public class CollectionViewWrapper
let number = self.collectionView.numberOfItemsInSection(0)
let itemIndex = self.scrollDelegate.itemIndex ?? number/2

if itemIndex > 0 {
let inset = self.collectionView.contentInset.top
let itemHeight = self.collectionLayout.itemHeight
let offset = CGPoint(x: 0, y: CGFloat(itemIndex) * itemHeight - inset)

self.collectionView.contentOffset = offset
guard itemIndex > 0 else {
return
}

let inset = self.collectionView.contentInset.top
let itemHeight = self.collectionLayout.itemHeight
let offset = CGPoint(x: 0, y: CGFloat(itemIndex) * itemHeight - inset)

self.collectionView.contentOffset = offset
}
}

Expand Down Expand Up @@ -244,8 +244,7 @@ class ScrollViewDelegate: NSObject, UIScrollViewDelegate {
var itemIndexChangeCallback: ItemIndexChangeCallback?
private(set) var itemIndex: Int? = nil {
willSet (newIndex) {
if let callback = itemIndexChangeCallback
{
if let callback = itemIndexChangeCallback {
callback(newIndex)
}
}
Expand Down
13 changes: 10 additions & 3 deletions RAMReel/Framework/RAMReel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,17 @@ public class RAMReel
/// Visual appearance theme
public var theme: Theme = RAMTheme.sharedTheme {
didSet {
if theme.font != oldValue.font || theme.listBackgroundColor != oldValue.listBackgroundColor || theme.textColor != oldValue.textColor {
updateVisuals()
updatePlaceholder(self.placeholder)
guard theme.font != oldValue.font
||
theme.listBackgroundColor != oldValue.listBackgroundColor
||
theme.textColor != oldValue.textColor
else {
return
}

updateVisuals()
updatePlaceholder(self.placeholder)
}
}

Expand Down
21 changes: 11 additions & 10 deletions RAMReel/Framework/RAMTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RAMTextField: UITextField {
Overriding UIView's drawRect method to add line in the bottom of the Text Field

- parameter rect: Rect that should be updated. This override ignores this parameter and redraws all text field
*/
*/
override public func drawRect(rect: CGRect) {
let rect = self.bounds
let ctx = UIGraphicsGetCurrentContext()
Expand Down Expand Up @@ -50,7 +50,7 @@ extension UITextField {

/**
Overriding `UITextField` `tintColor` property to make it affect close image tint color.
*/
*/
public override var tintColor: UIColor! {
get {
return super.tintColor
Expand All @@ -61,13 +61,14 @@ extension UITextField {

let subviews = self.subviews
for view in subviews {
if let button = view as? UIButton
{
let states: [UIControlState] = [.Normal, .Highlighted]
states.forEach { state -> Void in
let image = button.imageForState(state)?.tintedImage(self.tintColor)
button.setImage(image, forState: state)
}
guard let button = view as? UIButton else {
break
}

let states: [UIControlState] = [.Normal, .Highlighted]
states.forEach { state -> Void in
let image = button.imageForState(state)?.tintedImage(self.tintColor)
button.setImage(image, forState: state)
}
}
}
Expand All @@ -83,7 +84,7 @@ extension UIImage {
Create new image by applying a tint.

- parameter color: New image tint color.
*/
*/
public func tintedImage(color: UIColor) -> UIImage {
let size = self.size

Expand Down
68 changes: 0 additions & 68 deletions RAMReel/Images.xcassets/AppIcon.appiconset/Contents.json

This file was deleted.

Loading

0 comments on commit eb064a0

Please sign in to comment.