Skip to content

Commit

Permalink
Fix focusable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuxiang committed Nov 24, 2022
1 parent 15b9ede commit 51bf067
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.math.roundToInt

class AndroidWindow(
val service: Service,
focusable: Boolean,
private val focusable: Boolean,
width: Int,
height: Int,
private val x: Int,
Expand Down Expand Up @@ -76,8 +76,10 @@ class AndroidWindow(
}
}
MotionEvent.ACTION_DOWN -> {
layoutParams.flags = layoutParams.flags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE.inv()
windowManager.updateViewLayout(rootView, layoutParams)
if (focusable) {
layoutParams.flags = layoutParams.flags and WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE.inv()
windowManager.updateViewLayout(rootView, layoutParams)
}
}
}
false
Expand Down
29 changes: 21 additions & 8 deletions lib/android_window.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

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

@override
Widget build(BuildContext context) {
return GestureDetector(
onPanStart: (event) => start = true,
onPanUpdate: (event) {
if (start) {
_api.dragStart();
start = false;
}
return RawGestureDetector(
gestures: {
PanGestureRecognizer: GestureRecognizerFactoryWithHandlers(
() => PanGestureRecognizer(),
(instance) {
(instance as PanGestureRecognizer)
..onStart = (event) {
start = true;
}
..onUpdate = (event) {
if (start) {
_api.dragStart();
start = false;
}
}
..onEnd = (event) {
_api.dragEnd();
};
},
),
},
onPanEnd: (event) => _api.dragEnd(),
child: widget.child,
);
}
Expand Down

0 comments on commit 51bf067

Please sign in to comment.