Skip to content

Instantly share code, notes, and snippets.

@edudnyk
edudnyk / PagingView-example.swift
Last active October 20, 2021 20:59
An example of usage of the PagingView in SwiftUI
struct PagingContentView: View {
@State var currentPage: Int = 0
let config: PagingViewConfig
init() {
var config = PagingViewConfig()
config.direction = .horizontal
config.size = 100
config.margin = 0
config.spacing = 0
@edudnyk
edudnyk / _ScrollViewProxy.swift
Created October 20, 2021 20:47
The public interface of the hidden _ScrollViewProxy type in SwiftUI.
public struct _ScrollViewProxy : Equatable {
public var config: _ScrollViewConfig { get }
public var contentOffset: CGPoint { get set }
public var minContentOffset: CGPoint { get }
public var maxContentOffset: CGPoint { get }
public var contentSize: CGSize { get }
public var pageSize: CGSize { get }
public var visibleRect: CGRect { get }
public var isDragging: Bool { get }
public var isDecelerating: Bool { get }
@edudnyk
edudnyk / SolidScrollView-example.swift
Last active October 20, 2021 20:57
An example of usage of the SolidScrollView in SwiftUI
struct ContentView: View {
var config = ScrollViewConfig()
@State var scrollViewProxy: SolidScrollViewProxy?
var body: some View {
VStack(spacing: 0) {
SolidScrollView(config) {
VStack(spacing: 0) {
Color.red.frame(height: 200)
Color.green.frame(height: 200)
@edudnyk
edudnyk / SheeTestCase.swift
Created October 7, 2021 23:50
Commented preview test case in SheeKit
// func test() {
// viewTest?.loop()
// }
@edudnyk
edudnyk / SheeTestCase.swift
Last active October 7, 2021 23:53
ChangedThrice / DismissedOnce test case in SheeKit
final class SheeTestCase: ViewTestCase {
...
func testItemChangedThriceDismissedOnce() {
guard let viewTest = viewTest else {
XCTFail("No view to test.")
return
}
let bounds = UIScreen.main.bounds
@edudnyk
edudnyk / SheeTestCase.swift
Last active October 7, 2021 23:56
ChangedThrice / DismissedTwice test case in SheeKit
final class SheeTestCase: ViewTestCase {
...
func testItemChangedThriceDismissedTwice() {
guard let viewTest = viewTest else {
XCTFail("No view to test.")
return
}
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension SwiftUI._ViewTest {
public typealias Touch = (location: CoreGraphics.CGPoint, globalLocation: CoreGraphics.CGPoint?, timestamp: Foundation.Date)
public func sendTouchSequence(_ touches: [Self.Touch])
...
}
final class SheeTestCase: ViewTestCase {
var dismissCounter: Int = 0
@ViewBuilder
override func initRootView() -> AnyView {
AnyView(ShowPartDetail { [weak self] in
guard let self = self else { return }
self.dismissCounter += 1
})
}
@edudnyk
edudnyk / View-SheeTestCase.swift
Last active October 7, 2021 23:14
The view for testing with _ViewTest.
import SwiftUI
@testable import SheeKit
import XCTest
enum ID: String {
case showPartDetailButton
case changePartDetailButton
}
struct ShowPartDetail: View {
@edudnyk
edudnyk / ViewTestCase.swift
Last active March 5, 2024 06:39
Utils for _ViewTest
import SwiftUI
import XCTest
extension UIHostingController: _Test where Content == AnyView {}
extension UIHostingController: _ViewTest where Content == AnyView {
public func initRootView() -> AnyView {
return rootView
}
public func initSize() -> CGSize {
sizeThatFits(in: UIScreen.main.bounds.size)