@@ -14,6 +14,8 @@ namespace flutter {
1414namespace {
1515
1616constexpr char kChannelName [] = " flutter/platform_views" ;
17+ constexpr int kLayoutDirectionLtr = 0 ;
18+ constexpr int kLayoutDirectionRtl = 1 ;
1719
1820} // namespace
1921
@@ -112,6 +114,8 @@ void PlatformViewChannel::HandleMethodCall(
112114 OnResize (arguments, std::move (result));
113115 } else if (method == " touch" ) {
114116 OnTouch (arguments, std::move (result));
117+ } else if (method == " setDirection" ) {
118+ OnSetDirection (arguments, std::move (result));
115119 } else {
116120 FT_LOG (Warn) << " Unimplemented method: " << method;
117121 result->NotImplemented ();
@@ -131,8 +135,9 @@ void PlatformViewChannel::OnCreate(
131135 EncodableValueHolder<int > view_id (map, " id" );
132136 EncodableValueHolder<double > width (map, " width" );
133137 EncodableValueHolder<double > height (map, " height" );
138+ EncodableValueHolder<int > direction (map, " direction" );
134139
135- if (!view_type || !view_id || !width || !height) {
140+ if (!view_type || !view_id || !width || !height || !direction ) {
136141 result->Error (" Invalid arguments" );
137142 return ;
138143 }
@@ -154,6 +159,7 @@ void PlatformViewChannel::OnCreate(
154159 PlatformView* view = iter->second ->Create (
155160 *view_id, *width * pixel_ratio_, *height * pixel_ratio_, byte_message);
156161 if (view) {
162+ view->SetDirection (*direction);
157163 views_[*view_id] = view;
158164 result->Success (EncodableValue (view->GetTextureId ()));
159165 } else {
@@ -315,4 +321,41 @@ void PlatformViewChannel::OnTouch(
315321 result->Success ();
316322}
317323
324+ void PlatformViewChannel::OnSetDirection (
325+ const EncodableValue* arguments,
326+ std::unique_ptr<MethodResult<EncodableValue>>&& result) {
327+ auto * map = std::get_if<EncodableMap>(arguments);
328+ if (!map) {
329+ result->Error (" Invalid arguments" );
330+ return ;
331+ }
332+
333+ EncodableValueHolder<int > view_id (map, " id" );
334+ EncodableValueHolder<int > direction (map, " direction" );
335+
336+ if (!view_id || !direction) {
337+ result->Error (" Invalid arguments" );
338+ return ;
339+ }
340+ if (!ValidateDirection (*direction)) {
341+ result->Error (
342+ " Trying to set unknown direction value: " + std::to_string (*direction) +
343+ " (view id: " + std::to_string (*view_id) + " )" );
344+ return ;
345+ }
346+
347+ PlatformView* view = FindViewById (*view_id);
348+ if (!view) {
349+ result->Error (" Can't find view id" );
350+ return ;
351+ }
352+
353+ view->SetDirection (*direction);
354+ result->Success ();
355+ }
356+
357+ bool PlatformViewChannel::ValidateDirection (int direction) {
358+ return direction == kLayoutDirectionLtr || direction == kLayoutDirectionRtl ;
359+ }
360+
318361} // namespace flutter
0 commit comments