Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle ios native side touch input enable/disable feature #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class _MyAppState extends State<MyApp> {
double currentWidth = 1;
Color currentColor = Colors.black;
String base64Image = '';
bool isPencilKitEnabled = true;

@override
Widget build(BuildContext context) {
Expand All @@ -34,7 +35,7 @@ class _MyAppState extends State<MyApp> {
textButtonTheme: const TextButtonThemeData(
style: ButtonStyle(
visualDensity: VisualDensity.compact,
padding: MaterialStatePropertyAll(
padding: WidgetStatePropertyAll(
EdgeInsets.all(8),
),
),
Expand Down Expand Up @@ -64,6 +65,13 @@ class _MyAppState extends State<MyApp> {
icon: const Icon(Icons.refresh),
onPressed: () => controller.clear(),
),
Switch(
value: isPencilKitEnabled,
onChanged: (bool value) {
setState(() => isPencilKitEnabled = value);
controller.setPencilKitEnabled(isPencilKitEnabled);
},
),
],
),
body: Stack(
Expand Down
7 changes: 7 additions & 0 deletions ios/Classes/FLPencilKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/src/pencil_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class PencilKit extends StatefulWidget {
this.isRulerActive,
this.drawingPolicy,
this.isOpaque,
this.isPencilKitEnabled = true,
this.backgroundColor,
this.toolPickerVisibilityDidChange,
this.toolPickerIsRulerActiveDidChange,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -286,6 +289,9 @@ class PencilKitController {
});
}

Future<void> setPencilKitEnabled(bool enable) =>
_channel.invokeMethod('setPencilKitEnabled', enable);

/// Clear all drawing data
Future<void> clear() => _channel.invokeMethod('clear');

Expand Down