diff --git a/app_flowy/packages/flowy_infra_ui/android/src/main/java/com/example/flowy_infra_ui/FlowyInfraUiPlugin.java b/app_flowy/packages/flowy_infra_ui/android/src/main/java/com/example/flowy_infra_ui/FlowyInfraUiPlugin.java index 62270ab6ef..e93c990e62 100644 --- a/app_flowy/packages/flowy_infra_ui/android/src/main/java/com/example/flowy_infra_ui/FlowyInfraUiPlugin.java +++ b/app_flowy/packages/flowy_infra_ui/android/src/main/java/com/example/flowy_infra_ui/FlowyInfraUiPlugin.java @@ -15,8 +15,8 @@ import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -/** FlowyInfraUiPlugin */ -public class FlowyInfraUiPlugin implements FlutterPlugin, ActivityAware, MethodCallHandler { +/** FlowyInfraUIPlugin */ +public class FlowyInfraUIPlugin implements FlutterPlugin, ActivityAware, MethodCallHandler { // MARK: - Constant public static final String INFRA_UI_METHOD_CHANNEL_NAME = "flowy_infra_ui_method"; diff --git a/app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt b/app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt new file mode 100644 index 0000000000..5d98dd8f10 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/android/src/main/kotlin/com/example/flowy_infra_ui/FlowyInfraUiPlugin.kt @@ -0,0 +1,35 @@ +package com.example.flowy_infra_ui + +import androidx.annotation.NonNull + +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result + +/** FlowyInfraUiPlugin */ +class FlowyInfraUiPlugin: FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private lateinit var channel : MethodChannel + + override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flowy_infra_ui") + channel.setMethodCallHandler(this) + } + + override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { + if (call.method == "getPlatformVersion") { + result.success("Android ${android.os.Build.VERSION.RELEASE}") + } else { + result.notImplemented() + } + } + + override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + } +} diff --git a/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/kotlin/com/example/flowy_infra_ui_example/MainActivity.kt b/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/kotlin/com/example/flowy_infra_ui_example/MainActivity.kt new file mode 100644 index 0000000000..6c4bb00d45 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/example/android/app/src/main/kotlin/com/example/flowy_infra_ui_example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.example.flowy_infra_ui_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock b/app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock deleted file mode 100644 index c5a50f2dc9..0000000000 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Podfile.lock +++ /dev/null @@ -1,22 +0,0 @@ -PODS: - - flowy_infra_ui (0.0.1): - - Flutter - - Flutter (1.0.0) - -DEPENDENCIES: - - flowy_infra_ui (from `.symlinks/plugins/flowy_infra_ui/ios`) - - Flutter (from `Flutter`) - -EXTERNAL SOURCES: - flowy_infra_ui: - :path: ".symlinks/plugins/flowy_infra_ui/ios" - Flutter: - :path: Flutter - -SPEC CHECKSUMS: - flowy_infra_ui: 146c88346fd55d2ee6a41ae35059a5bf095cfbb3 - Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c - -PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c - -COCOAPODS: 1.9.3 diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj index eb8f7f7e87..6eb94532cf 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 73D88840D6ADB1B9C000C539 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA749E34E8D549849F119B5B /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -33,7 +32,6 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3CA8F348EBCAB0B9417EC70D /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -44,9 +42,6 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - BD462F555277405D97D69F24 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; - C010FCE60C748638851A2DFA /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; - CA749E34E8D549849F119B5B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,32 +49,12 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 73D88840D6ADB1B9C000C539 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 2A04BAC54BC6D85A998F0000 /* Frameworks */ = { - isa = PBXGroup; - children = ( - CA749E34E8D549849F119B5B /* Pods_Runner.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - 8F8024933033E730415889FC /* Pods */ = { - isa = PBXGroup; - children = ( - C010FCE60C748638851A2DFA /* Pods-Runner.debug.xcconfig */, - BD462F555277405D97D69F24 /* Pods-Runner.release.xcconfig */, - 3CA8F348EBCAB0B9417EC70D /* Pods-Runner.profile.xcconfig */, - ); - name = Pods; - path = Pods; - sourceTree = ""; - }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( @@ -97,8 +72,6 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - 8F8024933033E730415889FC /* Pods */, - 2A04BAC54BC6D85A998F0000 /* Frameworks */, ); sourceTree = ""; }; @@ -132,14 +105,12 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 653DE1EFE700467C4AF71781 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - C71338FE5F010950C936DB01 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -212,28 +183,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; - 653DE1EFE700467C4AF71781 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -248,24 +197,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; - C71338FE5F010950C936DB01 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/flowy_infra_ui/flowy_infra_ui.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flowy_infra_ui.framework", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata index 21a3cc14c7..1d526a16ed 100644 --- a/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/app_flowy/packages/flowy_infra_ui/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,7 +4,4 @@ - - diff --git a/app_flowy/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart b/app_flowy/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart index c459f61668..dcd11fe0e2 100644 --- a/app_flowy/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart +++ b/app_flowy/packages/flowy_infra_ui/example/lib/keyboard/keyboard_screen.dart @@ -1,3 +1,4 @@ +import 'package:flowy_infra_ui/flowy_infra_ui_web.dart'; import 'package:flutter/material.dart'; import '../home/demo_item.dart'; @@ -25,21 +26,33 @@ class KeyboardScreen extends StatefulWidget { } class _KeyboardScreenState extends State { + bool _isKeyboardVisible = false; + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Keyboard Visibility Demo'), ), - body: GestureDetector( - onTap: () => _dismissKeyboard(context), - behavior: HitTestBehavior.translucent, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 36), - child: Center( - child: TextField( - style: const TextStyle(fontSize: 20), - controller: TextEditingController(text: 'Test'), + body: KeyboardVisibilityDetector( + onKeyboardVisibilityChange: (isKeyboardVisible) { + setState(() => _isKeyboardVisible = isKeyboardVisible); + }, + child: GestureDetector( + onTap: () => _dismissKeyboard(context), + behavior: HitTestBehavior.translucent, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 36), + child: Center( + child: Column( + children: [ + Text('Keyboard Visible: $_isKeyboardVisible'), + TextField( + style: const TextStyle(fontSize: 20), + controller: TextEditingController(text: 'Test'), + ), + ], + ), ), ), ), diff --git a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock index 7b3e7031d3..48fb2300d9 100644 --- a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock @@ -199,7 +199,7 @@ packages: source: hosted version: "2.0.1" provider: - dependency: "direct main" + dependency: transitive description: name: provider url: "https://pub.dartlang.org" diff --git a/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml b/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml index 09ad328ffb..4b3c5ac678 100644 --- a/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml +++ b/app_flowy/packages/flowy_infra_ui/example/pubspec.yaml @@ -13,8 +13,11 @@ dependencies: <<<<<<< HEAD ======= cupertino_icons: ^1.0.2 +<<<<<<< HEAD provider: ^5.0.0 >>>>>>> [infra_ui][keyboard] (WIP) Add demo proj for infra ui +======= +>>>>>>> [infra_ui] Integrate keyboard detector to example proj flowy_infra_ui: path: ../ diff --git a/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart b/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart index 198cf4618d..1550d94848 100644 --- a/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart +++ b/app_flowy/packages/flowy_infra_ui/example/test/widget_test.dart @@ -18,12 +18,7 @@ void main() { // Verify that platform version is retrieved. expect( find.byWidgetPredicate( -<<<<<<< HEAD - (Widget widget) => - widget is Text && widget.data!.startsWith('Running on:'), -======= (Widget widget) => widget is Text && widget.data!.startsWith('Running on:'), ->>>>>>> [infra_ui][keyboard] Bump infra_ui to 1.20.0 and fix compiling issues ), findsOneWidget, ); diff --git a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/lib/src/method_channel_flowy_infra_ui.dart b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/lib/src/method_channel_flowy_infra_ui.dart index 067636ad8b..ad8051f515 100644 --- a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/lib/src/method_channel_flowy_infra_ui.dart +++ b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_platform_interface/lib/src/method_channel_flowy_infra_ui.dart @@ -3,7 +3,7 @@ import 'package:flutter/services.dart'; import '../flowy_infra_ui_platform_interface.dart'; -// ignore: constant_identifier_names +// ignore_for_file: constant_identifier_names const INFRA_UI_METHOD_CHANNEL_NAME = 'flowy_infra_ui_method'; const INFRA_UI_KEYBOARD_EVENT_CHANNEL_NAME = 'flowy_infra_ui_event/keyboard'; const INFRA_UI_METHOD_GET_PLATFORM_VERSION = 'getPlatformVersion'; diff --git a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/lib/flowy_infra_ui_web.dart b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/lib/flowy_infra_ui_web.dart index 98a7864942..e3bd3a2fe0 100644 --- a/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/lib/flowy_infra_ui_web.dart +++ b/app_flowy/packages/flowy_infra_ui/flowy_infra_ui_web/lib/flowy_infra_ui_web.dart @@ -1,5 +1,6 @@ library flowy_infra_ui_web; +import 'dart:html' as html show window; import 'package:flowy_infra_ui_platform_interface/flowy_infra_ui_platform_interface.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; @@ -18,6 +19,7 @@ class FlowyInfraUIPlugin extends FlowyInfraUIPlatform { @override Future getPlatformVersion() async { - return 'Web: unknow version'; + final version = html.window.navigator.userAgent; + return Future.value(version); } } diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUIPlugin.h b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUIPlugin.h new file mode 100644 index 0000000000..51f5d35106 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUIPlugin.h @@ -0,0 +1,4 @@ +#import + +@interface FlowyInfraUIPlugin : NSObject +@end diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUIPlugin.m similarity index 78% rename from app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m rename to app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUIPlugin.m index 6609bdcf24..58f19ce516 100644 --- a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.m +++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUIPlugin.m @@ -1,4 +1,4 @@ -#import "FlowyInfraUiPlugin.h" +#import "FlowyInfraUIPlugin.h" #if __has_include() #import #else @@ -8,8 +8,8 @@ #import "flowy_infra_ui-Swift.h" #endif -@implementation FlowyInfraUiPlugin +@implementation FlowyInfraUIPlugin + (void)registerWithRegistrar:(NSObject*)registrar { - [SwiftFlowyInfraUiPlugin registerWithRegistrar:registrar]; + [SwiftFlowyInfraUIPlugin registerWithRegistrar:registrar]; } @end diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h b/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h deleted file mode 100644 index 9f353812ba..0000000000 --- a/app_flowy/packages/flowy_infra_ui/ios/Classes/FlowyInfraUiPlugin.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface FlowyInfraUiPlugin : NSObject -@end diff --git a/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift b/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUIPlugin.swift similarity index 91% rename from app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift rename to app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUIPlugin.swift index 39b9a47a04..641a0e53c2 100644 --- a/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUiPlugin.swift +++ b/app_flowy/packages/flowy_infra_ui/ios/Classes/SwiftFlowyInfraUIPlugin.swift @@ -1,7 +1,7 @@ import Flutter import UIKit -public class SwiftFlowyInfraUiPlugin: NSObject, FlutterPlugin { +public class SwiftFlowyInfraUIPlugin: NSObject, FlutterPlugin { enum Constant { static let infraUIMethodChannelName = "flowy_infra_ui_method" @@ -11,7 +11,7 @@ public class SwiftFlowyInfraUiPlugin: NSObject, FlutterPlugin { } public static func register(with registrar: FlutterPluginRegistrar) { - let instance = SwiftFlowyInfraUiPlugin() + let instance = SwiftFlowyInfraUIPlugin() let methodChannel = FlutterMethodChannel( name: Constant.infraUIMethodChannelName, diff --git a/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart index 2efe27d245..36a2148c07 100644 --- a/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart +++ b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui.dart @@ -1,13 +1,2 @@ - -import 'dart:async'; - -import 'package:flutter/services.dart'; - -class FlowyInfraUi { - static const MethodChannel _channel = MethodChannel('flowy_infra_ui'); - - static Future get platformVersion async { - final String? version = await _channel.invokeMethod('getPlatformVersion'); - return version; - } -} +// Keyboard +export 'src/keyboard/keyboard_visibility_detector.dart'; diff --git a/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart index f9d9035149..36a2148c07 100644 --- a/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart +++ b/app_flowy/packages/flowy_infra_ui/lib/flowy_infra_ui_web.dart @@ -1,44 +1,2 @@ -import 'dart:async'; -// In order to *not* need this ignore, consider extracting the "web" version -// of your plugin as a separate package, instead of inlining it in the same -// package as the core of your plugin. -// ignore: avoid_web_libraries_in_flutter -import 'dart:html' as html show window; - -import 'package:flutter/services.dart'; -import 'package:flutter_web_plugins/flutter_web_plugins.dart'; - -/// A web implementation of the FlowyInfraUi plugin. -class FlowyInfraUiWeb { - static void registerWith(Registrar registrar) { - final MethodChannel channel = MethodChannel( - 'flowy_infra_ui', - const StandardMethodCodec(), - registrar, - ); - - final pluginInstance = FlowyInfraUiWeb(); - channel.setMethodCallHandler(pluginInstance.handleMethodCall); - } - - /// Handles method calls over the MethodChannel of this plugin. - /// Note: Check the "federated" architecture for a new way of doing this: - /// https://flutter.dev/go/federated-plugins - Future handleMethodCall(MethodCall call) async { - switch (call.method) { - case 'getPlatformVersion': - return getPlatformVersion(); - default: - throw PlatformException( - code: 'Unimplemented', - details: 'flowy_infra_ui for web doesn\'t implement \'${call.method}\'', - ); - } - } - - /// Returns a [String] containing the version of the platform. - Future getPlatformVersion() { - final version = html.window.navigator.userAgent; - return Future.value(version); - } -} +// Keyboard +export 'src/keyboard/keyboard_visibility_detector.dart'; diff --git a/app_flowy/packages/flowy_infra_ui/lib/src/keyboard/keyboard_.dart b/app_flowy/packages/flowy_infra_ui/lib/src/keyboard/keyboard_.dart deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app_flowy/packages/flowy_infra_ui/lib/src/keyboard/keyboard_visibility_detector.dart b/app_flowy/packages/flowy_infra_ui/lib/src/keyboard/keyboard_visibility_detector.dart new file mode 100644 index 0000000000..7521435310 --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/lib/src/keyboard/keyboard_visibility_detector.dart @@ -0,0 +1,73 @@ +import 'dart:async'; + +import 'package:flowy_infra_ui_platform_interface/flowy_infra_ui_platform_interface.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class KeyboardVisibilityDetector extends StatefulWidget { + const KeyboardVisibilityDetector({ + Key? key, + required this.child, + this.onKeyboardVisibilityChange, + }) : super(key: key); + + final Widget child; + final void Function(bool)? onKeyboardVisibilityChange; + + static bool isKeyboardVisible(BuildContext context) { + return context.read<_KeyboardVisibilityDetectorInheritedWidget>().isKeyboardVisible; + } + + @override + _KeyboardVisibilityDetectorState createState() => _KeyboardVisibilityDetectorState(); +} + +class _KeyboardVisibilityDetectorState extends State { + FlowyInfraUIPlatform get _platform => FlowyInfraUIPlatform.instance; + + bool isObserving = false; + bool isKeyboardVisible = false; + late StreamSubscription _keyboardSubscription; + + @override + void initState() { + super.initState(); + _keyboardSubscription = _platform.onKeyboardVisibilityChange.listen((newValue) { + setState(() { + isKeyboardVisible = newValue; + if (widget.onKeyboardVisibilityChange != null) { + widget.onKeyboardVisibilityChange!(newValue); + } + }); + }); + } + + @override + void dispose() { + _keyboardSubscription.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return _KeyboardVisibilityDetectorInheritedWidget( + isKeyboardVisible: isKeyboardVisible, + child: widget.child, + ); + } +} + +class _KeyboardVisibilityDetectorInheritedWidget extends InheritedWidget { + const _KeyboardVisibilityDetectorInheritedWidget({ + Key? key, + required this.isKeyboardVisible, + required Widget child, + }) : super(key: key, child: child); + + final bool isKeyboardVisible; + + @override + bool updateShouldNotify(_KeyboardVisibilityDetectorInheritedWidget oldWidget) { + return isKeyboardVisible != oldWidget.isKeyboardVisible; + } +} diff --git a/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift b/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift index b0fcc26b21..a18610dede 100644 --- a/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift +++ b/app_flowy/packages/flowy_infra_ui/macos/Classes/FlowyInfraUiPlugin.swift @@ -1,10 +1,10 @@ import Cocoa import FlutterMacOS -public class FlowyInfraUiPlugin: NSObject, FlutterPlugin { +public class FlowyInfraUIPlugin: NSObject, FlutterPlugin { public static func register(with registrar: FlutterPluginRegistrar) { let channel = FlutterMethodChannel(name: "flowy_infra_ui", binaryMessenger: registrar.messenger) - let instance = FlowyInfraUiPlugin() + let instance = FlowyInfraUIPlugin() registrar.addMethodCallDelegate(instance, channel: channel) } diff --git a/app_flowy/packages/flowy_infra_ui/platform_interface/keyboard_web/lib/keyboard_web.dart b/app_flowy/packages/flowy_infra_ui/platform_interface/keyboard_web/lib/keyboard_web.dart new file mode 100644 index 0000000000..30e6eabb1d --- /dev/null +++ b/app_flowy/packages/flowy_infra_ui/platform_interface/keyboard_web/lib/keyboard_web.dart @@ -0,0 +1,16 @@ +library keyboard_web; + +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'package:keyboard_platform_interface/keyboard_platform_interface.dart'; + +class KeyboardPlugin extends KeyboardPlatform { + static void registerWith(Registrar registrar) { + KeyboardPlatform.instance = KeyboardPlugin(); + } + + @override + Stream get onKeyboardChange async* { + // suppose that keyboard won't show in web side + yield false; + } +} diff --git a/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp b/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp index f4329eacf4..4de31d554f 100644 --- a/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp +++ b/app_flowy/packages/flowy_infra_ui/windows/flowy_infra_ui_plugin.cpp @@ -16,13 +16,13 @@ namespace { -class FlowyInfraUiPlugin : public flutter::Plugin { +class FlowyInfraUIPlugin : public flutter::Plugin { public: static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); - FlowyInfraUiPlugin(); + FlowyInfraUIPlugin(); - virtual ~FlowyInfraUiPlugin(); + virtual ~FlowyInfraUIPlugin(); private: // Called when a method is called on this plugin's channel from Dart. @@ -32,14 +32,14 @@ class FlowyInfraUiPlugin : public flutter::Plugin { }; // static -void FlowyInfraUiPlugin::RegisterWithRegistrar( +void FlowyInfraUIPlugin::RegisterWithRegistrar( flutter::PluginRegistrarWindows *registrar) { auto channel = std::make_unique>( registrar->messenger(), "flowy_infra_ui", &flutter::StandardMethodCodec::GetInstance()); - auto plugin = std::make_unique(); + auto plugin = std::make_unique(); channel->SetMethodCallHandler( [plugin_pointer = plugin.get()](const auto &call, auto result) { @@ -49,11 +49,11 @@ void FlowyInfraUiPlugin::RegisterWithRegistrar( registrar->AddPlugin(std::move(plugin)); } -FlowyInfraUiPlugin::FlowyInfraUiPlugin() {} +FlowyInfraUIPlugin::FlowyInfraUIPlugin() {} -FlowyInfraUiPlugin::~FlowyInfraUiPlugin() {} +FlowyInfraUIPlugin::~FlowyInfraUIPlugin() {} -void FlowyInfraUiPlugin::HandleMethodCall( +void FlowyInfraUIPlugin::HandleMethodCall( const flutter::MethodCall &method_call, std::unique_ptr> result) { if (method_call.method_name().compare("getPlatformVersion") == 0) { @@ -74,9 +74,9 @@ void FlowyInfraUiPlugin::HandleMethodCall( } // namespace -void FlowyInfraUiPluginRegisterWithRegistrar( +void FlowyInfraUIPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { - FlowyInfraUiPlugin::RegisterWithRegistrar( + FlowyInfraUIPlugin::RegisterWithRegistrar( flutter::PluginRegistrarManager::GetInstance() ->GetRegistrar(registrar)); } diff --git a/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h b/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h index cdd90185ab..475039941f 100644 --- a/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h +++ b/app_flowy/packages/flowy_infra_ui/windows/include/flowy_infra_ui/flowy_infra_ui_plugin.h @@ -13,7 +13,7 @@ extern "C" { #endif -FLUTTER_PLUGIN_EXPORT void FlowyInfraUiPluginRegisterWithRegistrar( +FLUTTER_PLUGIN_EXPORT void FlowyInfraUIPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar); #if defined(__cplusplus)