summaryrefslogtreecommitdiff
path: root/macos/Sources/Helpers/CrossKit.swift
blob: 690e811bb524954eb49e246486a1c38d61ee07a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// This file is a helper to bridge some types that are effectively identical
// between AppKit and UIKit.

import SwiftUI

#if canImport(AppKit)

import AppKit

typealias OSView = NSView
typealias OSColor = NSColor
typealias OSSize = NSSize
typealias OSPasteboard = NSPasteboard

protocol OSViewRepresentable: NSViewRepresentable where NSViewType == OSViewType {
    associatedtype OSViewType: NSView
    func makeOSView(context: Context) -> OSViewType
    func updateOSView(_ osView: OSViewType, context: Context)
}

extension OSViewRepresentable {
    func makeNSView(context: Context) -> OSViewType {
        makeOSView(context: context)
    }

    func updateNSView(_ nsView: OSViewType, context: Context) {
        updateOSView(nsView, context: context)
    }
}

#elseif canImport(UIKit)

import UIKit

typealias OSView = UIView
typealias OSColor = UIColor
typealias OSSize = CGSize
typealias OSPasteboard = UIPasteboard

protocol OSViewRepresentable: UIViewRepresentable {
    associatedtype OSViewType: UIView
    func makeOSView(context: Context) -> OSViewType
    func updateOSView(_ osView: OSViewType, context: Context)
}

extension OSViewRepresentable {
    func makeUIView(context: Context) -> OSViewType {
        makeOSView(context: context)
    }

    func updateUIView(_ uiView: OSViewType, context: Context) {
        updateOSView(uiView, context: context)
    }
}

#endif