Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
[infra_ui][keyboard] Change ios plugin to swift and impl ios-side impl
Jaylen Bianb257ca11d0a5
diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/Event/KeyboardEventHandler.swift b/app_flowy/packages/flowy_infra_ui/ios/Classes/Event/KeyboardEventHandler.swiftnew file mode 100644index 0000000000..6f7e1f4b25--- /dev/null+++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/Event/KeyboardEventHandler.swift@@ -0,0 +1,85 @@+//+// KeyboardEventHandler.swift+// flowy_infra_ui+//+// Created by Jaylen Bian on 7/17/21.+//++class KeyboardEventHandler: NSObject, FlutterStreamHandler {++ var isKeyboardShow: Bool = false+ var eventSink: FlutterEventSink?++ override init() {+ super.init()++ NotificationCenter.default.addObserver(+ self,+ selector: #selector(handleKeyboardWillShow),+ name: UIApplication.keyboardWillShowNotification,+ object: nil)+ NotificationCenter.default.addObserver(+ self,+ selector: #selector(handleKeyboardDidShow),+ name: UIApplication.keyboardDidShowNotification,+ object: nil)+ NotificationCenter.default.addObserver(+ self,+ selector: #selector(handleKeyboardWillHide),+ name: UIApplication.keyboardWillHideNotification,+ object: nil)+ NotificationCenter.default.addObserver(+ self,+ selector: #selector(handleKeyboardDidHide),+ name: UIApplication.keyboardDidHideNotification,+ object: nil)+ }++ func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {+ eventSink = events+ return nil+ }++ func onCancel(withArguments arguments: Any?) -> FlutterError? {+ eventSink = nil+ return nil+ }++ // MARK: Helper++ @objc+ private func handleKeyboardWillShow() {+ guard !isKeyboardShow else {+ return+ }+ isKeyboardShow = true+ eventSink?(NSNumber(booleanLiteral: true))+ }++ @objc+ private func handleKeyboardDidShow() {+ guard !isKeyboardShow else {+ return+ }+ isKeyboardShow = true+ eventSink?(NSNumber(booleanLiteral: true))+ }++ @objc+ private func handleKeyboardWillHide() {+ guard isKeyboardShow else {+ return+ }+ isKeyboardShow = false+ eventSink?(NSNumber(booleanLiteral: false))+ }++ @objc+ private func handleKeyboardDidHide() {+ guard isKeyboardShow else {+ return+ }+ isKeyboardShow = false+ eventSink?(NSNumber(booleanLiteral: false))+ }+}diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift b/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swiftindex 5459739470..f8e62efe14 100644--- a/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift+++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift@@ -2,13 +2,33 @@ import Flutterimport UIKitpublic class SwiftFlowyInfraUiPlugin: NSObject, FlutterPlugin {- public static func register(with registrar: FlutterPluginRegistrar) {- let channel = FlutterMethodChannel(name: "flowy_infra_ui", binaryMessenger: registrar.messenger())- let instance = SwiftFlowyInfraUiPlugin()- registrar.addMethodCallDelegate(instance, channel: channel)- }-- public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {- result("iOS " + UIDevice.current.systemVersion)- }++ enum Constant {+ static let infraUIMethodChannelName = "flowy_infra_ui_method"+ static let infraUIKeyboardEventChannelName = "flowy_infra_ui_event/keyboard"+ }++ public static func register(with registrar: FlutterPluginRegistrar) {+ let instance = SwiftFlowyInfraUiPlugin()++ let methodChannel = FlutterMethodChannel(+ name: Constant.infraUIMethodChannelName,+ binaryMessenger: registrar.messenger())+ registrar.addMethodCallDelegate(instance, channel: methodChannel)++ let keyboardEventChannel = FlutterEventChannel(+ name: Constant.infraUIKeyboardEventChannelName,+ binaryMessenger: registrar.messenger())+ keyboardEventChannel.setStreamHandler(KeyboardEventHandler())+ }++ // MARK: - Method Channel++ public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {+ switch call.method {+ default:+ assertionFailure("Unsupported method \(call.method)")+ }+ }+}