Skip to content

Commit

Permalink
Support LTR/RTL layout directions for embedded Android views. (flutte…
Browse files Browse the repository at this point in the history
  • Loading branch information
amirh authored Aug 20, 2018
1 parent d687f9d commit 2ff1626
Showing 1 changed file with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,30 @@ public void onMethodCall(final MethodCall call, final MethodChannel.Result resul
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(
Expand Down Expand Up @@ -147,6 +160,7 @@ private void createPlatformView(MethodCall call, MethodChannel.Result result) {
}

vdControllers.put(id, vdController);
vdController.getView().setLayoutDirection(direction);

// TODO(amirh): copy accessibility nodes to the FlutterView's accessibility tree.

Expand Down Expand Up @@ -253,6 +267,39 @@ private void onTouch(MethodCall call, MethodChannel.Result result) {
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;
Expand Down

0 comments on commit 2ff1626

Please sign in to comment.