Skip to content

Commit 576a413

Browse files
authored
Add setDirection method to platform view channel (#85)
1 parent 7e48f8d commit 576a413

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

flutter/shell/platform/tizen/channels/platform_view_channel.cc

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace flutter {
1414
namespace {
1515

1616
constexpr 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

flutter/shell/platform/tizen/channels/platform_view_channel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PlatformViewChannel {
4343
void RemoveViewIfExists(int view_id);
4444
void ClearViews();
4545
void ClearViewFactories();
46+
bool ValidateDirection(int direction);
4647

4748
void HandleMethodCall(const MethodCall<EncodableValue>& call,
4849
std::unique_ptr<MethodResult<EncodableValue>> result);
@@ -59,6 +60,8 @@ class PlatformViewChannel {
5960
std::unique_ptr<MethodResult<EncodableValue>>&& result);
6061
void OnTouch(const EncodableValue* arguments,
6162
std::unique_ptr<MethodResult<EncodableValue>>&& result);
63+
void OnSetDirection(const EncodableValue* arguments,
64+
std::unique_ptr<MethodResult<EncodableValue>>&& result);
6265

6366
std::unique_ptr<MethodChannel<EncodableValue>> channel_;
6467
std::map<std::string, std::unique_ptr<PlatformViewFactory>> view_factories_;

0 commit comments

Comments
 (0)