From 2ff1626335ce9bd60e74046b5000a68fb6d2948b Mon Sep 17 00:00:00 2001 From: amirh Date: Mon, 20 Aug 2018 16:22:38 -0700 Subject: [PATCH] Support LTR/RTL layout directions for embedded Android views. (#6057) --- .../platform/PlatformViewsController.java | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 969f527cb..caf04ccdd 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -96,17 +96,30 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler case "touch": onTouch(call, result); return; + case "setDirection": + setDirection(call, result); + return; } result.notImplemented(); } - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void createPlatformView(MethodCall call, MethodChannel.Result result) { Map args = call.arguments(); int id = (int) args.get("id"); String viewType = (String) args.get("viewType"); double logicalWidth = (double) args.get("width"); double logicalHeight = (double) args.get("height"); + int direction = (int) args.get("direction"); + + if (!validateDirection(direction)) { + result.error( + "error", + "Trying to create a view with unknown direction value: " + direction + "(view id: " + id + ")", + null + ); + return; + } if (vdControllers.containsKey(id)) { result.error( @@ -147,6 +160,7 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler } vdControllers.put(id, vdController); + vdController.getView().setLayoutDirection(direction); // TODO(amirh): copy accessibility nodes to the FlutterView's accessibility tree. @@ -253,6 +267,39 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler result.success(null); } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + private void setDirection(MethodCall call, MethodChannel.Result result) { + Map args = call.arguments(); + int id = (int) args.get("id"); + int direction = (int) args.get("direction"); + + if (!validateDirection(direction)) { + result.error( + "error", + "Trying to set unknown direction value: " + direction + "(view id: " + id + ")", + null + ); + return; + } + + View view = vdControllers.get(id).getView(); + if (view == null) { + result.error( + "error", + "Sending touch to an unknown view with id: " + id, + null + ); + return; + } + + view.setLayoutDirection(direction); + result.success(null); + } + + private static boolean validateDirection(int direction) { + return direction == View.LAYOUT_DIRECTION_LTR || direction == View.LAYOUT_DIRECTION_RTL; + } + @SuppressWarnings("unchecked") private static List parsePointerPropertiesList(Object rawPropertiesList) { List rawProperties = (List) rawPropertiesList; -- GitLab