@@ -89,6 +89,27 @@ PlatformViewChannel::~PlatformViewChannel() {
8989 view_instances_.clear ();
9090}
9191
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+
92113void PlatformViewChannel::HandleMethodCall (
93114 const flutter::MethodCall<flutter::EncodableValue>& call,
94115 std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
@@ -113,10 +134,22 @@ void PlatformViewChannel::HandleMethodCall(
113134 }
114135 auto it = view_factories_.find (viewType);
115136 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+
116142 auto viewInstance =
117143 it->second ->create (viewId, width, height, byteMessage);
144+ viewInstance->setFocus (true );
118145 view_instances_.insert (
119146 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+
120153 result->Success (flutter::EncodableValue (viewInstance->getTextureId ()));
121154 } else {
122155 LoggerE (" can't find view type = %s" , viewType.c_str ());
0 commit comments