This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class NetworkClient { | |
private let session: URLSession = .shared | |
public init() { } | |
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) { | |
session.dataTask(with: request) { (data, _, error) in | |
if let error = error { | |
completion(.failure(error)) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.simultaneousGesture(DragGesture().onChanged({value in | |
/// catch moving to category | |
if self.allowSubCategoryDragging { | |
let movingCategoryRight = self.page == 0 && self.nestedPages[self.page] == 2 && value.translation.width < 0 | |
let movingCategoryLeft = self.page == 1 && self.nestedPages[self.page] == 0 && value.translation.width > 0 | |
if movingCategoryRight || movingCategoryLeft{ | |
self.allowSubCategoryDragging = false | |
} | |
else{ | |
let westAsCanBe = self.nestedPages[self.page] == 0 && self.page == 0 && value.translation.width > 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.onPageChanged({ _ in | |
self.allowSubCategoryDragging = true | |
}) | |
.swipeInteractionArea(.allAvailable) | |
.simultaneousGesture(DragGesture().onChanged({value in | |
/// catch moving to category | |
if self.allowSubCategoryDragging { | |
let movingCategoryRight = self.page == 0 && self.nestedPages[self.page] == 2 && value.translation.width < 0 | |
let movingCategoryLeft = self.page == 1 && self.nestedPages[self.page] == 0 && value.translation.width > 0 | |
if movingCategoryRight || movingCategoryLeft{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct YourLibraryView: View { | |
@State var page: Int = 0 //// keeps track of which category index we are at | |
@State var nestedPages: [Int] = [0, 0] /// keeps track of which sub category index we are at for each category | |
@State var indicatorOffsets : [CGFloat] = [0,0] /// keepts track of indicator offsets for each category | |
var data = Array(0..<2) | |
var nestedData = Array(0..<3) | |
var body: some View { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MediaContentView: View { | |
var colours : [Color] = [.red, .orange, .green, .pink, .purple, .yellow] | |
var body: some View { | |
ScrollView(.vertical, showsIndicators: true){ | |
ForEach(0..<10) {_ in | |
HStack{ | |
Rectangle() | |
.frame(width: UIScreen.main.bounds.size.width/6 , height: UIScreen.main.bounds.size.height/12) | |
.foregroundColor(self.colours[Int.random(in: 0 ... 5 )]) | |
VStack(alignment: .leading){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SubCategoryText: View { | |
var subCategorys : [String] | |
@Binding var currentSubCategoryIndex : Int | |
@Binding var indicatorOffset : CGFloat | |
var body: some View { | |
HStack{ | |
subCategory(index: 0, parent: self) | |
subCategory(index: 1, parent: self) | |
subCategory(index: 2, parent: self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CategoryText: View { | |
@Binding var currentCategoryIndex : Int | |
@Binding var nestedPages : [Int] | |
var body: some View { | |
HStack(spacing: 20){ | |
Text("Music") | |
.font(.largeTitle).bold() | |
.foregroundColor(self.currentCategoryIndex == 0 ? .primary : .secondary) | |
.onTapGesture { | |
self.nestedPages = [0,0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State var alertItem : AlertItem? | |
var body: some View { | |
/// button | |
Button(action: { | |
self.alertItem = AlertItem(title: Text("I'm an alert"), message: Text("Are you sure about this?"), primaryButton: .default(Text("Yes"), action: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State var alertItem : AlertItem? | |
var body: some View { | |
VStack{ | |
/// button 1 | |
Button(action: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AlertItem: Identifiable { | |
var id = UUID() | |
var title = Text("") | |
var message: Text? | |
var dismissButton: Alert.Button? | |
var primaryButton: Alert.Button? | |
var secondaryButton: Alert.Button? | |
} |