This file contains 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 BackgroundGradientView: View { | |
let color: Color | |
var body: some View { | |
ZStack { | |
Color.black | |
.ignoresSafeArea() | |
LinearGradient( | |
gradient: Gradient( | |
colors: [ |
This file contains 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
protocol Loggable { | |
init(filename: String) | |
func log() | |
} | |
class Logger: Loggable { | |
private var filename = "" | |
// Required is needed for subclass conforming protocol too. | |
// Unless class is marked as final |
This file contains 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
protocol Player { | |
var name: String { get set } | |
var score: Int { get } | |
var nickname: String { get } | |
static var numberOfPlayers: Int { get set } | |
} | |
struct SoccerPlayer: Player { | |
var name: String |
This file contains 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
// Call this in the cell, for example CellView().noSeparators() | |
extension View { | |
@ViewBuilder public func noSeparators( | |
edgeInsets: EdgeInsets = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0), | |
color: Color | |
) -> some View { | |
self | |
.padding(edgeInsets) | |
.frame( | |
minWidth: 0, |
This file contains 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
import SwiftUI | |
protocol TXTabBarElementView: View { | |
associatedtype Content | |
var content: Content { get set } | |
var item: TXTabItem.Item { get set } | |
} | |
public struct TXTabItem: TXTabBarElementView { |
This file contains 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 TestPaginationView: View { | |
//1 | |
@ObservedObject var viewModel = ItemListViewModel() | |
var body: some View { | |
NavigationView { | |
//2 | |
ListPagination(items: viewModel.items, offset: 8, pagination: viewModel.getData) { item in | |
//3 | |
Text("Item #\(item)") |
This file contains 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
//1 | |
class ItemListViewModel: ObservableObject { | |
//2 | |
@Published var items: [Int] = [] | |
//3 | |
static private var itemsPerPage = 25 | |
private var start = -ItemListViewModel.itemsPerPage | |
private var stop = -1 | |
private let maxData = 250 |
This file contains 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
import SwiftUI | |
public struct SpinnerView: UIViewRepresentable { | |
public typealias UIViewType = UIActivityIndicatorView | |
public init(isAnimating: Binding<Bool>, style: UIActivityIndicatorView.Style) { | |
self._isAnimating = isAnimating | |
self.style = style | |
} | |
This file contains 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
private func isLastItem(index: Int) -> Bool { | |
index == (items.count - 1) | |
} | |
private func isOffsetReached(at index: Int) -> Bool { | |
index == (items.count - offset) | |
} | |
private func itemAppears(at index: Int) { | |
if isOffsetReached(at: index) { |
This file contains 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
var pagination: ((() -> Void)?) -> Void | |
@State var isLoading = false | |
private var offset: Int |