Skip to content

Commit 556ccfe

Browse files
committed
fix: disable drawing on app hide
1 parent 711908a commit 556ccfe

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/onyxsdk_pen/android/src/main/kotlin/com/example/onyxsdk_pen/OnyxsdkPenArea.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,15 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
231231
val params = call.arguments<Map<String, Any>?>()
232232
updateStroke(params)
233233
result.success(null)
234+
} else if (call.method == "setDraw") {
235+
val param = call.arguments<Boolean>()
236+
touchHelper.setRawDrawingEnabled(param!!)
237+
result.success(null)
234238
} else {
235239
result.notImplemented()
236240
}
237241
}
238-
242+
239243
override fun dispose() {
240244
touchHelper.closeRawDrawing()
241245
}

packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart

+20-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class OnyxSdkPenArea extends StatefulWidget {
4444
}
4545
}
4646

47-
class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> {
47+
class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> with WidgetsBindingObserver {
4848
static bool? _isOnyxDevice = (kIsWeb || !Platform.isAndroid) ? false : null;
4949
static Future<bool> _findIsOnyxDevice() async {
5050
if (_isOnyxDevice != null) return _isOnyxDevice!;
@@ -91,6 +91,25 @@ class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> {
9191
channel.invokeMethod('updateStroke', creationParams).catchError((e) {});
9292
}
9393

94+
@override
95+
void initState() {
96+
WidgetsBinding.instance.addObserver(this);
97+
super.initState();
98+
}
99+
100+
@override
101+
void didChangeAppLifecycleState(AppLifecycleState state) async {
102+
switch (state) {
103+
case AppLifecycleState.resumed:
104+
channel.invokeMethod('setDraw', true).catchError((e) {});
105+
break;
106+
case AppLifecycleState.paused:
107+
channel.invokeMethod('setDraw', false).catchError((e) {});
108+
break;
109+
default:
110+
}
111+
}
112+
94113
@override
95114
Widget build(BuildContext context) {
96115
if (!isOnyxDevice) return widget.child;

0 commit comments

Comments
 (0)