Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptation AppKit #78

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ fastlane/test_output
iOSInjectionProject/
Example/Pods
Gemfile.lock
.DS_Store
contents.xcworkspacedata
6 changes: 4 additions & 2 deletions ChatLayout.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ supplementary view sizes.
s.source = { :git => 'https://github.com/ekazaev/ChatLayout.git', :tag => s.version.to_s }

s.ios.deployment_target = '12.0'

s.osx.deployment_target = '11.0'

s.default_subspec = "Ultimate"

s.subspec "Ultimate" do |complete|
Expand All @@ -33,5 +34,6 @@ supplementary view sizes.
extras.dependency "ChatLayout/Core"
end

s.frameworks = 'UIKit'
s.ios.frameworks = 'UIKit'
s.osx.frameworks = 'AppKit'
end
44 changes: 38 additions & 6 deletions ChatLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@
45A45FF12568570300F0A68A /* IndexPath+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A45FF02568570300F0A68A /* IndexPath+Extension.swift */; };
45E987C8261340C9008ECE6E /* ChangeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45E987C7261340C9008ECE6E /* ChangeItem.swift */; };
841578F82A1E2572002EB2EC /* RandomAccessCollection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841578F72A1E2572002EB2EC /* RandomAccessCollection+Extension.swift */; };
841578FA2A1E2580002EB2EC /* UILayoutPriority+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841578F92A1E2580002EB2EC /* UILayoutPriority+Extension.swift */; };
841578FA2A1E2580002EB2EC /* LayoutPriority+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841578F92A1E2580002EB2EC /* LayoutPriority+Extension.swift */; };
84424F702A17E7320079E09E /* SwappingContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84424F6F2A17E7320079E09E /* SwappingContainerView.swift */; };
84424F742A17E7420079E09E /* NSLayoutAnchor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84424F722A17E7420079E09E /* NSLayoutAnchor+Extension.swift */; };
84424F752A17E7420079E09E /* NSLayoutDimension+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84424F732A17E7420079E09E /* NSLayoutDimension+Extension.swift */; };
84D248F0296354B90060BBF1 /* CollectionViewChatLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D248EF296354B90060BBF1 /* CollectionViewChatLayout.swift */; };
E93614332B4FD77100413751 /* ContainerCollectionViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93614322B4FD77100413751 /* ContainerCollectionViewItem.swift */; };
E97131652B50E16700AA3D66 /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E97131642B50E16700AA3D66 /* NSView+Extension.swift */; };
E97131672B50ED7D00AA3D66 /* CollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E97131662B50ED7D00AA3D66 /* CollectionReusableView.swift */; };
E97495E62B47E4FB00B6E6C2 /* NSEdgeInsets+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E97495E32B47E4FB00B6E6C2 /* NSEdgeInsets+Extension.swift */; };
E97495E72B47E4FB00B6E6C2 /* CollectionView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E97495E42B47E4FB00B6E6C2 /* CollectionView+Extension.swift */; };
E97495E82B47E4FB00B6E6C2 /* CollectionViewLayoutAttributes+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E97495E52B47E4FB00B6E6C2 /* CollectionViewLayoutAttributes+Extension.swift */; };
E97495EA2B47E50400B6E6C2 /* Typealias.swift in Sources */ = {isa = PBXBuildFile; fileRef = E97495E92B47E50400B6E6C2 /* Typealias.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -71,11 +78,18 @@
45AF49BA24D9F3C000B5BBC2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = SOURCE_ROOT; };
45E987C7261340C9008ECE6E /* ChangeItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeItem.swift; sourceTree = "<group>"; };
841578F72A1E2572002EB2EC /* RandomAccessCollection+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RandomAccessCollection+Extension.swift"; sourceTree = "<group>"; };
841578F92A1E2580002EB2EC /* UILayoutPriority+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILayoutPriority+Extension.swift"; sourceTree = "<group>"; };
841578F92A1E2580002EB2EC /* LayoutPriority+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "LayoutPriority+Extension.swift"; sourceTree = "<group>"; };
84424F6F2A17E7320079E09E /* SwappingContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwappingContainerView.swift; sourceTree = "<group>"; };
84424F722A17E7420079E09E /* NSLayoutAnchor+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSLayoutAnchor+Extension.swift"; sourceTree = "<group>"; };
84424F732A17E7420079E09E /* NSLayoutDimension+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSLayoutDimension+Extension.swift"; sourceTree = "<group>"; };
84D248EF296354B90060BBF1 /* CollectionViewChatLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewChatLayout.swift; sourceTree = "<group>"; };
E93614322B4FD77100413751 /* ContainerCollectionViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerCollectionViewItem.swift; sourceTree = "<group>"; };
E97131642B50E16700AA3D66 /* NSView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = "<group>"; };
E97131662B50ED7D00AA3D66 /* CollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionReusableView.swift; sourceTree = "<group>"; };
E97495E32B47E4FB00B6E6C2 /* NSEdgeInsets+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSEdgeInsets+Extension.swift"; sourceTree = "<group>"; };
E97495E42B47E4FB00B6E6C2 /* CollectionView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CollectionView+Extension.swift"; sourceTree = "<group>"; };
E97495E52B47E4FB00B6E6C2 /* CollectionViewLayoutAttributes+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CollectionViewLayoutAttributes+Extension.swift"; sourceTree = "<group>"; };
E97495E92B47E50400B6E6C2 /* Typealias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Typealias.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -101,6 +115,7 @@
455ED42D2534BF1B00F4A83F /* ChatLayoutAttributes.swift */,
455ED42E2534BF1B00F4A83F /* Model */,
455ED4362534BF1B00F4A83F /* ChatLayoutSettings.swift */,
E97495E92B47E50400B6E6C2 /* Typealias.swift */,
);
name = Core;
path = Classes/Core;
Expand All @@ -112,6 +127,10 @@
841578F72A1E2572002EB2EC /* RandomAccessCollection+Extension.swift */,
455ED42C2534BF1B00F4A83F /* CGRect+Extension.swift */,
45A45FF02568570300F0A68A /* IndexPath+Extension.swift */,
E97495E42B47E4FB00B6E6C2 /* CollectionView+Extension.swift */,
E97495E52B47E4FB00B6E6C2 /* CollectionViewLayoutAttributes+Extension.swift */,
E97495E32B47E4FB00B6E6C2 /* NSEdgeInsets+Extension.swift */,
E97131642B50E16700AA3D66 /* NSView+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand All @@ -138,7 +157,9 @@
84424F712A17E7420079E09E /* Extensions */,
4570EE5C264C276C00103D39 /* ContainerCollectionViewCellDelegate.swift */,
455ED43F2534BF1B00F4A83F /* ContainerCollectionViewCell.swift */,
E93614322B4FD77100413751 /* ContainerCollectionViewItem.swift */,
455ED43A2534BF1B00F4A83F /* ContainerCollectionReusableView.swift */,
E97131662B50ED7D00AA3D66 /* CollectionReusableView.swift */,
455ED4382534BF1B00F4A83F /* CellLayoutContainerView.swift */,
455ED4392534BF1B00F4A83F /* StaticViewFactory.swift */,
455ED43B2534BF1B00F4A83F /* ImageMaskedView.swift */,
Expand Down Expand Up @@ -182,7 +203,7 @@
children = (
84424F722A17E7420079E09E /* NSLayoutAnchor+Extension.swift */,
84424F732A17E7420079E09E /* NSLayoutDimension+Extension.swift */,
841578F92A1E2580002EB2EC /* UILayoutPriority+Extension.swift */,
841578F92A1E2580002EB2EC /* LayoutPriority+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -267,13 +288,17 @@
buildActionMask = 2147483647;
files = (
455ED4462534BF1B00F4A83F /* ChatLayoutAttributes.swift in Sources */,
E97495E82B47E4FB00B6E6C2 /* CollectionViewLayoutAttributes+Extension.swift in Sources */,
455ED44B2534BF1B00F4A83F /* StateController.swift in Sources */,
841578FA2A1E2580002EB2EC /* UILayoutPriority+Extension.swift in Sources */,
E97495E72B47E4FB00B6E6C2 /* CollectionView+Extension.swift in Sources */,
841578FA2A1E2580002EB2EC /* LayoutPriority+Extension.swift in Sources */,
455ED4432534BF1B00F4A83F /* ChatLayoutPositionSnapshot.swift in Sources */,
455ED4442534BF1B00F4A83F /* ChatItemAlignment.swift in Sources */,
84D248F0296354B90060BBF1 /* CollectionViewChatLayout.swift in Sources */,
84424F752A17E7420079E09E /* NSLayoutDimension+Extension.swift in Sources */,
84424F702A17E7320079E09E /* SwappingContainerView.swift in Sources */,
E97131672B50ED7D00AA3D66 /* CollectionReusableView.swift in Sources */,
E97495EA2B47E50400B6E6C2 /* Typealias.swift in Sources */,
455ED4542534BF1B00F4A83F /* RoundedCornersContainerView.swift in Sources */,
455ED4532534BF1B00F4A83F /* MessageContainerView.swift in Sources */,
455ED44F2534BF1B00F4A83F /* CellLayoutContainerView.swift in Sources */,
Expand All @@ -286,14 +311,17 @@
455ED4482534BF1B00F4A83F /* ItemModel.swift in Sources */,
455ED4492534BF1B00F4A83F /* ItemKind.swift in Sources */,
455ED4552534BF1B00F4A83F /* EdgeAligningView.swift in Sources */,
E97495E62B47E4FB00B6E6C2 /* NSEdgeInsets+Extension.swift in Sources */,
455ED44E2534BF1B00F4A83F /* ChatLayoutSettings.swift in Sources */,
455ED44D2534BF1B00F4A83F /* ModelState.swift in Sources */,
841578F82A1E2572002EB2EC /* RandomAccessCollection+Extension.swift in Sources */,
455ED4472534BF1B00F4A83F /* SectionModel.swift in Sources */,
455ED4422534BF1B00F4A83F /* ChatLayoutInvalidationContext.swift in Sources */,
E97131652B50E16700AA3D66 /* NSView+Extension.swift in Sources */,
455ED4452534BF1B00F4A83F /* CGRect+Extension.swift in Sources */,
455ED4502534BF1B00F4A83F /* StaticViewFactory.swift in Sources */,
455ED4402534BF1B00F4A83F /* ChatLayoutDelegate.swift in Sources */,
E93614332B4FD77100413751 /* ContainerCollectionViewItem.swift in Sources */,
455ED4562534BF1B00F4A83F /* ContainerCollectionViewCell.swift in Sources */,
4570EE5D264C276C00103D39 /* ContainerCollectionViewCellDelegate.swift in Sources */,
45A45FEE256856ED00F0A68A /* ItemPath.swift in Sources */,
Expand Down Expand Up @@ -431,7 +459,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = PG4V34R8QT;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -445,6 +473,8 @@
PRODUCT_BUNDLE_IDENTIFIER = ie.ekazaev.ChatLayout;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -455,7 +485,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = PG4V34R8QT;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -469,6 +499,8 @@
PRODUCT_BUNDLE_IDENTIFIER = ie.ekazaev.ChatLayout;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
1 change: 0 additions & 1 deletion ChatLayout/Classes/Core/ChatItemAlignment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//

import Foundation
import UIKit

/// Represent item alignment in collection view layout
public enum ChatItemAlignment: Hashable {
Expand Down
32 changes: 25 additions & 7 deletions ChatLayout/Classes/Core/ChatLayoutAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@
//

import Foundation
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit
#endif

#if canImport(UIKit)
import UIKit
#endif

/// Custom implementation of `UICollectionViewLayoutAttributes`
public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
public final class ChatLayoutAttributes: NSUICollectionViewLayoutAttributes {
/// Alignment of the current item. Can be changed within `UICollectionViewCell.preferredLayoutAttributesFitting(...)`
public var alignment: ChatItemAlignment = .fullWidth

/// Inter item spacing. Can be changed within `UICollectionViewCell.preferredLayoutAttributesFitting(...)`
public var interItemSpacing: CGFloat = 0

/// `CollectionViewChatLayout`s additional insets setup using `ChatLayoutSettings`. Added for convenience.
public internal(set) var additionalInsets: UIEdgeInsets = .zero
public internal(set) var additionalInsets: NSUIEdgeInsets = .zero

/// `UICollectionView`s frame size. Added for convenience.
public internal(set) var viewSize: CGSize = .zero

/// `UICollectionView`s adjusted content insets. Added for convenience.
public internal(set) var adjustedContentInsets: UIEdgeInsets = .zero
public internal(set) var adjustedContentInsets: NSUIEdgeInsets = .zero

/// `CollectionViewChatLayout`s visible bounds size excluding `adjustedContentInsets`. Added for convenience.
public internal(set) var visibleBoundsSize: CGSize = .zero
Expand All @@ -43,11 +49,17 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
convenience init(kind: ItemKind, indexPath: IndexPath = IndexPath(item: 0, section: 0)) {
switch kind {
case .cell:
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
self.init(forItemWith: indexPath)
#endif

#if canImport(UIKit)
self.init(forCellWith: indexPath)
#endif
case .header:
self.init(forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, with: indexPath)
self.init(forSupplementaryViewOfKind: NSUICollectionView.elementKindSectionHeader, with: indexPath)
case .footer:
self.init(forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, with: indexPath)
self.init(forSupplementaryViewOfKind: NSUICollectionView.elementKindSectionFooter, with: indexPath)
}
}

Expand Down Expand Up @@ -77,11 +89,17 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes {
/// `ItemKind` represented by this attributes object.
public var kind: ItemKind {
switch (representedElementCategory, representedElementKind) {
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
case (.item, nil):
.cell
#endif
#if canImport(UIKit)
case (.cell, nil):
.cell
case (.supplementaryView, .some(UICollectionView.elementKindSectionHeader)):
#endif
case (.supplementaryView, .some(NSUICollectionView.elementKindSectionHeader)):
.header
case (.supplementaryView, .some(UICollectionView.elementKindSectionFooter)):
case (.supplementaryView, .some(NSUICollectionView.elementKindSectionFooter)):
.footer
default:
preconditionFailure("Unsupported element kind.")
Expand Down
6 changes: 6 additions & 0 deletions ChatLayout/Classes/Core/ChatLayoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
//

import Foundation
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit
#endif

#if canImport(UIKit)
import UIKit
#endif

/// Represents the point in time when `CollectionViewChatLayout` asks about layout attributes modification.
public enum InitialAttributesRequestType: Hashable {
Expand Down
9 changes: 8 additions & 1 deletion ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
//

import Foundation
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit
#endif

#if canImport(UIKit)
import UIKit
#endif

/// Custom implementation of `UICollectionViewLayoutInvalidationContext`
public final class ChatLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext {
public final class ChatLayoutInvalidationContext: NSUICollectionViewLayoutInvalidationContext {

/// Indicates whether to recompute the positions and sizes of the items based on the current
/// collection view and delegate layout metrics.
public var invalidateLayoutMetrics = true
Expand Down
6 changes: 6 additions & 0 deletions ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
//

import Foundation
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit
#endif

#if canImport(UIKit)
import UIKit
#endif

/// Represents content offset position expressed by the specific item and it offset from the top or bottom edge.
public struct ChatLayoutPositionSnapshot: Hashable {
Expand Down
9 changes: 8 additions & 1 deletion ChatLayout/Classes/Core/ChatLayoutSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
//

import Foundation
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
import AppKit
#endif

#if canImport(UIKit)
import UIKit
#endif

/// `CollectionViewChatLayout` settings.
public struct ChatLayoutSettings: Equatable {
Expand All @@ -26,5 +32,6 @@ public struct ChatLayoutSettings: Equatable {
public var interSectionSpacing: CGFloat = 0

/// Additional insets for the `CollectionViewChatLayout` content.
public var additionalInsets: UIEdgeInsets = .zero
public var additionalInsets: NSUIEdgeInsets = .zero

}
Loading