Skip to content

Commit

Permalink
SwiftFormat for code-style consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Apptek Studios committed Jan 6, 2020
1 parent a3e5402 commit ff46f57
Show file tree
Hide file tree
Showing 31 changed files with 322 additions and 260 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Demo/BuildTools/.build
5 changes: 1 addition & 4 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
--fractiongrouping disabled
--ifdef outdent
--importgrouping testable-top
--operatorfunc no-space
--ranges no-space
--selfrequired validate
--stripunusedargs closure-only
--wraparguments before-first
--wrapcollections before-first
--wrapcollections after-first
22 changes: 22 additions & 0 deletions Demo/ASCollectionViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
B86C6F0F234B078600522AEF /* Sources */,
B86C6F10234B078600522AEF /* Frameworks */,
B86C6F11234B078600522AEF /* Resources */,
B8E6691323C2C8700034A9C1 /* SwiftFormat */,
);
buildRules = (
);
Expand Down Expand Up @@ -319,6 +320,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
B8E6691323C2C8700034A9C1 /* SwiftFormat */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftFormat;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd BuildTools\n\n#Temporarily uncomment the following line to update your packages (based on the versions defined in BuildTools/Package.swift)\n#swift package update\n\n#swift run -c release swiftformat \"$SRCROOT/../\"\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
B86C6F0F234B078600522AEF /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ struct AdjustableGridScreen: View
{
VStack
{
Stepper("Number of columns", value: self.$layoutState.numberOfColumns, in: 0...10)
Stepper("Number of columns", value: self.$layoutState.numberOfColumns, in: 0 ... 10)
.padding()
Stepper("Item inset", value: self.$layoutState.itemInset, in: 0...5)
Stepper("Item inset", value: self.$layoutState.itemInset, in: 0 ... 5)
.padding()
Toggle(isOn: self.$animateChange) { Text("Animate layout change") }
.padding()
Expand All @@ -83,7 +83,7 @@ struct AdjustableGridScreen: View
ASCollectionView(
section: section)
.layout(self.layout)
.shouldInvalidateLayoutOnStateChange(true, animated: self.animateChange) ///////////////////////// TELLS ASCOLLECTIONVIEW TO INVALIDATE THE LAYOUT WHEN THE VIEW IS UPDATED
.shouldInvalidateLayoutOnStateChange(true, animated: self.animateChange) /// ////////////////////// TELLS ASCOLLECTIONVIEW TO INVALIDATE THE LAYOUT WHEN THE VIEW IS UPDATED
.navigationBarTitle("Adjustable Layout", displayMode: .inline)
}
.navigationBarItems(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftUI

struct AppStoreScreen: View
{
@State var data: [(sectionTitle: String, apps: [App])] = (0...20).map
@State var data: [(sectionTitle: String, apps: [App])] = (0 ... 20).map
{
(Lorem.title, DataSource.appsForSection($0))
}
Expand Down
79 changes: 41 additions & 38 deletions Demo/ASCollectionViewDemo/Screens/InstaFeed/InstaFeedScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import UIKit
struct InstaFeedScreen: View
{
@State var storiesData: [Post] = DataSource.postsForInstaSection(0, number: 12)
@State var data: [[Post]] = (0...1).map { DataSource.postsForInstaSection($0 + 1) }
@State var data: [[Post]] = (0 ... 1).map { DataSource.postsForInstaSection($0 + 1) }

var storiesCollectionView: some View {
var storiesCollectionView: some View
{
ASCollectionView(
section:
ASCollectionViewSection(
Expand All @@ -20,52 +21,54 @@ struct InstaFeedScreen: View
StoryView(post: item)
})
.layout(scrollDirection: .horizontal)
{
.list(itemSize: .absolute(100), sectionInsets: NSDirectionalEdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
{
.list(itemSize: .absolute(100), sectionInsets: NSDirectionalEdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}
.frame(height: 100)
.scrollIndicatorsEnabled(false)
.onCollectionViewReachedBoundary
{ boundary in
print("Reached the \(boundary) boundary")
{ boundary in
print("Reached the \(boundary) boundary")
}
}

var storiesSection: ASTableViewSection<Int> {
return ASTableViewSection(id: 0)

var storiesSection: ASTableViewSection<Int>
{
ASTableViewSection(id: 0)
{
storiesCollectionView
}
}

var postSections: [ASTableViewSection<Int>] {

var postSections: [ASTableViewSection<Int>]
{
data.enumerated().map
{ i, sectionData in
return ASTableViewSection(
id: i + 1,
data: sectionData,
onCellEvent: onCellEventPosts)
{ item, _ in
PostView(post: item)
}
.tableViewSetEstimatedSizes(rowHeight: 500, headerHeight: 50) // Optional: Provide reasonable estimated heights for this section
.sectionHeader
{ i, sectionData in
ASTableViewSection(
id: i + 1,
data: sectionData,
onCellEvent: onCellEventPosts)
{ item, _ in
PostView(post: item)
}
.tableViewSetEstimatedSizes(rowHeight: 500, headerHeight: 50) // Optional: Provide reasonable estimated heights for this section
.sectionHeader
{
VStack(spacing: 0)
{
HStack
{
VStack(spacing: 0)
{
HStack
{
Text("Demo sticky header view")
.padding(EdgeInsets(top: 4, leading: 20, bottom: 4, trailing: 20))
Spacer()
}
Divider()
}
.background(Color(.secondarySystemBackground))
Text("Demo sticky header view")
.padding(EdgeInsets(top: 4, leading: 20, bottom: 4, trailing: 20))
Spacer()
}
Divider()
}
.background(Color(.secondarySystemBackground))
}
}
}

var sections: [ASTableViewSection<Int>]
{
[storiesSection] + postSections
Expand All @@ -77,21 +80,21 @@ struct InstaFeedScreen: View
.tableViewSeparatorsEnabled(false)
.onTableViewPullToRefresh { endRefreshing in
print("PULL TO REFRESH")
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { (_) in
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
endRefreshing()
}
}
}
.onTableViewReachedBottom
{
self.loadMoreContent() // REACHED BOTTOM, LOADING MORE CONTENT
{
self.loadMoreContent() // REACHED BOTTOM, LOADING MORE CONTENT
}
.navigationBarTitle("Insta Feed (tableview)", displayMode: .inline)
}

func loadMoreContent()
{
let a = data.count
data.append(DataSource.postsForInstaSection(a+1))
data.append(DataSource.postsForInstaSection(a + 1))
}

func onCellEventStories(_ event: CellEvent<Post>)
Expand Down
2 changes: 1 addition & 1 deletion Demo/ASCollectionViewDemo/Screens/InstaFeed/PostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ struct PostView_Previews: PreviewProvider
{
static var previews: some View
{
PostView(post: Post.randomPost(Int.random(in: 0...1000), aspectRatio: 1))
PostView(post: Post.randomPost(Int.random(in: 0 ... 1000), aspectRatio: 1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ struct StoryView_Previews: PreviewProvider
{
static var previews: some View
{
StoryView(post: Post.randomPost(Int.random(in: 0...1000), aspectRatio: 1))
StoryView(post: Post.randomPost(Int.random(in: 0 ... 1000), aspectRatio: 1))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit

struct MagazineLayoutScreen: View
{
@State var data: [[Post]] = (0...5).map
@State var data: [[Post]] = (0 ... 5).map
{
DataSource.postsForGridSection($0, number: 10)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ struct PhotoGridScreen: View
}
}
}

func destinationForItem(_ item: Post) -> some View {

func destinationForItem(_ item: Post) -> some View
{
ScrollView {
PostView(post: item)
.onAppear {
ASRemoteImageManager.shared.load(item.url)
ASRemoteImageManager.shared.load(item.usernamePhotoURL)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct GroupModel: Identifiable
{
var icon: String
var title: String
var contentCount: Int? = Int.random(in: 0...20)
var contentCount: Int? = Int.random(in: 0 ... 20)
var color: Color = [Color.red, Color.orange, Color.blue, Color.purple].randomElement()!

static var demo = GroupModel(icon: "paperplane", title: "Test category", contentCount: 19)
Expand Down
34 changes: 15 additions & 19 deletions Demo/ASCollectionViewDemo/Screens/Reminders/RemindersScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ struct RemindersScreen: View
case footnote
}

@State var upperData: [GroupModel] = [
GroupModel(icon: "calendar", title: "Today", color: .blue),
GroupModel(icon: "clock.fill", title: "Scheduled", color: .orange),
GroupModel(icon: "tray.fill", title: "All", color: .gray),
GroupModel(icon: "flag.fill", title: "Flagged", color: .red)
]
@State var lowerData: [GroupModel] = [
GroupModel(icon: "list.bullet", title: "Todo"),
GroupModel(icon: "cart.fill", title: "Groceries"),
GroupModel(icon: "house.fill", title: "House renovation"),
GroupModel(icon: "book.fill", title: "Reading list")
]
@State var upperData: [GroupModel] = [GroupModel(icon: "calendar", title: "Today", color: .blue),
GroupModel(icon: "clock.fill", title: "Scheduled", color: .orange),
GroupModel(icon: "tray.fill", title: "All", color: .gray),
GroupModel(icon: "flag.fill", title: "Flagged", color: .red)]
@State var lowerData: [GroupModel] = [GroupModel(icon: "list.bullet", title: "Todo"),
GroupModel(icon: "cart.fill", title: "Groceries"),
GroupModel(icon: "house.fill", title: "House renovation"),
GroupModel(icon: "book.fill", title: "Reading list")]

let addNewModel = GroupModel(icon: "plus", title: "Create new list", contentCount: nil, color: .green)

Expand Down Expand Up @@ -64,15 +60,15 @@ struct RemindersScreen: View
{
GroupSmall(model: self.addNewModel)
}

ASCollectionViewSection<Section>(id: .footnote)
{
HStack
{
Spacer()
Text("Try rotating the screen")
.padding()
Spacer()
{
Spacer()
Text("Try rotating the screen")
.padding()
Spacer()
}
}
}
Expand Down Expand Up @@ -113,7 +109,7 @@ struct RemindersScreen: View

let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20)

let supplementarySize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(50))
let headerSupplementary = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: supplementarySize,
Expand Down
2 changes: 1 addition & 1 deletion Demo/ASCollectionViewDemo/Screens/Tags/TagStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TagStore: ObservableObject

static func randomItems() -> [Item]
{
TagStore.allWords.indices.shuffled()[0...Int.random(in: 8...18)].map
TagStore.allWords.indices.shuffled()[0 ... Int.random(in: 8 ... 18)].map
{
Item(id: $0, displayString: TagStore.allWords[$0])
}
Expand Down
2 changes: 1 addition & 1 deletion Demo/ASCollectionViewDemo/Screens/Tags/TagsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class AlignedFlowLayout: UICollectionViewFlowLayout
}
guard
indexPath.item > 0,
let previousAttributes = self.layoutAttributesForItem(at: IndexPath(item: indexPath.item - 1, section: indexPath.section))
let previousAttributes = layoutAttributesForItem(at: IndexPath(item: indexPath.item - 1, section: indexPath.section))
else
{
attributes.frame.origin.x = leftEdge // first item of the section should always be left aligned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct WaterfallScreen: View
HStack
{
Text("Min. column size")
Slider(value: self.$columnMinSize, in: 60...200)
Slider(value: self.$columnMinSize, in: 60 ... 200)
}.padding()
}

Expand Down
Loading

0 comments on commit ff46f57

Please sign in to comment.