Skip to content

Commit

Permalink
Update default font size, make ConstraintComponent simpler, add dropD…
Browse files Browse the repository at this point in the history
…elegate
  • Loading branch information
lkzhao committed Jan 14, 2022
1 parent 0878a17 commit 1f0690b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ struct ConstraintOverrideComponent: Component {
}
}

public struct ConstraintOverrideViewComponent<R, Content: ViewComponent>: ViewComponent where R == Content.R {
public struct ConstraintOverrideViewComponent<Content: ViewComponent>: ViewComponent {
let child: Content
let transformer: ConstraintTransformer
public func layout(_ constraint: Constraint) -> R {
public func layout(_ constraint: Constraint) -> Content.R {
child.layout(transformer.calculate(constraint))
}
}
15 changes: 15 additions & 0 deletions Sources/UIComponent/Components/View/TappableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ open class TappableView: ComponentView {
}
}
}

private var dropInteraction: UIDropInteraction?
public weak var dropDelegate: UIDropInteractionDelegate? {
didSet {
guard dropDelegate !== oldValue else { return }
if let dropDelegate = dropDelegate {
dropInteraction = UIDropInteraction(delegate: dropDelegate)
addInteraction(dropInteraction!)
} else {
if let dropInteraction = dropInteraction {
removeInteraction(dropInteraction)
}
}
}
}

public var previewProvider: (() -> UIViewController?)? {
didSet {
Expand Down
2 changes: 1 addition & 1 deletion Sources/UIComponent/Components/View/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct Text: ViewComponent {
public let numberOfLines: Int
public let lineBreakMode: NSLineBreakMode
public init(_ text: String,
font: UIFont = UIFont.systemFont(ofSize: 16),
font: UIFont = UIFont.systemFont(ofSize: UIFont.systemFontSize),
numberOfLines: Int = 0,
lineBreakMode: NSLineBreakMode = .byWordWrapping)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ extension Component {
}

extension Component {
public func maxSize(width: CGFloat = .infinity, height: CGFloat = .infinity) -> Component {
constraint { c in
Constraint(minSize: c.minSize, maxSize: CGSize(width: min(width, c.maxSize.width), height: min(height, c.maxSize.height)))
}
}
public func size(width: SizeStrategy = .fit, height: SizeStrategy = .fit) -> Component {
ConstraintOverrideComponent(child: self, transformer: SizeStrategyConstraintTransformer(width: width, height: height))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,33 @@ extension ViewComponent {
}

extension ViewComponent {
public func size(width: SizeStrategy = .fit, height: SizeStrategy = .fit) -> ConstraintOverrideViewComponent<R, Self> {
public func size(width: SizeStrategy = .fit, height: SizeStrategy = .fit) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: SizeStrategyConstraintTransformer(width: width, height: height))
}
public func size(width: CGFloat, height: SizeStrategy = .fit) -> ConstraintOverrideViewComponent<R, Self> {
public func size(width: CGFloat, height: SizeStrategy = .fit) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: SizeStrategyConstraintTransformer(width: .absolute(width), height: height))
}
public func size(width: CGFloat, height: CGFloat) -> ConstraintOverrideViewComponent<R, Self> {
public func size(width: CGFloat, height: CGFloat) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: SizeStrategyConstraintTransformer(width: .absolute(width), height: .absolute(height)))
}
public func size(_ size: CGSize) -> ConstraintOverrideViewComponent<R, Self> {
public func size(_ size: CGSize) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: SizeStrategyConstraintTransformer(width: .absolute(size.width), height: .absolute(size.height)))
}
public func size(width: SizeStrategy = .fit, height: CGFloat) -> ConstraintOverrideViewComponent<R, Self> {
public func size(width: SizeStrategy = .fit, height: CGFloat) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: SizeStrategyConstraintTransformer(width: width, height: .absolute(height)))
}
public func constraint(_ constraintComponent: @escaping (Constraint) -> Constraint) -> ConstraintOverrideViewComponent<R, Self> {
public func constraint(_ constraintComponent: @escaping (Constraint) -> Constraint) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: BlockConstraintTransformer(block: constraintComponent))
}
public func constraint(_ constraint: Constraint) -> ConstraintOverrideViewComponent<R, Self> {
public func constraint(_ constraint: Constraint) -> ConstraintOverrideViewComponent<Self> {
ConstraintOverrideViewComponent(child: self, transformer: PassThroughConstraintTransformer(constraint: constraint))
}
public func unboundedWidth() -> ConstraintOverrideViewComponent<R, Self> {
public func unboundedWidth() -> ConstraintOverrideViewComponent<Self> {
constraint { c in
Constraint(minSize: c.minSize, maxSize: CGSize(width: .infinity, height: c.maxSize.height))
}
}
public func unboundedHeight() -> ConstraintOverrideViewComponent<R, Self> {
public func unboundedHeight() -> ConstraintOverrideViewComponent<Self> {
constraint { c in
Constraint(minSize: c.minSize, maxSize: CGSize(width: c.maxSize.width, height: .infinity))
}
Expand Down

0 comments on commit 1f0690b

Please sign in to comment.