Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Support macOS #11

Merged
merged 6 commits into from
Jul 13, 2016
Merged
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
10 changes: 8 additions & 2 deletions LayoutKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ Pod::Spec.new do |spec|
spec.summary = 'LayoutKit is a fast view layout library for iOS.'
spec.source = { :git => 'https://github.com/linkedin/LayoutKit.git', :tag => spec.version }
spec.source_files = 'LayoutKit/**/*.swift'
spec.platform = :ios, '8.0'
spec.frameworks = 'Foundation', 'UIKit'

spec.ios.deployment_target = '8.0'
spec.ios.frameworks = 'Foundation', 'CoreGraphics', 'UIKit'
spec.ios.exclude_files = 'LayoutKit/AppKitSupport.swift'

spec.osx.deployment_target = '10.9'
spec.osx.frameworks = 'Foundation', 'CoreGraphics', 'AppKit'
spec.osx.exclude_files = 'LayoutKit/UIKitSupport.swift', 'LayoutKit/Layouts/LabelLayout.Swift', 'LayoutKit/Views/**'
end

319 changes: 294 additions & 25 deletions LayoutKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EF21CC57348003820E8"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit"
BlueprintName = "LayoutKit-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -34,8 +34,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EFB1CC57348003820E8"
BuildableName = "LayoutKitTests.xctest"
BlueprintName = "LayoutKitTests"
BuildableName = "LayoutKitTests-iOS.xctest"
BlueprintName = "LayoutKitTests-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</TestableReference>
Expand All @@ -45,7 +45,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EF21CC57348003820E8"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit"
BlueprintName = "LayoutKit-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand All @@ -67,7 +67,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EF21CC57348003820E8"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit"
BlueprintName = "LayoutKit-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand All @@ -85,7 +85,7 @@
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EF21CC57348003820E8"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit"
BlueprintName = "LayoutKit-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B5191421D2922C800769358"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit-macOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B5191651D29241200769358"
BuildableName = "LayoutKitTests-macOS.xctest"
BlueprintName = "LayoutKitTests-macOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B5191421D2922C800769358"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit-macOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B5191421D2922C800769358"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit-macOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0B5191421D2922C800769358"
BuildableName = "LayoutKit.framework"
BlueprintName = "LayoutKit-macOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EFB1CC57348003820E8"
BuildableName = "LayoutKitTests.xctest"
BlueprintName = "LayoutKitTests"
BuildableName = "LayoutKitTests-iOS.xctest"
BlueprintName = "LayoutKitTests-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</TestableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47F2B1CC57492003820E8"
BuildableName = "LayoutKitSampleApp.app"
BlueprintName = "LayoutKitSampleApp"
BuildableName = "LayoutKitSampleApp-iOS.app"
BlueprintName = "LayoutKitSampleApp-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -33,8 +33,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47EFB1CC57348003820E8"
BuildableName = "LayoutKitTests.xctest"
BlueprintName = "LayoutKitTests"
BuildableName = "LayoutKitTests-iOS.xctest"
BlueprintName = "LayoutKitTests-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</TestableReference>
Expand All @@ -43,8 +43,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47F2B1CC57492003820E8"
BuildableName = "LayoutKitSampleApp.app"
BlueprintName = "LayoutKitSampleApp"
BuildableName = "LayoutKitSampleApp-iOS.app"
BlueprintName = "LayoutKitSampleApp-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand All @@ -66,8 +66,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47F2B1CC57492003820E8"
BuildableName = "LayoutKitSampleApp.app"
BlueprintName = "LayoutKitSampleApp"
BuildableName = "LayoutKitSampleApp-iOS.app"
BlueprintName = "LayoutKitSampleApp-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
Expand All @@ -85,8 +85,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BE47F2B1CC57492003820E8"
BuildableName = "LayoutKitSampleApp.app"
BlueprintName = "LayoutKitSampleApp"
BuildableName = "LayoutKitSampleApp-iOS.app"
BlueprintName = "LayoutKitSampleApp-iOS"
ReferencedContainer = "container:LayoutKit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
Expand Down
2 changes: 1 addition & 1 deletion LayoutKit/Alignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import CoreGraphics

/**
Specifies how a layout positions itself inside of the rect that it is given to it by its parent during the positioning pass.
Expand Down
17 changes: 17 additions & 0 deletions LayoutKit/AppKitSupport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 LinkedIn Corp.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import AppKit

public typealias View = NSView

public typealias EdgeInsets = NSEdgeInsets

public typealias UserInterfaceLayoutDirection = NSUserInterfaceLayoutDirection

public typealias Application = NSApplication
6 changes: 3 additions & 3 deletions LayoutKit/Internal/CGSizeExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import CoreGraphics

extension CGSize {
func sizeDecreasedByInsets(insets: UIEdgeInsets) -> CGSize {
func sizeDecreasedByInsets(insets: EdgeInsets) -> CGSize {
return CGSize(width: width - insets.left - insets.right, height: height - insets.top - insets.bottom)
}

func sizeIncreasedByInsets(insets: UIEdgeInsets) -> CGSize {
func sizeIncreasedByInsets(insets: EdgeInsets) -> CGSize {
return CGSize(width: width + insets.left + insets.right, height: height + insets.top + insets.bottom)
}

Expand Down
4 changes: 2 additions & 2 deletions LayoutKit/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import CoreGraphics

/**
A protocol for types that layout view frames.
Expand Down Expand Up @@ -70,7 +70,7 @@ public protocol Layout {

MUST be run on the main thread.
*/
func makeView() -> UIView?
func makeView() -> View?

/**
The flexibility of the layout.
Expand Down
18 changes: 9 additions & 9 deletions LayoutKit/LayoutArrangement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import CoreGraphics

/**
The frame of a layout and the frames of its sublayouts.
Expand Down Expand Up @@ -35,9 +35,9 @@ public struct LayoutArrangement {

- returns: The root view. If a view was provided, the same view will be returned, otherwise, a new one will be created.
*/
public func makeViews(inView view: UIView? = nil, direction: UIUserInterfaceLayoutDirection = .LeftToRight) -> UIView {
public func makeViews(inView view: View? = nil, direction: UserInterfaceLayoutDirection = .LeftToRight) -> View {
let views = makeSubviews()
let rootView: UIView
let rootView: View

if let view = view {
// We have a parent view so replace all of its subviews.
Expand All @@ -54,7 +54,7 @@ public struct LayoutArrangement {
rootView = view
} else {
// We have multiple views so create a root view.
rootView = UIView(frame: frame)
rootView = View(frame: frame)
for subview in views {
// Unapply the offset that was applied in makeSubviews()
subview.frame.offsetInPlace(dx: -frame.origin.x, dy: -frame.origin.y)
Expand All @@ -67,23 +67,23 @@ public struct LayoutArrangement {
}

/// Horizontally flips the view frames if direction does not match the user's language direction.
private func handleLayoutDirection(view: UIView, direction: UIUserInterfaceLayoutDirection) {
if UIApplication.sharedApplication().userInterfaceLayoutDirection != direction {
private func handleLayoutDirection(view: View, direction: UserInterfaceLayoutDirection) {
if Application.sharedApplication().userInterfaceLayoutDirection != direction {
flipSubviewsHorizontally(view)
}
}

/// Flips the right and left edges of the view's subviews.
private func flipSubviewsHorizontally(view: UIView) {
private func flipSubviewsHorizontally(view: View) {
for subview in view.subviews {
subview.frame.origin.x = view.frame.width - subview.frame.maxX
flipSubviewsHorizontally(subview)
}
}

/// Returns the views for the layout and all of its sublayouts.
private func makeSubviews() -> [UIView] {
let subviews = sublayouts.flatMap({ (sublayout: LayoutArrangement) -> [UIView] in
private func makeSubviews() -> [View] {
let subviews = sublayouts.flatMap({ (sublayout: LayoutArrangement) -> [View] in
return sublayout.makeSubviews()
})
if let view = layout.makeView() {
Expand Down
2 changes: 1 addition & 1 deletion LayoutKit/LayoutMeasurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import CoreGraphics

/**
The size of a layout and the sizes of its sublayouts.
Expand Down
12 changes: 6 additions & 6 deletions LayoutKit/Layouts/InsetLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

import UIKit
import CoreGraphics

/**
A layout that insets another layout.
*/
public class InsetLayout: PositioningLayout<UIView>, Layout {
public class InsetLayout: PositioningLayout<View>, Layout {

public let insets: UIEdgeInsets
public let insets: EdgeInsets
public let alignment: Alignment
public let sublayout: Layout

public init(insets: UIEdgeInsets, alignment: Alignment = Alignment.fill, sublayout: Layout, config: (UIView -> Void)? = nil) {
public init(insets: EdgeInsets, alignment: Alignment = Alignment.fill, sublayout: Layout, config: (View -> Void)? = nil) {
self.insets = insets
self.alignment = alignment
self.sublayout = sublayout
super.init(config: config)
}

public convenience init(inset: CGFloat, alignment: Alignment = Alignment.fill, sublayout: Layout, config: (UIView -> Void)? = nil) {
let insets = UIEdgeInsets(top: inset, left: inset, bottom: inset, right: inset)
public convenience init(inset: CGFloat, alignment: Alignment = Alignment.fill, sublayout: Layout, config: (View -> Void)? = nil) {
let insets = EdgeInsets(top: inset, left: inset, bottom: inset, right: inset)
self.init(insets: insets, alignment: alignment, sublayout: sublayout, config: config)
}

Expand Down
Loading