未验证 提交 2ff16263 编写于 作者: A amirh 提交者: GitHub

Support LTR/RTL layout directions for embedded Android views. (#6057)

上级 d687f9da
......@@ -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<String, Object> 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<String, Object> 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<PointerProperties> parsePointerPropertiesList(Object rawPropertiesList) {
List<Object> rawProperties = (List<Object>) rawPropertiesList;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册