-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from square/watt/caffeinated-layout/1
Introduce mode control and debugging types
- Loading branch information
Showing
13 changed files
with
247 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
enum LayoutModeKey: EnvironmentKey { | ||
static let defaultValue: LayoutMode = .default | ||
} | ||
|
||
extension Environment { | ||
/// This mode will be inherited by descendant BlueprintViews that do not have an explicit | ||
/// mode set. | ||
var layoutMode: LayoutMode { | ||
get { self[LayoutModeKey.self] } | ||
set { self[LayoutModeKey.self] = newValue } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
|
||
/// A wrapper to make metatypes easier to work with, providing Equatable, Hashable, and | ||
/// CustomStringConvertible. | ||
struct Metatype: Hashable, CustomStringConvertible { | ||
var type: Any.Type | ||
|
||
init(_ type: Any.Type) { | ||
self.type = type | ||
} | ||
|
||
var description: String { | ||
"\(type)" | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(ObjectIdentifier(type)) | ||
} | ||
|
||
static func == (lhs: Metatype, rhs: Metatype) -> Bool { | ||
lhs.type == rhs.type | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
|
||
/// Stores info about the currently running render pass, if there is one. | ||
/// | ||
/// The render context is available statically, which allows "out of band" operations like | ||
/// calls to ``ElementContent/measure(in:environment:)`` to get some context without having it | ||
/// passed in explicitly. This depends entirely on the render pass running exclusively on the main | ||
/// thread. | ||
struct RenderContext { | ||
/// The current render context, if there is one. | ||
private(set) static var current: Self? | ||
|
||
var layoutMode: LayoutMode | ||
|
||
/// Perform the given block with this as the current render context, restoring the previous | ||
/// context before returning. | ||
func perform<Result>(block: () throws -> Result) rethrows -> Result { | ||
let previous = Self.current | ||
defer { Self.current = previous } | ||
|
||
Self.current = self | ||
|
||
return try block() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
/// Controls the layout system that Blueprint uses to lay out elements. | ||
/// | ||
/// Blueprint supports multiple layout systems. Each is expected to produce the same result, but | ||
/// some may have different performance profiles or special requirements. | ||
/// | ||
/// You can change the layout system used by setting the ``BlueprintView/layoutMode`` property, but | ||
/// generally you should use the ``default`` option. | ||
/// | ||
public enum LayoutMode: Equatable { | ||
public static let `default`: Self = .legacy | ||
|
||
/// The "standard" layout system. | ||
case legacy | ||
|
||
/// A newer layout system with some optimizations made possible by ensuring elements adhere | ||
/// certain contract for behavior. | ||
case caffeinated | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.