Skip to content

Commit

Permalink
making custon gridview to allow compatibility with macOS X
Browse files Browse the repository at this point in the history
  • Loading branch information
sjgutta committed Jan 9, 2021
1 parent 2cebcf6 commit 3136076
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
3D4C8EFAEA272979675B8141 /* Pods_personal_scoreboard_personal_scoreboardUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C265E8C2994388C5410572C0 /* Pods_personal_scoreboard_personal_scoreboardUITests.framework */; };
640B35B825A13345004D303C /* Pods_personal_scoreboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BACE9E46131DCE659A328D97 /* Pods_personal_scoreboard.framework */; };
648A893F25AA24E800F26CF3 /* EventGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648A893E25AA24E800F26CF3 /* EventGridView.swift */; };
64BAB61D258FA79F00236E4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BAB61C258FA79F00236E4E /* AppDelegate.swift */; };
64BAB61F258FA79F00236E4E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64BAB61E258FA79F00236E4E /* ContentView.swift */; };
64BAB621258FA7A300236E4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 64BAB620258FA7A300236E4E /* Assets.xcassets */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
16143F6DE9CAFB9FCE9CC25C /* Pods-personal-scoreboard-personal-scoreboardUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-personal-scoreboard-personal-scoreboardUITests.release.xcconfig"; path = "Target Support Files/Pods-personal-scoreboard-personal-scoreboardUITests/Pods-personal-scoreboard-personal-scoreboardUITests.release.xcconfig"; sourceTree = "<group>"; };
1ADFDBD763EBDF3FE0B25048 /* Pods-personal-scoreboard-personal-scoreboardUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-personal-scoreboard-personal-scoreboardUITests.debug.xcconfig"; path = "Target Support Files/Pods-personal-scoreboard-personal-scoreboardUITests/Pods-personal-scoreboard-personal-scoreboardUITests.debug.xcconfig"; sourceTree = "<group>"; };
4C9EE8805F6E3B9FD8E520A0 /* Pods-personal-scoreboard.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-personal-scoreboard.release.xcconfig"; path = "Target Support Files/Pods-personal-scoreboard/Pods-personal-scoreboard.release.xcconfig"; sourceTree = "<group>"; };
648A893E25AA24E800F26CF3 /* EventGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventGridView.swift; sourceTree = "<group>"; };
64BAB619258FA79F00236E4E /* personal-scoreboard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "personal-scoreboard.app"; sourceTree = BUILT_PRODUCTS_DIR; };
64BAB61C258FA79F00236E4E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
64BAB61E258FA79F00236E4E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -150,6 +152,7 @@
64BAB66625A0146100236E4E /* Team.swift */,
64BAB67325A128B200236E4E /* RequestFunctions.swift */,
64E5250825A68628007D4DA9 /* HelpView.swift */,
648A893E25AA24E800F26CF3 /* EventGridView.swift */,
);
path = "personal-scoreboard";
sourceTree = "<group>";
Expand Down Expand Up @@ -438,6 +441,7 @@
64BAB61D258FA79F00236E4E /* AppDelegate.swift in Sources */,
64E5250925A68628007D4DA9 /* HelpView.swift in Sources */,
64BAB655259EBAE000236E4E /* EventView.swift in Sources */,
648A893F25AA24E800F26CF3 /* EventGridView.swift in Sources */,
64BAB66225A013E200236E4E /* Event.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -618,7 +622,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = "sjgutta.personal-scoreboard";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -643,7 +647,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = "sjgutta.personal-scoreboard";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,13 @@ struct ContentView: View {
Text("Press 'Hide Help' above to view scores again.").font(.headline).bold().padding(.top, 25)
Text("").frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
let gridItems = [GridItem(.fixed(275), spacing: 10, alignment: .center),
GridItem(.fixed(275), spacing: 0, alignment: .center)]

let current_event_objs = getCurrentEventObjsList(sport_type: self.sport_type)

VStack {
ScrollView(.vertical) {
VStack {
LazyVGrid(columns: gridItems, spacing: 10) {
ForEach(Array(current_event_objs.keys), id: \.self) { event_id in
let this_event = current_event_objs[event_id]
EventView(event: this_event!)
}
}
}.padding(5).frame(minWidth: 0, maxWidth: .greatestFiniteMagnitude, minHeight: 0, maxHeight: .greatestFiniteMagnitude)
EventGridView(event_list: current_event_objs)
}.padding(.top, 5).padding(.bottom, 5).padding(.leading).padding(.trailing).frame(minWidth: 0, maxWidth: .greatestFiniteMagnitude, minHeight: 0, maxHeight: .greatestFiniteMagnitude)
}
}.frame(width: 600, height: 700)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// EventGridView.swift
// personal-scoreboard
//
// Created by Sajan Gutta on 1/9/21.
//

import SwiftUI

struct EventGridView: View {
var event_list: Dictionary<String, Event>

var body: some View {
let rows = self.getRows()
VStack (alignment: .leading) {
ForEach(rows, id: \.self) { event_ids in
let left_id = event_ids[0]
HStack () {
if event_ids.count == 2 {
let right_id = event_ids [1]
EventView(event: event_list[left_id]!)
EventView(event: event_list[right_id]!)
} else if event_ids.count == 1 {
EventView(event: event_list[left_id]!)
Spacer()
}
}
}
}
}

func getRows() -> [[String]] {
var result: [[String]] = [[String]]()
if event_list.count == 0 {
return result
}
for index in 0...event_list.count - 1 {
if index % 2 == 0 {
let this_key = Array(event_list.keys)[index]
if index == event_list.count - 1{
result.append([this_key])
} else {
let next_key = Array(event_list.keys)[index + 1]
result.append([this_key, next_key])
}
}
}
return result
}
}

struct EventGridView_Previews: PreviewProvider {
static var previews: some View {
let lions = Team(full_name: "Detroit Lions", logo_url: "https://a.espncdn.com/i/teamlogos/nfl/500/det.png")
let rams = Team(full_name: "Los Angeles Rams", logo_url: "https://a.espncdn.com/i/teamlogos/nfl/500/lar.png")

let nfl_event = Event(id: "1", away_team: lions, home_team: rams, sport_type: SportType.nfl, away_score: "7", home_score: "10", status: "IN PROGRESS", status_string: "Q4 | 10:45", yardage_string: "4th and 5 at DET 35", possession: "AWAY")

let events = ["1": nfl_event, "2": nfl_event, "3": nfl_event]
EventGridView(event_list: events)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ struct EventView: View {
VStack {
let espn_url = self.event.espn_url
HStack {
Link(destination: URL(string: espn_url)!) {
Image(systemName: "link.circle.fill").foregroundColor(.blue)
}.padding(.leading, 5)
if #available(OSX 11.0, *) {
Link(destination: URL(string: espn_url)!) {
Image(systemName: "link.circle.fill").foregroundColor(.blue)
}.padding(.leading, 5)
} else {
// Fallback on earlier versions
}
Text(self.event.status_string)
Spacer()
Text(self.event.yardage_string).padding(.trailing)
Expand Down

0 comments on commit 3136076

Please sign in to comment.