Skip to content
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

Rename Context to EasyContext and View to EasyView for SwiftUI compatibility #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions EasyPeasy/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public typealias Condition = () -> Bool

#if os(iOS)
/**
Typealias of a closure with a `Context` struct as parameter and `Bool`
Typealias of a closure with an `EasyContext` struct as parameter and `Bool`
as returning type.

This type of closure is used to evaluate whether an `Attribute` should
be applied or not.
*/
public typealias ContextualCondition = (Context) -> Bool
public typealias ContextualCondition = (EasyContext) -> Bool
#endif

/**
Expand Down Expand Up @@ -240,8 +240,8 @@ open class Attribute {
// struct and call the closure
#if os(iOS)
let item = self.createItem?.owningView ?? self.createItem
if let contextualCondition = self.condition as? ContextualCondition, let view = item as? View {
return contextualCondition(Context(with: view.traitCollection))
if let contextualCondition = self.condition as? ContextualCondition, let view = item as? EasyView {
return contextualCondition(EasyContext(with: view.traitCollection))
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion EasyPeasy/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import UIKit
Struct that from an `UITraitCollection` object populates some helper
properties easing access to device and size class information
*/
public struct Context {
public struct EasyContext {

/// `true` if the current device is an iPad
public let isPad: Bool
Expand Down
4 changes: 2 additions & 2 deletions EasyPeasy/Item+AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import AppKit

/// Alias of NSView
public typealias View = NSView
public typealias EasyView = NSView

/**
Extension making `NSView` conform the `Item` protocol and
Expand All @@ -23,7 +23,7 @@ extension NSView: Item {

/// Owning `NSView` for the current `Item`. The concept varies
/// depending on the class conforming the protocol
public var owningView: View? {
public var owningView: EasyView? {
// Owning view for `NSView` is the `superview`
return self.superview
}
Expand Down
4 changes: 2 additions & 2 deletions EasyPeasy/Item+UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import UIKit

/// Alias of UIView
public typealias View = UIView
public typealias EasyView = UIView

/**
Extension making `UIView` conform the `Item` protocol and
Expand All @@ -23,7 +23,7 @@ extension UIView: Item {

/// Owning `UIView` for the current `Item`. The concept varies
/// depending on the class conforming the protocol
public var owningView: View? {
public var owningView: EasyView? {
return self.superview
}

Expand Down
2 changes: 1 addition & 1 deletion EasyPeasy/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol Item: NSObjectProtocol {

/// Owning `UIView` for the current `Item`. The concept varies
/// depending on the class conforming the protocol
var owningView: View? { get }
var owningView: EasyView? { get }

}

Expand Down
10 changes: 5 additions & 5 deletions Example/Tests/ContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ContextTests: XCTestCase {
let isVerticalRegular = view.traitCollection.verticalSizeClass == .regular

// when
let context = Context(with: view.traitCollection)
let context = EasyContext(with: view.traitCollection)

// then
XCTAssertTrue(context.isPad == isPad)
Expand All @@ -60,7 +60,7 @@ class ContextTests: XCTestCase {
let isVerticalRegular = traitCollection.verticalSizeClass == .regular

// when
let context = Context(with: traitCollection)
let context = EasyContext(with: traitCollection)

// then
XCTAssertTrue(context.isPad == isPad)
Expand All @@ -86,7 +86,7 @@ class ContextTests: XCTestCase {
let isVerticalRegular = traitCollection.verticalSizeClass == .regular

// when
let context = Context(with: traitCollection)
let context = EasyContext(with: traitCollection)

// then
XCTAssertTrue(context.isPad == isPad)
Expand All @@ -112,7 +112,7 @@ class ContextTests: XCTestCase {
let isVerticalRegular = traitCollection.verticalSizeClass == .regular

// when
let context = Context(with: traitCollection)
let context = EasyContext(with: traitCollection)

// then
XCTAssertTrue(context.isPad == isPad)
Expand All @@ -138,7 +138,7 @@ class ContextTests: XCTestCase {
let isVerticalRegular = traitCollection.verticalSizeClass == .regular

// when
let context = Context(with: traitCollection)
let context = EasyContext(with: traitCollection)

// then
XCTAssertTrue(context.isPad == isPad)
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/ItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ItemTests: XCTestCase {
}
}

fileprivate var owningView: View?
fileprivate var owningView: EasyView?

}
let testClassInstance = TestClass()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ view.easy.layout([

#### ContextualConditions
This iOS only feature is a variant of the `Condition` closures that receive no
parameters and return a boolean value. Instead, a `Context` struct is passed
parameters and return a boolean value. Instead, an `EasyContext` struct is passed
as parameter providing some extra information based on the `UITraitCollection`
of the `UIView` the `Attributes` are going to be applied to.

The properties available on this `Context` struct are:
The properties available on this `EasyContext` struct are:

* `isPad`: true if the current device is iPad.
* `isPhone`: true if the current device is iPhone.
Expand Down