@@ -89,6 +89,27 @@ PlatformViewChannel::~PlatformViewChannel() {
89
89
view_instances_.clear ();
90
90
}
91
91
92
+ void PlatformViewChannel::sendKeyEvent (Ecore_Event_Key* key, bool is_down) {
93
+ auto instances = viewInstances ();
94
+ auto it = instances.find (currentFocusedViewId ());
95
+ if (it != instances.end ()) {
96
+ if (is_down) {
97
+ it->second ->dispatchKeyDownEvent (key);
98
+ } else {
99
+ it->second ->dispatchKeyUpEvent (key);
100
+ }
101
+ }
102
+ }
103
+
104
+ int PlatformViewChannel::currentFocusedViewId () {
105
+ for (auto it = view_instances_.begin (); it != view_instances_.end (); it++) {
106
+ if (it->second ->isFocused ()) {
107
+ return it->second ->getViewId ();
108
+ }
109
+ }
110
+ return -1 ;
111
+ }
112
+
92
113
void PlatformViewChannel::HandleMethodCall (
93
114
const flutter::MethodCall<flutter::EncodableValue>& call,
94
115
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
@@ -113,10 +134,22 @@ void PlatformViewChannel::HandleMethodCall(
113
134
}
114
135
auto it = view_factories_.find (viewType);
115
136
if (it != view_factories_.end ()) {
137
+ auto focuesdView = view_instances_.find (currentFocusedViewId ());
138
+ if (focuesdView != view_instances_.end ()) {
139
+ focuesdView->second ->setFocus (false );
140
+ }
141
+
116
142
auto viewInstance =
117
143
it->second ->create (viewId, width, height, byteMessage);
144
+ viewInstance->setFocus (true );
118
145
view_instances_.insert (
119
146
std::pair<int , PlatformView*>(viewId, viewInstance));
147
+
148
+ if (channel_ != nullptr ) {
149
+ auto id = std::make_unique<flutter::EncodableValue>(viewId);
150
+ channel_->InvokeMethod (" viewFocused" , std::move (id));
151
+ }
152
+
120
153
result->Success (flutter::EncodableValue (viewInstance->getTextureId ()));
121
154
} else {
122
155
LoggerE (" can't find view type = %s" , viewType.c_str ());
0 commit comments