Skip to content

Commit 1aeb569

Browse files
pkoskoswift-kim
authored andcommitted
[SystemChrome] setPreferredOrientations implementation added (#79)
[Before] not implemented [After] Using API below allows to narrow some rotations of application UI e.g. /// to limit some orientations List<DeviceOrientation> orientations = [DeviceOrientation.portraitUp, DeviceOrientation.landscapeLeft]; SystemChrome.setPreferredOrientations(orientations).then( (value) => print("preferred orientations were set")); /// to clear previous limitations List<DeviceOrientation> orientations = []; SystemChrome.setPreferredOrientations(orientations).then( (value) => print("preferred orientations were CLEARED"));
1 parent 4d04d8c commit 1aeb569

8 files changed

+64
-4
lines changed

shell/platform/tizen/channels/platform_channel.cc

+42-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
#include <app.h>
88

9+
#include <map>
10+
911
#include "flutter/shell/platform/common/cpp/json_method_codec.h"
1012
#include "flutter/shell/platform/tizen/tizen_log.h"
1113

1214
static constexpr char kChannelName[] = "flutter/platform";
1315

14-
PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
16+
PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger,
17+
TizenRenderer* renderer)
1518
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
1619
messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) {
1720
channel_->SetMethodCallHandler(
@@ -20,6 +23,9 @@ PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
2023
std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
2124
HandleMethodCall(call, std::move(result));
2225
});
26+
// renderer pointer is managed by TizenEmbedderEngine
27+
// !! can be nullptr in case of service application !!
28+
tizen_renderer_ = renderer;
2329
}
2430

2531
PlatformChannel::~PlatformChannel() {}
@@ -43,7 +49,41 @@ void PlatformChannel::HandleMethodCall(
4349
} else if (method == "Clipboard.hasStrings") {
4450
result->NotImplemented();
4551
} else if (method == "SystemChrome.setPreferredOrientations") {
46-
result->NotImplemented();
52+
if (tizen_renderer_) {
53+
static const std::string kPortraitUp = "DeviceOrientation.portraitUp";
54+
static const std::string kPortraitDown = "DeviceOrientation.portraitDown";
55+
static const std::string kLandscapeLeft =
56+
"DeviceOrientation.landscapeLeft";
57+
static const std::string kLandscapeRight =
58+
"DeviceOrientation.landscapeRight";
59+
static const std::map<std::string, int> orientation_mapping = {
60+
{kPortraitUp, 0},
61+
{kLandscapeLeft, 90},
62+
{kPortraitDown, 180},
63+
{kLandscapeRight, 270},
64+
};
65+
66+
const auto& list = call.arguments()[0];
67+
std::vector<int> rotations;
68+
for (rapidjson::Value::ConstValueIterator itr = list.Begin();
69+
itr != list.End(); ++itr) {
70+
const std::string& rot = itr->GetString();
71+
FT_LOGD("Passed rotation: %s", rot.c_str());
72+
rotations.push_back(orientation_mapping.at(rot));
73+
}
74+
if (rotations.size() == 0) {
75+
// According do docs
76+
// https://api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html
77+
// "The empty list causes the application to defer to the operating
78+
// system default."
79+
FT_LOGD("No rotations passed, using default values");
80+
rotations = {0, 90, 180, 270};
81+
}
82+
tizen_renderer_->SetPreferredOrientations(rotations);
83+
result->Success();
84+
} else {
85+
result->Error("Not supported for service applications");
86+
}
4787
} else if (method == "SystemChrome.setApplicationSwitcherDescription") {
4888
result->NotImplemented();
4989
} else if (method == "SystemChrome.setEnabledSystemUIOverlays") {

shell/platform/tizen/channels/platform_channel.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77

88
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
99
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h"
10+
#include "flutter/shell/platform/tizen/tizen_renderer.h"
1011
#include "rapidjson/document.h"
1112

1213
class PlatformChannel {
1314
public:
14-
explicit PlatformChannel(flutter::BinaryMessenger* messenger);
15+
explicit PlatformChannel(flutter::BinaryMessenger* messenger,
16+
TizenRenderer* renderer);
1517
virtual ~PlatformChannel();
1618

1719
private:
1820
std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
21+
TizenRenderer* tizen_renderer_;
1922

2023
void HandleMethodCall(
2124
const flutter::MethodCall<rapidjson::Document>& call,

shell/platform/tizen/tizen_embedder_engine.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool TizenEmbedderEngine::RunEngine(
222222
std::make_unique<flutter::PluginRegistrar>(plugin_registrar_.get());
223223

224224
platform_channel = std::make_unique<PlatformChannel>(
225-
internal_plugin_registrar_->messenger());
225+
internal_plugin_registrar_->messenger(), tizen_renderer.get());
226226
settings_channel = std::make_unique<SettingsChannel>(
227227
internal_plugin_registrar_->messenger());
228228
localization_channel = std::make_unique<LocalizationChannel>(flutter_engine);

shell/platform/tizen/tizen_renderer.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define EMBEDDER_TIZEN_RENDERER_H
77

88
#include <cstdint>
9+
#include <vector>
910

1011
class TizenRenderer {
1112
public:
@@ -36,6 +37,7 @@ class TizenRenderer {
3637
virtual void SetRotate(int angle) = 0;
3738
virtual void ResizeWithRotation(int32_t x, int32_t y, int32_t width,
3839
int32_t height, int32_t degree) = 0;
40+
virtual void SetPreferredOrientations(const std::vector<int>& rotations) = 0;
3941

4042
protected:
4143
explicit TizenRenderer(TizenRenderer::Delegate& delegate);

shell/platform/tizen/tizen_renderer_ecore_wl2.cc

+6
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,9 @@ void TizenRendererEcoreWl2::SendRotationChangeDone() {
585585
ecore_wl2_window_, ecore_wl2_window_rotation_get(ecore_wl2_window_), w,
586586
h);
587587
}
588+
589+
void TizenRendererEcoreWl2::SetPreferredOrientations(
590+
const std::vector<int> &rotations) {
591+
ecore_wl2_window_available_rotations_set(ecore_wl2_window_, rotations.data(),
592+
rotations.size());
593+
}

shell/platform/tizen/tizen_renderer_ecore_wl2.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class TizenRendererEcoreWl2 : public TizenRenderer {
3030
void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height,
3131
int32_t angle) override;
3232
void SetRotate(int angle) override;
33+
void SetPreferredOrientations(const std::vector<int> &rotations) override;
3334

3435
private:
3536
bool InitializeRenderer();

shell/platform/tizen/tizen_renderer_evas_gl.cc

+7
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,10 @@ void TizenRendererEvasGL::ResizeWithRotation(int32_t x, int32_t y,
709709
void TizenRendererEvasGL::SendRotationChangeDone() {
710710
elm_win_wm_rotation_manual_rotation_done(evas_window_);
711711
}
712+
713+
void TizenRendererEvasGL::SetPreferredOrientations(
714+
const std::vector<int>& rotations) {
715+
elm_win_wm_rotation_available_rotations_set(
716+
evas_window_, static_cast<const int*>(rotations.data()),
717+
rotations.size());
718+
}

shell/platform/tizen/tizen_renderer_evas_gl.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TizenRendererEvasGL : public TizenRenderer {
3131
void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height,
3232
int32_t angle) override;
3333
void SetRotate(int angle) override;
34+
void SetPreferredOrientations(const std::vector<int>& rotations) override;
3435

3536
void* GetImageHandle();
3637

0 commit comments

Comments
 (0)