Repository: flutter
Issue: Native screens hosted in Flutter don't respond to screen interactions.
Labels: platform-ios,framework,f: gestures,a: platform-views,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.16,found in release: 3.19

I'm trying to show a native Swift ViewController which has 2 buttons, one of which invokes a method on the FlutterMethodChannel to which Flutter reacts in the corresponding methodHandler.
I did test the method invoking inside the VC's viewDidLoad method and Flutter behaves as expected.
The issue is that no invocation is made from the native button, nor any other action from the button. It seems that it never gets tapped.
Lookin into the issue I made sure that UiKitView was wrapped in a GestureDetector and the gestures were properly forwarded to it, using an ElevatedButton to test it and indeed the button's and the GestureDetector callbacks are working as expected, so it's not preventing the gesture from its child.

Back to the swift ViewController I did tried and added the UIGestureRecognizerDelegate and setup methods to make sure that gestures were detected by the native ViewController, but to no avail.

Here is some code snippets:
# PlatformViews
```
class AdatptivePlatformView extends StatelessWidget {
  final String nativeScreen;
  final String viewType;
  final dynamic creationParams;
  final TextDirection? layoutDirection;
  final MessageCodec<dynamic>? creationParamsCodec;
  const AdatptivePlatformView(
      {super.key,
      required this.viewType,
      this.creationParams,
      this.creationParamsCodec,
      this.layoutDirection,
      required this.nativeScreen});

  @override
  Widget build(BuildContext context) {
    return Platform.isAndroid
        ? AndroidView(
            viewType: viewType,
            layoutDirection: TextDirection.ltr,
            creationParams: creationParams,
            creationParamsCodec: const StandardMessageCodec(),
            gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
              Factory<OneSequenceGestureRecognizer>(
                () => EagerGestureRecognizer(),
              ),
            },
          )
        : GestureDetector(
            // onTap: () {
            //   console.log("onTap");
            // },
            // onTapCancel: () {
            //   console.log("onTapCancel");
            // },
            // onLongPress: () {
            //   console.log("onLongPress");
            // },
            // onDoubleTap: () {
            //   console.log("onDoubleTap");
            // },
            // with "deferToChild" hit test behaviour , touches are passed down to widget.
            // if we do activate any GestureDetector callback then they both work.
            behavior: HitTestBehavior.deferToChild,
            // child: ElevatedButton(
            //     onPressed: () {
            //       console.log('the tap has beeen detected by the button');
            //     },
            //     child: const Text('test button')),
            child: UiKitView(
              viewType: viewType,
              layoutDirection: TextDirection.ltr,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
              hitTestBehavior: PlatformViewHitTestBehavior.translucent,
              gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
                Factory<OneSequenceGestureRecognizer>(
                  () => EagerGestureRecognizer(),
                ),
              },
            ),
          );
  }
}
```
# ViewController
```
//
//  ViewController.swift
//  UiKitFlutter
//
//  Created by vincenzo calia on 16/10/23.
//

import Flutter

class ViewController: UIViewController, UIGestureRecognizerDelegate {
    public var buttonTitleA: String?
    public var buttonTitleB: String?
    var buttonA = UIButton(type:UIButton.ButtonType.custom)
    var buttonB = UIButton(type:UIButton.ButtonType.custom)

     override func viewDidLoad() {
         
         super.viewDidLoad()

         buttonA.addTarget(self, action: #selector(dismissViewController), for: .touchUpInside)
         buttonA.setTitle(buttonTitleA ?? "Flutter Screen A", for: UIControl.State.normal)
         buttonA.frame = CGRect(x: 80.0, y: 210.0, width: 160.0, height: 40.0)
         buttonA.backgroundColor = UIColor.systemGray5
         buttonA.setTitleColor(UIColor.systemBlue, for: .normal)
         buttonA.layer.cornerRadius = 8;
         self.view.addSubview(buttonA)

         let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(flutterButtonBTapped));

         gestureRecognizer.isEnabled = true
         
        gestureRecognizer.cancelsTouchesInView = false

         gestureRecognizer.delegate = self

         
         
        buttonB.addGestureRecognizer(gestureRecognizer);

        // buttonB.addTarget(self, action: #selector(flutterButtonBTapped), for: .touchUpInside)


         buttonB.setTitle(buttonTitleB ?? "Flutter Screen B", for: UIControl.State.normal)
         buttonB.frame = CGRect(x: 80.0, y: 260.0, width: 160.0, height: 40.0)
         buttonB.backgroundColor = UIColor.systemGray5
         buttonB.setTitleColor(UIColor.systemBlue, for: .normal)
         buttonB.layer.cornerRadius = 8;
         self.view.addSubview(buttonB);
         
         
// THE ISSUE:
// called here invokeMethod works so we are sure that the desired beahviour is correct..calling it from button doesn't.
// Native gesture detection is not recognized when native ViewController is shown in Flutter, so no interaction with native buttons is possible.

// WHAT I TRIED:
// Wrapping the UiKitVIew with a GestureDetector, so we made sure that gestures are passed down to it.
// As a test I swapped the UiKitView wit an ElevatedButton and tested that both onTap from GestureDetector 
// and onPressed from the ElevatedButton callbacks where in fact working as expected.
// I added UIGestureRecognizerDelegate and setup methods to make sure that gestures were detected by the native ViewController, but to no avail.
// 
// OUTCOME: No interaction with the native ViewController has been achieved, making the whole hosting native views in flutter a waste of time.


        // let params = [
        //         "screen": "viewController2",
        //         "param 1": "close native",
        //         "param 2": "goto VC1"
        //     ] as [String: AnyObject]
        // let appDelegate = UIApplication.shared.delegate as! AppDelegate;
        // let controller = appDelegate.window?.rootViewController as! FlutterViewController;
        // var nativeViewerPlatformCahannel = FlutterMethodChannel(name: "native_viewer_platform_channel",binaryMessenger: controller.binaryMessenger);
        // nativeViewerPlatformCahannel.invokeMethod("switch_to_screen", arguments: params);
    }
    
//    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
//        return true
//    }
//     func gestureRecognizer(
//     _ gestureRecognizer: UIGestureRecognizer,
//     shouldReceive touch: UITouch
// ) -> Bool {
//     return true
// }
    func gestureRecognizer(
        _ gestureRecognizer: UIGestureRecognizer,
        shouldReceive event: UIEvent
    ) -> Bool {
        return true
    }


   @objc func flutterButtonBTapped() {
    
    
       // Implement your native functionality here
       buttonA.setTitle("new value", for: UIControl.State.normal)
        let params = [
                "screen": "viewController2",
                "param 1": "close native",
                "param 2": "goto VC1"
            ] as [String: AnyObject]
        let appDelegate = UIApplication.shared.delegate as! AppDelegate;
        let controller = appDelegate.window?.rootViewController as! FlutterViewController;
       let nativeViewerPlatformCahannel = FlutterMethodChannel(name: "native_viewer_platform_channel",binaryMessenger: controller.binaryMessenger);
        nativeViewerPlatformCahannel.invokeMethod("switch_to_screen", arguments: params);

       let buttonA = UIButton(type:UIButton.ButtonType.infoDark)
        //  buttonA.addTarget(self, action: #selector(dismissViewController), for: .touchUpInside)
//         buttonA.setTitle("Flutter Screen A", for: UIControl.State.normal)
         buttonA.setTitle("added", for: UIControl.State.normal)
         buttonA.frame = CGRect(x: 80.0, y: 410.0, width: 160.0, height: 40.0)
         buttonA.backgroundColor = UIColor.systemGray5
         buttonA.setTitleColor(UIColor.systemBlue, for: .normal)
         buttonA.layer.cornerRadius = 8;
         self.view.addSubview(buttonA)
        

   }


    @objc func dismissViewController(vc: FlutterViewController){
        //  vc.dismiss(animated: true);
     }
}

```


Now looking at solving the problem I do see that this is an ongoing problem with PlatformViews, as I see issues here opened in 2020 and still unresolved with comments from two weeks ago.
Is the whole native view hosting actually fully working with interactions with the native views? I do see plugins like https://github.com/LuisThein/apple_maps_flutter which does successfully implements native view controllers and have flutter interact with it. 
Documentation on this subject is very sparse and I haven't been able to find concrete examples on how to set things up completely, but please do point me to it as I might just haven't found it.

Here https://github.com/vinnytwice/native_in_fluter you can find the complete code for this issue.
Can you spot if and what I'm doing wrong there?
Many many thanks.