diff --git a/Neutrino/RenderNeutrino.xcodeproj/project.pbxproj b/Neutrino/RenderNeutrino.xcodeproj/project.pbxproj index dbf1e51f..eb7a4faf 100644 --- a/Neutrino/RenderNeutrino.xcodeproj/project.pbxproj +++ b/Neutrino/RenderNeutrino.xcodeproj/project.pbxproj @@ -37,7 +37,6 @@ 16AA95F21FA3310600EAC136 /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 16AA95DB1FA3310100EAC136 /* Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16AA95F71FA3319B00EAC136 /* IGListCollectionViewLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 16AA95F61FA3319900EAC136 /* IGListCollectionViewLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16AA95F81FA3319E00EAC136 /* IGListCollectionViewLayout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 16AA95F51FA3319900EAC136 /* IGListCollectionViewLayout.mm */; }; - 16AF33931FACAD2500379FA9 /* IGListDiff.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16AF33921FACAD2500379FA9 /* IGListDiff.swift */; }; 16BB65921FABB98800373BB6 /* YGRenderAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 167B537B1FABB7B600AF6798 /* YGRenderAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16CEC0161F9A125C003D3D21 /* Props.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16CEC0151F9A125C003D3D21 /* Props.swift */; }; 16D9F3321FE6CD7F00ADAB3D /* Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D9F3311FE6CD7F00ADAB3D /* Style.swift */; }; @@ -47,9 +46,8 @@ 16F36BE71F8E197A00A04BE6 /* RenderNeutrino.h in Headers */ = {isa = PBXBuildFile; fileRef = 16F36BE51F8E197A00A04BE6 /* RenderNeutrino.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16F36BEE1F8E198B00A04BE6 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F36BED1F8E198B00A04BE6 /* Node.swift */; }; 16F36BF01F8E1A4700A04BE6 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F36BEF1F8E1A4700A04BE6 /* State.swift */; }; - 16F36BF21F8E2B2800A04BE6 /* YGCommonAdditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F36BF11F8E2B2800A04BE6 /* YGCommonAdditions.swift */; }; + 16F36BF21F8E2B2800A04BE6 /* YGExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F36BF11F8E2B2800A04BE6 /* YGExtensions.swift */; }; 16F36C191F8E4BA600A04BE6 /* KeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F36C181F8E4BA600A04BE6 /* KeyPath.swift */; }; - 16F5DD9B1FC1C108005E1497 /* YGPercentLayoutExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F5DD9A1FC1C108005E1497 /* YGPercentLayoutExtension.swift */; }; 16F7B55B1F9A322C00583082 /* RenderInspectorHook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16F7B55A1F9A322C00583082 /* RenderInspectorHook.swift */; }; 16FD2DAA1FB100A1005C2F9F /* Geometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16FD2DA91FB100A1005C2F9F /* Geometry.swift */; }; /* End PBXBuildFile section */ @@ -96,7 +94,6 @@ 16AA95E41FA3310100EAC136 /* YGPercentLayout.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YGPercentLayout.m; sourceTree = ""; }; 16AA95F51FA3319900EAC136 /* IGListCollectionViewLayout.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = IGListCollectionViewLayout.mm; sourceTree = ""; }; 16AA95F61FA3319900EAC136 /* IGListCollectionViewLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IGListCollectionViewLayout.h; sourceTree = ""; }; - 16AF33921FACAD2500379FA9 /* IGListDiff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IGListDiff.swift; sourceTree = ""; }; 16CEC0151F9A125C003D3D21 /* Props.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Props.swift; sourceTree = ""; }; 16D9F3311FE6CD7F00ADAB3D /* Style.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Style.swift; sourceTree = ""; }; 16DDA95C1F9799D200CDBCF5 /* Component.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Component.swift; sourceTree = ""; }; @@ -107,9 +104,8 @@ 16F36BE61F8E197A00A04BE6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 16F36BED1F8E198B00A04BE6 /* Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = ""; }; 16F36BEF1F8E1A4700A04BE6 /* State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = State.swift; sourceTree = ""; }; - 16F36BF11F8E2B2800A04BE6 /* YGCommonAdditions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YGCommonAdditions.swift; sourceTree = ""; }; + 16F36BF11F8E2B2800A04BE6 /* YGExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YGExtensions.swift; sourceTree = ""; }; 16F36C181F8E4BA600A04BE6 /* KeyPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPath.swift; sourceTree = ""; }; - 16F5DD9A1FC1C108005E1497 /* YGPercentLayoutExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YGPercentLayoutExtension.swift; sourceTree = ""; }; 16F7B55A1F9A322C00583082 /* RenderInspectorHook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenderInspectorHook.swift; sourceTree = ""; }; 16FD2DA91FB100A1005C2F9F /* Geometry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Geometry.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -160,13 +156,11 @@ 16AA95E41FA3310100EAC136 /* YGPercentLayout.m */, 16AA95DB1FA3310100EAC136 /* Yoga.h */, 16AA95DD1FA3310100EAC136 /* Yoga.c */, - 16F36BF11F8E2B2800A04BE6 /* YGCommonAdditions.swift */, + 16F36BF11F8E2B2800A04BE6 /* YGExtensions.swift */, 167B537B1FABB7B600AF6798 /* YGRenderAdditions.h */, 167B53791FABB7A400AF6798 /* YGRenderAdditions.m */, - 16F5DD9A1FC1C108005E1497 /* YGPercentLayoutExtension.swift */, 16AA95F61FA3319900EAC136 /* IGListCollectionViewLayout.h */, 16AA95F51FA3319900EAC136 /* IGListCollectionViewLayout.mm */, - 16AF33921FACAD2500379FA9 /* IGListDiff.swift */, ); path = yoga; sourceTree = ""; @@ -200,12 +194,12 @@ path = components; sourceTree = ""; }; - 1665D6651FE959E800955782 /* expression */ = { + 1665D6651FE959E800955782 /* expr */ = { isa = PBXGroup; children = ( 16108B9B1FDC82B000CD9E9A /* Expression.swift */, ); - path = expression; + path = expr; sourceTree = ""; }; 16F36BD81F8E197A00A04BE6 = { @@ -250,7 +244,7 @@ 16F36BF31F8E2BEE00A04BE6 /* deps */ = { isa = PBXGroup; children = ( - 1665D6651FE959E800955782 /* expression */, + 1665D6651FE959E800955782 /* expr */, 160627AF1FE9322B007779DD /* yoga */, 160627A71FE91BC9007779DD /* yaml */, 16F7B55A1F9A322C00583082 /* RenderInspectorHook.swift */, @@ -402,9 +396,8 @@ 160627A91FE91BE3007779DD /* YamlBridge.swift in Sources */, 16D9F3321FE6CD7F00ADAB3D /* Style.swift in Sources */, 167070241FB8C232008DFC5B /* ViewController.swift in Sources */, - 16F36BF21F8E2B2800A04BE6 /* YGCommonAdditions.swift in Sources */, + 16F36BF21F8E2B2800A04BE6 /* YGExtensions.swift in Sources */, 16AA95ED1FA3310600EAC136 /* YGNodeList.c in Sources */, - 16F5DD9B1FC1C108005E1497 /* YGPercentLayoutExtension.swift in Sources */, 16108B9C1FDC82B000CD9E9A /* Expression.swift in Sources */, 16F36BEE1F8E198B00A04BE6 /* Node.swift in Sources */, 16F36BF01F8E1A4700A04BE6 /* State.swift in Sources */, @@ -413,7 +406,6 @@ 16AA95E71FA3310600EAC136 /* YGEnums.c in Sources */, 165300BD1FD6D44C00A7BAB0 /* Debug.swift in Sources */, 16AA95F81FA3319E00EAC136 /* IGListCollectionViewLayout.mm in Sources */, - 16AF33931FACAD2500379FA9 /* IGListDiff.swift in Sources */, 16CEC0161F9A125C003D3D21 /* Props.swift in Sources */, 16108B9E1FDDD1A700CD9E9A /* StylesheetManager.swift in Sources */, 16AA95F11FA3310600EAC136 /* Yoga.c in Sources */, diff --git a/Neutrino/RenderNeutrino.xcodeproj/xcshareddata/xcschemes/RenderNeutrino.xcscheme b/Neutrino/RenderNeutrino.xcodeproj/xcshareddata/xcschemes/RenderNeutrino.xcscheme index 05f04db2..ee6d735f 100644 --- a/Neutrino/RenderNeutrino.xcodeproj/xcshareddata/xcschemes/RenderNeutrino.xcscheme +++ b/Neutrino/RenderNeutrino.xcodeproj/xcshareddata/xcschemes/RenderNeutrino.xcscheme @@ -27,8 +27,7 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" language = "" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/Neutrino/deps/expression/Expression.swift b/Neutrino/deps/expr/Expression.swift similarity index 100% rename from Neutrino/deps/expression/Expression.swift rename to Neutrino/deps/expr/Expression.swift diff --git a/Neutrino/deps/yoga/IGListDiff.swift b/Neutrino/deps/yoga/IGListDiff.swift deleted file mode 100644 index a4925f79..00000000 --- a/Neutrino/deps/yoga/IGListDiff.swift +++ /dev/null @@ -1,286 +0,0 @@ -// forked from: -// https://github.com/muukii/ListDiff/blob/master/Sources/ListDiff.swift -// https://github.com/Instagram/IGListKit/blob/master/Source/Common/IGListDiff.mm -// https://github.com/muukii/DataSources/blob/master/Sources/Diff/Diff.swift - -public typealias EqualityChecker = (T, T) -> Bool - -/// An object that can be diffed. -public protocol Diffable { - /// The identifier used from the diffing algorithm. - var diffIdentifier: String { get } -} - -public protocol Diffing { - /// Return the diff result from 'oldArray' to 'newArray' - static func diffing(oldArray: [T], - newArray: [T], - isEqual: EqualityChecker) -> DiffResultType -} - -public protocol DiffResultType { - var inserts: IndexSet { get set } - var updates: IndexSet { get set } - var deletes: IndexSet { get set } - var moves: [MoveIndex] { get set } -} - -public struct MoveIndex : Equatable { - public let from: Int - public let to: Int - - public init(from: Int, to: Int) { - self.from = from - self.to = to - } - - public static func == (lhs: MoveIndex, rhs: MoveIndex) -> Bool { - return lhs.from == rhs.from && lhs.to == rhs.to - } -} - -public struct DiffResult : DiffResultType { - public var inserts = IndexSet() - public var updates = IndexSet() - public var deletes = IndexSet() - public var moves = Array() - public var oldMap = Dictionary() - public var newMap = Dictionary() - - public func validate(_ oldArray: [T], _ newArray: [T]) -> Bool { - return (oldArray.count + self.inserts.count - self.deletes.count) == newArray.count - } - public func oldIndexFor(identifier: H) -> Int? { - return self.oldMap[identifier] - } - public func newIndexFor(identifier: H) -> Int? { - return self.newMap[identifier] - } -} - -extension DiffResultType { - public var hasChanges: Bool { - guard inserts.isEmpty else { return true } - guard deletes.isEmpty else { return true } - guard updates.isEmpty else { return true } - guard moves.isEmpty else { return true } - return false - } - - public var changeCount: Int { - return inserts.count + deletes.count + updates.count + moves.count - } -} - -struct Stack { - var items = [Element]() - var isEmpty: Bool { - return self.items.isEmpty - } - mutating func push(_ item: Element) { - items.append(item) - } - mutating func pop() -> Element { - return items.removeLast() - } -} - -/// https://github.com/Instagram/IGListKit/blob/master/Source/IGListDiff.mm -public enum Diff: Diffing { - /// Used to track data stats while diffing. - /// We expect to keep a reference of entry, thus its declaration as (final) class. - private final class Entry { - /// The number of times the data occurs in the old array - var oldCounter: Int = 0 - /// The number of times the data occurs in the new array - var newCounter: Int = 0 - /// The indexes of the data in the old array - var oldIndexes: Stack = Stack() - /// Flag marking if the data has been updated between arrays by equality check - var updated: Bool = false - /// Returns `true` if the data occur on both sides, `false` otherwise - var occurOnBothSides: Bool { - return self.newCounter > 0 && self.oldCounter > 0 - } - func push(new index: Int?) { - self.newCounter += 1 - self.oldIndexes.push(index) - } - func push(old index: Int?) { - self.oldCounter += 1; - self.oldIndexes.push(index) - } - } - - /// Track both the entry and the algorithm index. Default the index to `nil` - private struct Record { - let entry: Entry - var index: Int? - init(_ entry: Entry) { - self.entry = entry - self.index = nil - } - } - - private struct OptimizedIdentity : Hashable { - let hashValue: Int - let identity: UnsafePointer - - init(_ identity: UnsafePointer) { - self.identity = identity - self.hashValue = identity.pointee.hashValue - } - - static func == (lhs: OptimizedIdentity, rhs: OptimizedIdentity) -> Bool { - if lhs.hashValue != rhs.hashValue { return false } - if lhs.identity.distance(to: rhs.identity) == 0 { return true } - return lhs.identity.pointee == rhs.identity.pointee - } - } - - /// Diffing - public static func diffing(oldArray: [T], - newArray: [T], - isEqual: EqualityChecker) -> DiffResultType { - // symbol table uses the old/new array `diffIdentifier` as the key and `Entry` as the value - var table = Dictionary, Entry> - .init(minimumCapacity: oldArray.count) - let __oldArray = ContiguousArray(oldArray) - let __newArray = ContiguousArray(newArray) - - // pass 1 - // create an entry for every item in the new array - // increment its new count for each occurence - // record `nil` for each occurence of the item in the new array - var newRecords = __newArray.map { (newRecord) -> Record in - var identifier = newRecord.diffIdentifier - let key = OptimizedIdentity(&identifier) - if let entry = table[key] { - // add `nil` for each occurence of the item in the new array - entry.push(new: nil) - return Record(entry) - } else { - let entry = Entry() - // add `nil` for each occurence of the item in the new array - entry.push(new: nil) - table[key] = entry - return Record(entry) - } - } - - // pass 2 - // update or create an entry for every item in the old array - // increment its old count for each occurence - // record the old index for each occurence of the item in the old array - // MUST be done in descending order to respect the oldIndexes stack construction - var oldRecords = __oldArray.enumerated().reversed().map { (i, oldRecord) -> Record in - var identifier = oldRecord.diffIdentifier - let key = OptimizedIdentity(&identifier) - if let entry = table[key] { - // push the old indices where the item occured onto the index stack - entry.push(old: i) - return Record(entry) - } else { - let entry = Entry() - // push the old indices where the item occured onto the index stack - entry.push(old: i) - table[key] = entry - return Record(entry) - } - } - - // pass 3 - // handle data that occurs in both arrays - newRecords.enumerated().filter { $1.entry.occurOnBothSides }.forEach { (i, newRecord) in - let entry = newRecord.entry - // grab and pop the top old index. if the item was inserted this will be nil - assert(!entry.oldIndexes.isEmpty, "Old indexes is empty while iterating new item \(i).") - guard let oldIndex = entry.oldIndexes.pop() else { - return - } - if oldIndex < __oldArray.count { - let n = __newArray[i] - let o = __oldArray[oldIndex] - if isEqual(n, o) == false { - entry.updated = true - } - } - - // if an item occurs in the new and old array, it is unique - // assign the index of new and old records to the opposite index (reverse lookup) - newRecords[i].index = oldIndex - oldRecords[oldIndex].index = i - } - - // storage for final indexes - var result = DiffResult() - - // track offsets from deleted items to calculate where items have moved - // iterate old array records checking for deletes - // increment offset for each delete - var runningOffset = 0 - let deleteOffsets = oldRecords.enumerated().map { (i, oldRecord) -> Int in - let deleteOffset = runningOffset - // if the record index in the new array doesn't exist, its a delete - if oldRecord.index == nil { - result.deletes.insert(i) - runningOffset += 1 - } - result.oldMap[__oldArray[i].diffIdentifier] = i - return deleteOffset - } - - //reset and track offsets from inserted items to calculate where items have moved - runningOffset = 0 - /* let insertOffsets */_ = newRecords.enumerated().map { (i, newRecord) -> Int in - let insertOffset = runningOffset - if let oldIndex = newRecord.index { - // note that an entry can be updated /and/ moved - if newRecord.entry.updated { - result.updates.insert(oldIndex) - } - - // calculate the offset and determine if there was a move - // if the indexes match, ignore the index - let deleteOffset = deleteOffsets[oldIndex] - if (oldIndex - deleteOffset + insertOffset) != i { - result.moves.append(MoveIndex(from: oldIndex, to: i)) - } - } else { // add to inserts if the opposing index is nil - result.inserts.insert(i) - runningOffset += 1 - } - result.newMap[__newArray[i].diffIdentifier] = i - return insertOffset - } - - assert(result.validate(oldArray, newArray)) - return result - } -} - -// MARK: - Extensions - -extension Int: Diffable { - public var diffIdentifier: String { return "\(self)" } -} - -extension NSNumber: Diffable { - public var diffIdentifier: String { return "\(self)" } -} - -extension String: Diffable { - public var diffIdentifier: String { return self } -} - -extension NSString: Diffable { - public var diffIdentifier: String { return "\(self)" } -} - -extension FloatingPoint { - public var diffIdentifier: String { return "\(self)" } -} - -extension Float : Diffable { } - -extension Double : Diffable { } diff --git a/Neutrino/deps/yoga/YGCommonAdditions.swift b/Neutrino/deps/yoga/YGExtensions.swift similarity index 95% rename from Neutrino/deps/yoga/YGCommonAdditions.swift rename to Neutrino/deps/yoga/YGExtensions.swift index 56492110..290b20c9 100644 --- a/Neutrino/deps/yoga/YGCommonAdditions.swift +++ b/Neutrino/deps/yoga/YGExtensions.swift @@ -1,6 +1,46 @@ import UIKit import ImageIO +// MARK: - YGPercentLayout Operator + +postfix operator % + +extension Int { + public static postfix func %(value: Int) -> YGValue { + return YGValue(value: Float(value), unit: .percent) + } +} + +extension Float { + public static postfix func %(value: Float) -> YGValue { + return YGValue(value: value, unit: .percent) + } +} + +extension CGFloat { + public static postfix func %(value: CGFloat) -> YGValue { + return YGValue(value: Float(value), unit: .percent) + } +} + +extension YGValue : ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral { + public init(integerLiteral value: Int) { + self = YGValue(value: Float(value), unit: .point) + } + + public init(floatLiteral value: Float) { + self = YGValue(value: value, unit: .point) + } + + public init(_ value: Float) { + self = YGValue(value: value, unit: .point) + } + + public init(_ value: CGFloat) { + self = YGValue(value: Float(value), unit: .point) + } +} + // MARK: - UIStylesheetRepresentableEnum Yoga Compliancy extension YGAlign: UIStylesheetRepresentableEnum { @@ -72,7 +112,7 @@ extension UIScrollView: UIPostRendering { } } -// MARK: - Gesture recognizers +// MARK: - UIGestureRecognizer class WeakGestureRecognizer: NSObject { weak var object: UIGestureRecognizer? @@ -317,7 +357,6 @@ extension UIBezierPath { } public extension UIBezierPath { - @objc public convenience init(roundedRegularPolygon rect: CGRect, numberOfSides: Int, cornerRadius: CGFloat) { @@ -335,7 +374,6 @@ public extension UIBezierPath { } public extension UIBezierPath { - @objc public func applyRotation(angle: CGFloat) { let bounds = self.cgPath.boundingBox let center = CGPoint(x: bounds.midX, y: bounds.midY) @@ -386,8 +424,6 @@ public func radiansToDegrees(_ value: CGFloat) -> CGFloat { private func commonInit() { backgroundColor = .clear - frame.size.width = HeightPreset.medium.cgFloatValue - frame.size.height = HeightPreset.medium.cgFloatValue cornerRadius = CornerRadiusPreset.cornerRadius1.cgFloatValue } @@ -516,40 +552,6 @@ public func DepthPresetToValue(preset: DepthPreset) -> Depth { } } -@objc public enum MarginPreset: Int { - case none = 0 - case tiny = 2 - case xsmall = 4 - case small = 8 - case `default` = 16 - case normal = 24 - case medium = 32 - case large = 40 - case xlarge = 48 - case xxlarge = 64 - - public var cgFloatValue: CGFloat { - return CGFloat(rawValue) - } -} - -@objc public enum HeightPreset: Int { - case none = 0 - case tiny = 20 - case xsmall = 28 - case small = 36 - case `default` = 44 - case normal = 49 - case medium = 52 - case large = 60 - case xlarge = 68 - case xxlarge = 104 - - public var cgFloatValue: CGFloat { - return CGFloat(rawValue) - } -} - @objc public enum CornerRadiusPreset: Int { case none case cornerRadius1 @@ -621,34 +623,24 @@ public func CornerRadiusPresetToValue(preset: CornerRadiusPreset) -> CGFloat { fileprivate class ContainerLayer { /// A reference to the CALayer. fileprivate weak var layer: CALayer? - /// A property that sets the height of the layer's frame. - fileprivate var heightPreset = HeightPreset.default { - didSet { - layer?.height = CGFloat(heightPreset.rawValue) - } - } - /// A property that sets the cornerRadius of the backing layer. fileprivate var cornerRadiusPreset = CornerRadiusPreset.none { didSet { layer?.cornerRadius = CornerRadiusPresetToValue(preset: cornerRadiusPreset) } } - /// A preset property to set the borderWidth. fileprivate var borderWidthPreset = BorderWidthPreset.none { didSet { layer?.borderWidth = borderWidthPreset.cgFloatValue } } - /// A preset property to set the shape. fileprivate var shapePreset = ShapePreset.none { didSet { layer?.layoutShape() } } - /// A preset value for Depth. fileprivate var depthPreset: DepthPreset { get { @@ -739,13 +731,6 @@ extension CALayer { layoutShadowPath() } } - /// HeightPreset value. - open var heightPreset: HeightPreset { - get { return containerLayer.heightPreset } - set(value) { - containerLayer.heightPreset = value - } - } /// A property that manages the overall shape for the object. If either the /// width or height property is set, the other will be automatically adjusted /// to maintain the shape of the object. @@ -823,11 +808,6 @@ extension CALayer { } extension UIView { - /// HeightPreset value. - @objc open var heightPreset: HeightPreset { - get { return layer.heightPreset } - set(value) { layer.heightPreset = value } - } /// A property that manages the overall shape for the object. If either the /// width or height property is set, the other will be automatically adjusted /// to maintain the shape of the object. diff --git a/Neutrino/deps/yoga/YGPercentLayoutExtension.swift b/Neutrino/deps/yoga/YGPercentLayoutExtension.swift deleted file mode 100644 index 9833db20..00000000 --- a/Neutrino/deps/yoga/YGPercentLayoutExtension.swift +++ /dev/null @@ -1,40 +0,0 @@ -import Foundation -import UIKit - -postfix operator % - -extension Int { - public static postfix func %(value: Int) -> YGValue { - return YGValue(value: Float(value), unit: .percent) - } -} - -extension Float { - public static postfix func %(value: Float) -> YGValue { - return YGValue(value: value, unit: .percent) - } -} - -extension CGFloat { - public static postfix func %(value: CGFloat) -> YGValue { - return YGValue(value: Float(value), unit: .percent) - } -} - -extension YGValue : ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral { - public init(integerLiteral value: Int) { - self = YGValue(value: Float(value), unit: .point) - } - - public init(floatLiteral value: Float) { - self = YGValue(value: value, unit: .point) - } - - public init(_ value: Float) { - self = YGValue(value: value, unit: .point) - } - - public init(_ value: CGFloat) { - self = YGValue(value: Float(value), unit: .point) - } -} diff --git a/Neutrino/deps/yoga/YGRenderAdditions.h b/Neutrino/deps/yoga/YGRenderAdditions.h index c562c295..1f05ed18 100644 --- a/Neutrino/deps/yoga/YGRenderAdditions.h +++ b/Neutrino/deps/yoga/YGRenderAdditions.h @@ -49,7 +49,4 @@ NS_ASSUME_NONNULL_BEGIN + (UIImage*)yg_imageWithColor:(UIColor*)color size:(CGSize)size; @end - NS_ASSUME_NONNULL_END - - diff --git a/Neutrino/deps/yoga/YGRenderAdditions.m b/Neutrino/deps/yoga/YGRenderAdditions.m index 844f1ad5..72f59d4c 100644 --- a/Neutrino/deps/yoga/YGRenderAdditions.m +++ b/Neutrino/deps/yoga/YGRenderAdditions.m @@ -87,83 +87,67 @@ - (void)setShadowColor:(UIColor*)shadowColor @implementation UIButton (YGAdditions) -- (NSString*)text -{ +- (NSString*)text { return [self titleForState:UIControlStateNormal]; } -- (void)setText:(NSString*)text -{ +- (void)setText:(NSString*)text { [self setTitle:text forState:UIControlStateNormal]; } -- (NSString*)highlightedText -{ +- (NSString*)highlightedText { return [self titleForState:UIControlStateHighlighted]; } -- (void)setHighlightedText:(NSString*)highlightedText -{ +- (void)setHighlightedText:(NSString*)highlightedText { [self setTitle:highlightedText forState:UIControlStateHighlighted]; } -- (NSString*)selectedText -{ +- (NSString*)selectedText { return [self titleForState:UIControlStateSelected]; } -- (void)setSelectedText:(NSString*)selectedText -{ +- (void)setSelectedText:(NSString*)selectedText { [self setTitle:selectedText forState:UIControlStateSelected]; } -- (NSString*)disabledText -{ +- (NSString*)disabledText { return [self titleForState:UIControlStateDisabled]; } -- (void)setDisabledText:(NSString*)disabledText -{ +- (void)setDisabledText:(NSString*)disabledText { [self setTitle:disabledText forState:UIControlStateDisabled]; } -- (UIColor*)textColor -{ +- (UIColor*)textColor { return [self titleColorForState:UIControlStateNormal]; } -- (void)setTextColor:(UIColor*)textColor -{ +- (void)setTextColor:(UIColor*)textColor { [self setTitleColor:textColor forState:UIControlStateNormal]; } -- (UIColor*)highlightedTextColor -{ +- (UIColor*)highlightedTextColor { return [self titleColorForState:UIControlStateHighlighted]; } -- (void)setHighlightedTextColor:(UIColor*)highlightedTextColor -{ +- (void)setHighlightedTextColor:(UIColor*)highlightedTextColor { [self setTitleColor:highlightedTextColor forState:UIControlStateHighlighted]; } -- (UIColor*)selectedTextColor -{ +- (UIColor*)selectedTextColor { return [self titleColorForState:UIControlStateSelected]; } -- (void)setSelectedTextColor:(UIColor*)selectedTextColor -{ +- (void)setSelectedTextColor:(UIColor*)selectedTextColor { [self setTitleColor:selectedTextColor forState:UIControlStateSelected]; } -- (UIColor*)disabledTextColor -{ +- (UIColor*)disabledTextColor { return [self titleColorForState:UIControlStateDisabled]; } -- (void)setDisabledTextColor:(UIColor*)disabledTextColor -{ +- (void)setDisabledTextColor:(UIColor*)disabledTextColor { [self setTitleColor:disabledTextColor forState:UIControlStateDisabled]; } @@ -171,89 +155,72 @@ - (UIColor *)backgroundColorImage { return nil; } -- (void)setBackgroundColorImage:(UIColor*)backgroundColor -{ +- (void)setBackgroundColorImage:(UIColor*)backgroundColor { UIImage *image = [UIImage yg_imageWithColor:backgroundColor]; self.backgroundImage = image; } -- (UIImage*)backgroundImage -{ +- (UIImage*)backgroundImage { return [self backgroundImageForState:UIControlStateNormal]; } -- (void)setBackgroundImage:(UIImage*)backgroundImage -{ +- (void)setBackgroundImage:(UIImage*)backgroundImage { [self setBackgroundImage:backgroundImage forState:UIControlStateNormal]; } -- (UIImage*)highlightedBackgroundImage -{ +- (UIImage*)highlightedBackgroundImage { return [self backgroundImageForState:UIControlStateHighlighted]; } -- (void)setHighlightedBackgroundImage:(UIImage*)highlightedBackgroundImage -{ +- (void)setHighlightedBackgroundImage:(UIImage*)highlightedBackgroundImage { [self setBackgroundImage:highlightedBackgroundImage forState:UIControlStateHighlighted]; } -- (UIImage*)selectedBackgroundImage -{ +- (UIImage*)selectedBackgroundImage { return [self backgroundImageForState:UIControlStateSelected]; } -- (void)setSelectedBackgroundImage:(UIImage*)selectedBackgroundImage -{ +- (void)setSelectedBackgroundImage:(UIImage*)selectedBackgroundImage { [self setBackgroundImage:selectedBackgroundImage forState:UIControlStateSelected]; } -- (UIImage*)disabledBackgroundImage -{ +- (UIImage*)disabledBackgroundImage { return [self backgroundImageForState:UIControlStateDisabled]; } -- (void)setDisabledBackgroundImage:(UIImage*)disabledBackgroundImage -{ +- (void)setDisabledBackgroundImage:(UIImage*)disabledBackgroundImage { [self setBackgroundImage:disabledBackgroundImage forState:UIControlStateDisabled]; } -- (UIImage*)image -{ +- (UIImage*)image { return [self imageForState:UIControlStateNormal]; } -- (void)setImage:(UIImage*)image -{ +- (void)setImage:(UIImage*)image { [self setImage:image forState:UIControlStateNormal]; } -- (UIImage*)highlightedImage -{ +- (UIImage*)highlightedImage { return [self imageForState:UIControlStateHighlighted]; } -- (void)setHighlightedImage:(UIImage*)highlightedImage -{ +- (void)setHighlightedImage:(UIImage*)highlightedImage { [self setImage:highlightedImage forState:UIControlStateHighlighted]; } -- (UIImage*)selectedImage -{ +- (UIImage*)selectedImage { return [self imageForState:UIControlStateSelected]; } -- (void)setSelectedImage:(UIImage*)selectedImage -{ +- (void)setSelectedImage:(UIImage*)selectedImage { [self setImage:selectedImage forState:UIControlStateSelected]; } -- (UIImage*)disabledImage -{ +- (UIImage*)disabledImage { return [self imageForState:UIControlStateDisabled]; } -- (void)setDisabledImage:(UIImage*)disabledImage -{ +- (void)setDisabledImage:(UIImage*)disabledImage { [self setImage:disabledImage forState:UIControlStateDisabled]; } @@ -263,45 +230,19 @@ - (void)setDisabledImage:(UIImage*)disabledImage @implementation UIImage (YGAdditions) -+ (UIImage*)yg_imageWithColor:(UIColor*)color -{ ++ (UIImage*)yg_imageWithColor:(UIColor*)color { return [self yg_imageWithColor:color size:(CGSize){1,1}]; } -+ (UIImage*)yg_imageWithColor:(UIColor*)color size:(CGSize)size -{ ++ (UIImage*)yg_imageWithColor:(UIColor*)color size:(CGSize)size { CGRect rect = (CGRect){CGPointZero, size}; UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale); CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); - return image; } @end - -@implementation NSObject (YGAdditions) - -- (NSString*)yg_className -{ - NSString *className = NSStringFromClass(self.class); - - if ([className hasPrefix:@"Optional("]) { - className = [className stringByReplacingOccurrencesOfString:@"Optional(\"" withString:@""]; - className = [className stringByReplacingOccurrencesOfString:@"\")" withString:@""]; - } - - return className; -} - -- (Class)yg_class -{ - return self.class; -} - -@end diff --git a/Neutrino/stylesheet/StylesheetManager.swift b/Neutrino/stylesheet/StylesheetManager.swift index 8acfbd10..eb85d09c 100644 --- a/Neutrino/stylesheet/StylesheetManager.swift +++ b/Neutrino/stylesheet/StylesheetManager.swift @@ -620,7 +620,7 @@ extension NSTextAlignment: UIStylesheetRepresentableEnum { "\(namespace).left": Double(NSTextAlignment.left.rawValue), "\(namespace).center": Double(NSTextAlignment.center.rawValue), "\(namespace).right": Double(NSTextAlignment.right.rawValue), - "\(namespace)t.justified": Double(NSTextAlignment.justified.rawValue), + "\(namespace).justified": Double(NSTextAlignment.justified.rawValue), "\(namespace).natural": Double(NSTextAlignment.natural.rawValue)] } }