Skip to content

Commit

Permalink
Merge branch 'fancy-images' into 0.3.0
Browse files Browse the repository at this point in the history
* fancy-images:
  Cleaned EverLayoutBridge class
  Removed deprecated build function
  Added a synchronous image download if the image argument is a valid URL
  • Loading branch information
dalewebster48 committed Feb 24, 2017
2 parents 372cd5b + bf166e6 commit 4ed7479
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
12 changes: 5 additions & 7 deletions EverLayout/EverLayoutBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import SocketIO
public class EverLayoutBridge: NSObject
{
static var socket : SocketIOClient?

private static let DEFAULT_IP : String = "http://localhost"
private static let DEFAULT_PORT : String = "3000"

Expand All @@ -51,7 +52,7 @@ public class EverLayoutBridge: NSObject
{
let layoutName : NSString = layoutName as NSString

if let rawData = layoutData.getRawData()
if let rawData = layoutData.rawData as? Data
{
self.postLayoutUpdate(layoutName: layoutName.deletingPathExtension, layoutData: rawData)
}
Expand All @@ -65,8 +66,7 @@ public class EverLayoutBridge: NSObject
///
/// - Parameter data: raw data
/// - Returns: JSON Data
private static func parseData (_ data : [Any]) -> JSON
{
private static func parseData (_ data : [Any]) -> JSON {
return JSON(data.first as Any)
}

Expand All @@ -75,8 +75,7 @@ public class EverLayoutBridge: NSObject
/// - Parameters:
/// - layoutName: Name of the layout that has been updated
/// - layoutData: The new layout data
private static func postLayoutUpdate (layoutName : String , layoutData : Data)
{
private static func postLayoutUpdate (layoutName : String , layoutData : Data) {
let notificationName : Notification.Name = Notification.Name("layout-update__\(layoutName)")

NotificationCenter.default.post(name: notificationName, object: layoutData)
Expand All @@ -85,8 +84,7 @@ public class EverLayoutBridge: NSObject
/// Report a message to the bridge
///
/// - Parameter message: message to report
public static func sendReport (message : String)
{
public static func sendReport (message : String) {
self.socket?.emit("report", [
"message":message
])
Expand Down
21 changes: 0 additions & 21 deletions EverLayout/Model/EverLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,6 @@ open class EverLayout: ELRawData
return EverLayout(layoutData: layoutData, layoutIndexParser: self.indexParser)
}

/// Similar to building a full layout, this will begin the process of building a sublayout on the passed view
///
/// - Parameters:
/// - name: Name of sublayout to load
/// - view: The root view to build this layout on
/// - host: An optional object which contains the properties referenced in this layout
/// - data: An optional dictionary of data to inject into this sublayout
// public func buildSubLayout (_ name : String , onView view : UIView , host : NSObject? = nil , data : [String : String]? = nil)
// {
// guard var sublayout = self.sublayouts?[name] else { return }
//
// // Inject data into the sublayout
// if var sublayout = sublayout as? Data , let data = data
// {
// sublayout = self._injectDataIntoLayout(data: data, layoutData: sublayout)!
// }
//
// // Build!
// EverLayoutBuilder.buildLayout(sublayout, onView: view, host: host)
// }

/// Set data to be injected when the layout is built
///
/// - Parameter data: Dictionary of key-values for variables in the layout
Expand Down
14 changes: 13 additions & 1 deletion EverLayout/Resolvers/ImageViewPropertyResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ public class ImageViewPropertyResolver: PropertyResolver

static func image (source : String) -> UIImage?
{
return UIImage(named: source)
// Try loading the image from an asset
var image = UIImage(named: source)

if image == nil {
// Attempt to load this image as a url
if let imageUrl = URL(string: source) {
if let imageData = NSData(contentsOf: imageUrl) {
image = UIImage(data: imageData as Data)
}
}
}

return image
}
}

Expand Down

0 comments on commit 4ed7479

Please sign in to comment.