From ee0d1633f2facf7c5d69e8615a8e0d1fbafc199d Mon Sep 17 00:00:00 2001 From: frybitsinc Date: Fri, 16 Aug 2024 15:52:10 +0900 Subject: [PATCH 1/2] feat: add PencilKit interaction on/off toggle feature --- ios/Classes/FLPencilKit.swift | 7 +++++++ lib/src/pencil_kit.dart | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ios/Classes/FLPencilKit.swift b/ios/Classes/FLPencilKit.swift index 00ca976..9f38215 100644 --- a/ios/Classes/FLPencilKit.swift +++ b/ios/Classes/FLPencilKit.swift @@ -78,6 +78,9 @@ class FLPencilKit: NSObject, FlutterPlatformView { case "setPKTool": pencilKitView.setPKTool(properties: call.arguments as! [String: Any]) result(nil) + case "setPencilKitEnabled": + pencilKitView.setPencilKitEnabled(enabled:call.arguments as! Bool) + result(nil) case "save": save(pencilKitView: pencilKitView, call: call, result: result) case "load": @@ -270,6 +273,10 @@ private class PencilKitView: UIView { canvasView.resignFirstResponder() } + func setPencilKitEnabled(enabled: Bool) { + canvasView.isUserInteractionEnabled = enabled + } + func setPKTool(properties: [String: Any]) { // toolType let inputToolType = properties["toolType"] as! String diff --git a/lib/src/pencil_kit.dart b/lib/src/pencil_kit.dart index 5367e75..df3408b 100644 --- a/lib/src/pencil_kit.dart +++ b/lib/src/pencil_kit.dart @@ -78,6 +78,7 @@ class PencilKit extends StatefulWidget { this.isRulerActive, this.drawingPolicy, this.isOpaque, + this.isPencilKitEnabled = true, this.backgroundColor, this.toolPickerVisibilityDidChange, this.toolPickerIsRulerActiveDidChange, @@ -118,6 +119,8 @@ class PencilKit extends StatefulWidget { /// You should always set the value of this property to false if the view is fully or partially transparent. final bool? isOpaque; + final bool? isPencilKitEnabled; + /// The view’s background color. The default is transparent final Color? backgroundColor; @@ -286,6 +289,9 @@ class PencilKitController { }); } + Future setPencilKitEnabled(bool enable) => + _channel.invokeMethod('setPencilKitEnabled', enable); + /// Clear all drawing data Future clear() => _channel.invokeMethod('clear'); From 7fc0d383dee014328d7f31c1f0b80610691c3020 Mon Sep 17 00:00:00 2001 From: frybitsinc Date: Fri, 16 Aug 2024 15:52:53 +0900 Subject: [PATCH 2/2] feat: update example --- example/lib/main.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index cb5bc3a..91ef256 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -26,6 +26,7 @@ class _MyAppState extends State { double currentWidth = 1; Color currentColor = Colors.black; String base64Image = ''; + bool isPencilKitEnabled = true; @override Widget build(BuildContext context) { @@ -34,7 +35,7 @@ class _MyAppState extends State { textButtonTheme: const TextButtonThemeData( style: ButtonStyle( visualDensity: VisualDensity.compact, - padding: MaterialStatePropertyAll( + padding: WidgetStatePropertyAll( EdgeInsets.all(8), ), ), @@ -64,6 +65,13 @@ class _MyAppState extends State { icon: const Icon(Icons.refresh), onPressed: () => controller.clear(), ), + Switch( + value: isPencilKitEnabled, + onChanged: (bool value) { + setState(() => isPencilKitEnabled = value); + controller.setPencilKitEnabled(isPencilKitEnabled); + }, + ), ], ), body: Stack(