Skip to content

Commit 51bf067

Browse files
committed
Fix focusable bug
1 parent 15b9ede commit 51bf067

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

android/src/main/kotlin/qiuxiang/android_window/AndroidWindow.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.math.roundToInt
1515

1616
class AndroidWindow(
1717
val service: Service,
18-
focusable: Boolean,
18+
private val focusable: Boolean,
1919
width: Int,
2020
height: Int,
2121
private val x: Int,
@@ -76,8 +76,10 @@ class AndroidWindow(
7676
}
7777
}
7878
MotionEvent.ACTION_DOWN -> {
79-
layoutParams.flags = layoutParams.flags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE.inv()
80-
windowManager.updateViewLayout(rootView, layoutParams)
79+
if (focusable) {
80+
layoutParams.flags = layoutParams.flags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE.inv()
81+
windowManager.updateViewLayout(rootView, layoutParams)
82+
}
8183
}
8284
}
8385
false

lib/android_window.dart

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/gestures.dart';
12
import 'package:flutter/material.dart';
23

34
import 'pigeon.g.dart';
@@ -54,15 +55,27 @@ class _AndroidWindowState extends State<AndroidWindow> {
5455

5556
@override
5657
Widget build(BuildContext context) {
57-
return GestureDetector(
58-
onPanStart: (event) => start = true,
59-
onPanUpdate: (event) {
60-
if (start) {
61-
_api.dragStart();
62-
start = false;
63-
}
58+
return RawGestureDetector(
59+
gestures: {
60+
PanGestureRecognizer: GestureRecognizerFactoryWithHandlers(
61+
() => PanGestureRecognizer(),
62+
(instance) {
63+
(instance as PanGestureRecognizer)
64+
..onStart = (event) {
65+
start = true;
66+
}
67+
..onUpdate = (event) {
68+
if (start) {
69+
_api.dragStart();
70+
start = false;
71+
}
72+
}
73+
..onEnd = (event) {
74+
_api.dragEnd();
75+
};
76+
},
77+
),
6478
},
65-
onPanEnd: (event) => _api.dragEnd(),
6679
child: widget.child,
6780
);
6881
}

0 commit comments

Comments
 (0)