Warning, /network/kdeconnect-ios/KDE Connect/KDE Connect/Plugins and Plugin Views/RemoteInput/KeyboardInput.swift is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Han Young <hanyoung@protonmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import UIKit 0008 import SwiftUI 0009 import Introspect 0010 0011 extension View { 0012 public func introspectKeyboardListener(customize: @escaping (KeyboardListener) -> Void) -> some View { 0013 introspect(selector: TargetViewSelector.siblingContainingOrAncestorOrAncestorChild, customize: customize) 0014 } 0015 } 0016 0017 public class KeyboardListener: UIView, UIKeyInput { 0018 public var hasText: Bool { false } 0019 public override var canBecomeFirstResponder: Bool { true } 0020 0021 var onInsertText: (_ text: String) -> Void = { _ in } 0022 var onDeleteBackward: () -> Void = { } 0023 var onReturn: () -> Void = { } 0024 0025 public func insertText(_ text: String) { 0026 if text == "\n" { 0027 onReturn() 0028 } else { 0029 onInsertText(text) 0030 } 0031 } 0032 0033 public func deleteBackward() { 0034 onDeleteBackward() 0035 } 0036 } 0037 0038 // This naming is intentional to mimic a SwiftUI View 0039 // swiftlint:disable:next identifier_name 0040 func KeyboardListenerPlaceholderView(onInsertText: @escaping (String) -> Void = { _ in }, 0041 onDeleteBackward: @escaping () -> Void = {}, 0042 onReturn: @escaping () -> Void = {}) -> some View { 0043 return _KeyboardListenerPlaceholderView(onInsertText: onInsertText, 0044 onDeleteBackward: onDeleteBackward, 0045 onReturn: onReturn) 0046 .frame(width: 0, height: 0) 0047 } 0048 0049 fileprivate struct _KeyboardListenerPlaceholderView: UIViewRepresentable { 0050 typealias UIViewType = KeyboardListener 0051 let onInsertText: (String) -> Void 0052 let onDeleteBackward: () -> Void 0053 let onReturn: () -> Void 0054 0055 func makeUIView(context: Context) -> KeyboardListener { 0056 let view = KeyboardListener() 0057 view.onReturn = onReturn 0058 view.onInsertText = onInsertText 0059 view.onDeleteBackward = onDeleteBackward 0060 return view 0061 } 0062 0063 func updateUIView(_ uiView: KeyboardListener, context: Context) { 0064 // do nothing 0065 } 0066 }