Skip to content

Commit

Permalink
Merge pull request #342 from hyperoslo/improve/reload-with-components
Browse files Browse the repository at this point in the history
Improve reload with components
  • Loading branch information
vadymmarkov authored Oct 24, 2016
2 parents 10c8c7f + 77f6d2a commit 0c085d0
Show file tree
Hide file tree
Showing 15 changed files with 628 additions and 288 deletions.
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ osx_image: xcode8
language: objective-c

before_install:
- brew update
- if brew outdated | grep -qx xctool; then brew upgrade xctool; fi
- if brew outdated | grep -qx carthage; then brew upgrade carthage; fi
- travis_wait 35 carthage bootstrap --platform iOS,Mac
- travis_wait 35 carthage bootstrap --platform iOS,Mac,tvOS

script:
- xcodebuild clean build -project Spots.xcodeproj -scheme "Spots-iOS" -sdk iphonesimulator
- xcodebuild test -project Spots.xcodeproj -scheme "Spots-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0'
- xcodebuild clean build -project Spots.xcodeproj -scheme "Spots-Mac" -sdk macosx
- xcodebuild test -project Spots.xcodeproj -scheme "Spots-Mac" -sdk macosx
#- xcodebuild clean build -project Spots.xcodeproj -scheme "Spots-tvOS" -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=9.2'
#- xcodebuild test -project Spots.xcodeproj -scheme "Spots-tvOS" -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=9.2'
- xcodebuild clean build -project Spots.xcodeproj -scheme "Spots-iOS" -sdk iphonesimulator | xcpretty
- xcodebuild test -project Spots.xcodeproj -scheme "Spots-iOS" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0' | xcpretty
- xcodebuild clean build -project Spots.xcodeproj -scheme "Spots-Mac" -sdk macosx | xcpretty
- xcodebuild test -project Spots.xcodeproj -scheme "Spots-Mac" -sdk macosx | xcpretty
- xcodebuild clean build -project Spots.xcodeproj -scheme "Spots-tvOS" -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=10.0' | xcpretty
- xcodebuild test -project Spots.xcodeproj -scheme "Spots-tvOS" -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=10.0' | xcpretty

notifications:
email: false
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "krzyzanowskim/CryptoSwift" "0.6.1"
github "zenangst/Tailor" "2.0.1"
github "hyperoslo/Brick" "2.0.1"
github "hyperoslo/Cache" "2.0.0"
github "hyperoslo/Cache" "2.1.1"
2 changes: 1 addition & 1 deletion Sources/Shared/Extensions/Item+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public extension Item {
if kind != oldItem.kind { return .kind }
if newChildren != oldChildren { return .children }
if identifier != oldItem.identifier { return .identifier }
if size.height != oldItem.size.height { return .size }
if size != oldItem.size { return .size }
if title != oldItem.title { return .title }
if subtitle != oldItem.subtitle { return .subtitle }
if text != oldItem.text { return .text }
Expand Down
37 changes: 27 additions & 10 deletions Sources/Shared/Extensions/Spotable+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if os(iOS)
import UIKit
#else
#if os(OSX)
import Foundation
#else
import UIKit
#endif

import Brick
Expand Down Expand Up @@ -156,13 +156,21 @@ public extension Spotable {

/// Prepare items in component
func prepareItems() {
component.items.enumerated().forEach { (index: Int, _) in
configureItem(at: index, usesViewSize: true)
component.items = prepare(items: component.items)
}

func prepare(items: [Item]) -> [Item] {
var preparedItems = items
preparedItems.enumerated().forEach { (index: Int, item: Item) in
if let configuredItem = configure(item: item, usesViewSize: true) {
preparedItems[index].index = index
preparedItems[index] = configuredItem
}
if component.span > 0.0 {
#if os(OSX)
if let gridable = self as? Gridable,
let layout = gridable.layout as? FlowLayout {
component.items[index].size.width = gridable.collectionView.frame.width / CGFloat(component.span) - layout.sectionInset.left - layout.sectionInset.right
preparedItems[index].size.width = gridable.collectionView.frame.width / CGFloat(component.span) - layout.sectionInset.left - layout.sectionInset.right
}
#else
var spotWidth = render().frame.size.width
Expand All @@ -172,10 +180,12 @@ public extension Spotable {
}

let newWidth = spotWidth / CGFloat(component.span)
component.items[index].size.width = newWidth
preparedItems[index].size.width = newWidth
#endif
}
}

return preparedItems
}

/// Resolve item at index.
Expand Down Expand Up @@ -290,16 +300,22 @@ public extension Spotable {
/// - parameter index: The index of the view model
/// - parameter usesViewSize: A boolean value to determine if the view uses the views height
public func configureItem(at index: Int, usesViewSize: Bool = false) {
guard var item = item(at: index) else { return }
guard let item = item(at: index),
let configuredItem = configure(item: item, usesViewSize: usesViewSize) else { return }

component.items[index] = configuredItem
}

func configure(item: Item, usesViewSize: Bool = false) -> Item? {
var item = item
item.index = index

let kind = item.kind.isEmpty || Self.views.storage[item.kind] == nil
? Self.views.defaultIdentifier
: item.kind

guard let (_, resolvedView) = Self.views.make(kind),
let view = resolvedView else { return }
let view = resolvedView else { return nil }

#if !os(OSX)
if let composite = view as? Composable {
Expand Down Expand Up @@ -348,8 +364,9 @@ public extension Spotable {
item.size.width = UIScreen.main.bounds.width / CGFloat(component.span)
}
#endif
component.items[index] = item
}

return item
}

/// Update and return the size for the item at index path.
Expand Down
Loading

0 comments on commit 0c085d0

Please sign in to comment.