Skip to content

Commit

Permalink
Exclude Epoxy directory from SwiftFormat analysis (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamede1945 authored Jan 19, 2024
1 parent 830eeb6 commit a9403b0
Show file tree
Hide file tree
Showing 9 changed files with 1,001 additions and 894 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Don't format
--exclude .build
--exclude .build,UI/UIx/SwiftUI/Epoxy

# Options

Expand Down
797 changes: 391 additions & 406 deletions UI/UIx/SwiftUI/Epoxy/CollectionViewScrollToItemHelper.swift

Large diffs are not rendered by default.

56 changes: 48 additions & 8 deletions UI/UIx/SwiftUI/Epoxy/DataIDProviding.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
// From: https://github.com/airbnb/epoxy-ios/blob/ecee1ace58d58e3cc918a2dea28095de713b1112

// Created by eric_horacek on 12/1/20.
// Copyright © 2020 Airbnb Inc. All rights reserved.

// MARK: - DataIDProviding

/// The capability of providing a stable data identifier with an erased type.
///
/// While it has similar semantics, this type cannot inherit from `Identifiable` as this would give
/// it an associated type, which would cause the `keyPath` used in its `EpoxyModelProperty` to not
/// be stable across types if written as `\Self.dataID` since the `KeyPath` `Root` would be
/// different for each type.
///
/// - SeeAlso: `Identifiable`.
public protocol DataIDProviding {
/// A stable identifier that uniquely identifies this instance, with its typed erased.
///
/// Defaults to `DefaultDataID.noneProvided` if no data ID is provided.
var dataID: AnyHashable { get }
}

// MARK: - EpoxyModeled

extension EpoxyModeled where Self: DataIDProviding {

// MARK: Public

/// A stable identifier that uniquely identifies this model, with its typed erased.
public var dataID: AnyHashable {
get { self[dataIDProperty] }
set { self[dataIDProperty] = newValue }
}

/// Returns a copy of this model with the ID replaced with the provided ID.
public func dataID(_ value: AnyHashable) -> Self {
copy(updating: dataIDProperty, to: value)
}

// MARK: Private

private var dataIDProperty: EpoxyModelProperty<AnyHashable> {
EpoxyModelProperty(
keyPath: \DataIDProviding.dataID,
defaultValue: DefaultDataID.noneProvided,
updateStrategy: .replace)
}
}

// MARK: - DefaultDataID

/// The default data ID when none is provided.
public enum DefaultDataID: Hashable, CustomDebugStringConvertible {
case noneProvided

// MARK: Public
case noneProvided

public var debugDescription: String {
"DefaultDataID.noneProvided"
}
public var debugDescription: String {
"DefaultDataID.noneProvided"
}
}
26 changes: 10 additions & 16 deletions UI/UIx/SwiftUI/Epoxy/EpoxyIntrinsicContentSizeInvalidator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// From: https://github.com/airbnb/epoxy-ios/blob/ecee1ace58d58e3cc918a2dea28095de713b1112

// Created by matthew_cheok on 11/19/21.
// Copyright © 2021 Airbnb Inc. All rights reserved.

Expand All @@ -21,29 +19,25 @@ import SwiftUI
/// }
/// ```
public struct EpoxyIntrinsicContentSizeInvalidator {
// MARK: Public

public func callAsFunction() {
invalidate()
}

// MARK: Internal
let invalidate: () -> Void

let invalidate: () -> Void
public func callAsFunction() {
invalidate()
}
}

// MARK: - EnvironmentValues

extension EnvironmentValues {
/// A means of invalidating the intrinsic content size of the parent `EpoxySwiftUIHostingView`.
public var epoxyIntrinsicContentSizeInvalidator: EpoxyIntrinsicContentSizeInvalidator {
get { self[EpoxyIntrinsicContentSizeInvalidatorKey.self] }
set { self[EpoxyIntrinsicContentSizeInvalidatorKey.self] = newValue }
}
/// A means of invalidating the intrinsic content size of the parent `EpoxySwiftUIHostingView`.
public var epoxyIntrinsicContentSizeInvalidator: EpoxyIntrinsicContentSizeInvalidator {
get { self[EpoxyIntrinsicContentSizeInvalidatorKey.self] }
set { self[EpoxyIntrinsicContentSizeInvalidatorKey.self] = newValue }
}
}

// MARK: - EpoxyIntrinsicContentSizeInvalidatorKey

private struct EpoxyIntrinsicContentSizeInvalidatorKey: EnvironmentKey {
static let defaultValue = EpoxyIntrinsicContentSizeInvalidator(invalidate: { })
static let defaultValue = EpoxyIntrinsicContentSizeInvalidator(invalidate: { })
}
86 changes: 38 additions & 48 deletions UI/UIx/SwiftUI/Epoxy/EpoxySwiftUIHostingController.swift
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
// From: https://github.com/airbnb/epoxy-ios/blob/ecee1ace58d58e3cc918a2dea28095de713b1112

// Created by eric_horacek on 10/8/21.
// Copyright © 2021 Airbnb Inc. All rights reserved.

import SwiftUI

#if !os(macOS)

// MARK: - EpoxySwiftUIUIHostingController

/// A `UIHostingController` that hosts SwiftUI views within an Epoxy container, e.g. an Epoxy
/// `CollectionView`.
///
/// Exposed publicly to allow consumers to reason about these view controllers, e.g. to opt
/// collection view cells out of automated view controller impression tracking.
///
/// - SeeAlso: `EpoxySwiftUIHostingView`
open class EpoxySwiftUIHostingController<Content: View>: UIHostingController<Content> {
// MARK: Lifecycle

/// Creates a `UIHostingController` that optionally ignores the `safeAreaInsets` when laying out
/// its contained `RootView`.
public convenience init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)

clearBackground()

// We unfortunately need to call a private API to disable the safe area. We can also accomplish
// this by dynamically subclassing this view controller's view at runtime and overriding its
// `safeAreaInsets` property and returning `.zero`. An implementation of that logic is
// available in this file in the `2d28b3181cca50b89618b54836f7a9b6e36ea78e` commit if this API
// no longer functions in future SwiftUI versions.
_disableSafeArea = ignoreSafeArea
}

// MARK: Open

override open func viewDidLoad() {
super.viewDidLoad()

clearBackground()
}

// MARK: Internal

func clearBackground() {
// A `UIHostingController` has a system background color by default as it's typically used in
// full-screen use cases. Since we're using this view controller to place SwiftUI views within
// other view controllers we default the background color to clear so we can see the views
// below, e.g. to draw highlight states in a `CollectionView`.
view.backgroundColor = .clear
}
}
// MARK: - EpoxySwiftUIUIHostingController

/// A `UIHostingController` that hosts SwiftUI views within an Epoxy container, e.g. an Epoxy
/// `CollectionView`.
///
/// Exposed publicly to allow consumers to reason about these view controllers, e.g. to opt
/// collection view cells out of automated view controller impression tracking.
///
/// - SeeAlso: `EpoxySwiftUIHostingView`
open class EpoxySwiftUIHostingController<Content: View>: UIHostingController<Content> {

// MARK: Lifecycle

/// Creates a `UIHostingController` that optionally ignores the `safeAreaInsets` when laying out
/// its contained `RootView`.
public convenience init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)

// We unfortunately need to call a private API to disable the safe area. We can also accomplish
// this by dynamically subclassing this view controller's view at runtime and overriding its
// `safeAreaInsets` property and returning `.zero`. An implementation of that logic is
// available in this file in the `2d28b3181cca50b89618b54836f7a9b6e36ea78e` commit if this API
// no longer functions in future SwiftUI versions.
_disableSafeArea = ignoreSafeArea
}

// MARK: Open

open override func viewDidLoad() {
super.viewDidLoad()

// A `UIHostingController` has a system background color by default as it's typically used in
// full-screen use cases. Since we're using this view controller to place SwiftUI views within
// other view controllers we default the background color to clear so we can see the views
// below, e.g. to draw highlight states in a `CollectionView`.
view.backgroundColor = .clear
}
}
#endif
Loading

0 comments on commit a9403b0

Please sign in to comment.