wip
This commit is contained in:
parent
00e8349df0
commit
fcea0a249f
|
@ -1,5 +1,4 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SwiftUIIntrospect
|
|
||||||
|
|
||||||
#if os(iOS) || os(tvOS)
|
#if os(iOS) || os(tvOS)
|
||||||
@UIApplicationMain
|
@UIApplicationMain
|
||||||
|
@ -9,7 +8,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
window = UIWindow(frame: UIScreen.main.bounds)
|
window = UIWindow(frame: UIScreen.main.bounds)
|
||||||
window?.rootViewController = UIHostingController(rootView: AppView())
|
window?.rootViewController = UIHostingController(rootView: ContentView())
|
||||||
window?.makeKeyAndVisible()
|
window?.makeKeyAndVisible()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -19,220 +18,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
struct App: SwiftUI.App {
|
struct App: SwiftUI.App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
AppView()
|
ContentView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct AppView: View {
|
|
||||||
var body: some View {
|
|
||||||
NavigationView {
|
|
||||||
Form {
|
|
||||||
TextField("Text", text: .constant("Hello"))
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = .red
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = .red
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
.brightness(0.1) // <- this causes introspection to fail
|
|
||||||
Something()
|
|
||||||
}
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.list, on: .iOS(.v13, .v14, .v15), .tvOS(.v13, .v14, .v15, .v16)) { view in
|
|
||||||
view.backgroundColor = .purple
|
|
||||||
}
|
|
||||||
.introspect(.list, on: .iOS(.v16)) { view in
|
|
||||||
view.backgroundColor = .purple
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
#endif
|
|
||||||
#if os(iOS)
|
|
||||||
.navigationBarTitle(Text(""), displayMode: .inline)
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if os(iOS)
|
|
||||||
.navigationViewStyle(.stack)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VStack {
|
|
||||||
TextField("Name", text: .constant(""))
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.clearButtonMode = .whileEditing
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
// textField.clearButtonMode = .whileEditing
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
.clipped()
|
|
||||||
|
|
||||||
ExampleView()
|
|
||||||
|
|
||||||
VStack {
|
|
||||||
TextField("textField1Placeholder", text: .constant(""))
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = .orange
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = .orange
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
.cornerRadius(8)
|
|
||||||
TextField("textField2Placeholder", text: .constant(""))
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = .brown
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = .brown
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
.cornerRadius(8)
|
|
||||||
TextField("textField3Placeholder", text: .constant(""))
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = .gray
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = .gray
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
.cornerRadius(8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SecureToggle: ViewModifier {
|
|
||||||
|
|
||||||
@Binding public var isSecure: Bool
|
|
||||||
|
|
||||||
public func body(content: Content) -> some View {
|
|
||||||
|
|
||||||
HStack {
|
|
||||||
content
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.isSecureTextEntry = isSecure
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
// textField.clearButtonMode = .whileEditing
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
|
|
||||||
Button(action: {
|
|
||||||
self.isSecure.toggle()
|
|
||||||
}) {
|
|
||||||
Image(systemName: isSecure ? "eye.slash":"eye").frame(width: 20, height: 20)
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ExampleView: View {
|
|
||||||
@State private var text: String = ""
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
TextField("title", text: $text)
|
|
||||||
.foregroundColor(text.isEmpty ? .red : .blue)
|
|
||||||
.accentColor(text.isEmpty ? .red : .blue)
|
|
||||||
.padding(.all, 5)
|
|
||||||
.background(text.isEmpty ? Color.red.opacity(0.1) : Color.blue.opacity(0.1))
|
|
||||||
.cornerRadius(5)
|
|
||||||
.fixedSize(horizontal: true, vertical: false)
|
|
||||||
#if os(iOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
if #available(iOS 14, *) {
|
|
||||||
textField.attributedPlaceholder = NSAttributedString(
|
|
||||||
string: "placeholder",
|
|
||||||
attributes: [NSAttributedString.Key.foregroundColor: UIColor(Color.red)]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if canImport(UIKit)
|
|
||||||
typealias PlatformColor = UIColor
|
|
||||||
#elseif canImport(AppKit)
|
|
||||||
typealias PlatformColor = NSColor
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct Something: View {
|
|
||||||
@State var color = PlatformColor.green
|
|
||||||
@State var text = "s"
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
// NavigationView {
|
|
||||||
// List {
|
|
||||||
HStack {
|
|
||||||
Picker("Color", selection: $color) {
|
|
||||||
Text("Red").tag(PlatformColor.red)
|
|
||||||
Text("Green").tag(PlatformColor.green)
|
|
||||||
Text("Blue").tag(PlatformColor.blue)
|
|
||||||
}
|
|
||||||
.fixedSize()
|
|
||||||
|
|
||||||
TextField("dynamic", text: .constant(""))
|
|
||||||
// .frame(width: 50)
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = color
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = color
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
TextField("red", text: .constant(""))
|
|
||||||
// .frame(width: 50)
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = .red
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = .red
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
TextField("yellow", text: .constant(""))
|
|
||||||
// .frame(width: 50)
|
|
||||||
#if os(iOS) || os(tvOS)
|
|
||||||
.introspect(.textField, on: .iOS(.v13, .v14, .v15, .v16), .tvOS(.v13, .v14, .v15, .v16)) { textField in
|
|
||||||
textField.backgroundColor = .yellow
|
|
||||||
}
|
|
||||||
#elseif os(macOS)
|
|
||||||
.introspect(.textField, on: .macOS(.v13)) { textField in
|
|
||||||
textField.backgroundColor = .yellow
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
// TextField("dq", text: $text)
|
|
||||||
// .background(Color.green)
|
|
||||||
// .introspect(.textField, on: .iOS(.v14, .v15, .v16), observing: color) { textField, color in
|
|
||||||
// textField.backgroundColor = UIColor(color)
|
|
||||||
// }
|
|
||||||
// .introspect(.textField, on: .iOS14, .iOS15, .iOS16, observing: color) {
|
|
||||||
// textField.backgroundColor = UIColor(color)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue