Created
May 9, 2020 16:50
-
-
Save vasyafromrussia/66b9eb2ecf21ffd7a41642a6cf47319f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : FlutterActivity() { | |
companion object { | |
private const val CHANNEL = "sample/gesture"; | |
} | |
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | |
super.configureFlutterEngine(flutterEngine) | |
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL) | |
.setMethodCallHandler { call, result -> | |
if (call.method == "setSystemGestureExclusionRects") { | |
handleSetSystemGestureExclusionRectsCall(call, result) | |
} else { | |
result.notImplemented() | |
} | |
} | |
} | |
private fun handleSetSystemGestureExclusionRectsCall( | |
call: MethodCall, | |
result: MethodChannel.Result | |
) { | |
val arguments = call.arguments as? List<Map<String, Int>> | |
if (arguments != null) { | |
val decodedRects = decodeExclusionRects(arguments) | |
setSystemGestureExclusionRects(decodedRects) | |
result.success(null) | |
} else { | |
result.error( | |
"inputTypeError", | |
"Input type is incorrect. Ensure that a List<Map<String, int>> " + | |
"is passed as the input for " + | |
"SystemGestureExclusionRects.setSystemGestureExclusionRects.", | |
null | |
) | |
} | |
} | |
private fun decodeExclusionRects(inputRects: List<Map<String, Int>>): List<Rect> = | |
inputRects.mapIndexed { index, item -> | |
Rect( | |
item["left"] ?: error("rect at index $index doesn't contain 'left' property"), | |
item["top"] ?: error("rect at index $index doesn't contain 'top' property"), | |
item["right"] ?: error("rect at index $index doesn't contain 'right' property"), | |
item["bottom"] ?: error("rect at index $index doesn't contain 'bottom' property") | |
) | |
} | |
private fun setSystemGestureExclusionRects(rects: List<Rect>) { | |
ViewCompat.setSystemGestureExclusionRects(activity.window.decorView, rects) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment