ringcentral / engage-digital-messaging-ios

Engage Digital Messaging IOS SDK
Other
10 stars 6 forks source link

[Ios][Flutter] - Chat not displaying #47

Closed molobala closed 1 year ago

molobala commented 1 year ago

I'm developing a flutter plugin for Dimelo SDK for our application, I used to get ViewController from dimelo with bellow code and display the cat without Navigationbar but in my plugin the chat is not displying. If I do not disable the Navigationbar , in the plugin only the NavBar view displays, it's like if the chat view is not loading propertly.

 func view() -> UIView {
        let dimelo: Dimelo = Dimelo.sharedInstance()
        dimelo.enableThreads = false
        dimelo.embeddedAsFragment = false
        let navController = dimelo.chatViewController()! as! UINavigationController
        navController.setNavigationBarHidden(false, animated: false)
        let chatView = navController.view!
        chatView.backgroundColor = UIColor.cyan
        return chatView
    }

with_nav_bar without_navbar

Note that calling dimelo.displayChatView() displays well the chat in a modal view.

waelba commented 1 year ago

Hi @molobala,

This is not the correct way to embed the dimelo chat please can you test this code (obj c):

    _dimelo = [Dimelo sharedInstance];
    _dimelo.embeddedAsFragment = YES;
    _dimelo.enableThreads = NO;
    // add dimelo chat view as fragment
    UIViewController *vc = [_dimelo chatViewController];
    vc.view.frame = self.container.bounds;
    // container is the parent view
    [self.container addSubview:vc.view];
    [self addChildViewController:vc];
    [vc didMoveToParentViewController:self];
    [vc becomeFirstResponder];

and there is the result: Simulator Screen Shot - iPhone 14 Pro - 2023-02-14 at 15 40 07

Regards,

molobala commented 1 year ago

Still the same problem, note that I can't add the viewcontroller directly as you did with (addChildViewController and didMoveToParentViewController), since i'm in the plugin, i don't know if that's the problem. But I used to make dimelo works like this in my Capacitor plugin.

func createChat(_ call: [String: Any]) {
        let dimelo: Dimelo = Dimelo.sharedInstance()
        DimeloView.customize(dimelo, call)// customize dimelo view
        dimelo.enableThreads = false
        dimelo.embeddedAsFragment = true
        let dimVc = dimelo.chatViewController()!
        // let navController = dim as! UINavigationController
        dimVc.view.frame = self._view.bounds
        self._view.addSubview(dimVc.view)
        dimVc.becomeFirstResponder()
 }

  func view() -> UIView {
        return _view
    }
  // somewhere in my init function

   let sc = UIScrollView(frame: CGRect(x: x!, y: y!, width: width!, height: height!))
   sc.isScrollEnabled=true
   // sc.bounds = sc.frame.insetBy(dx: 10, dy: paddingBottom!)
   sc.contentInset=UIEdgeInsets.init(top: 20, left: 0, bottom: paddingBottom!, right: 0)
   if #available(iOS 13.0, *) {
        sc.automaticallyAdjustsScrollIndicatorInsets=false
   } else {
         // Fallback on earlier versions
   }
   _view = sc
   createChat(...)

Simulator Screen Shot - iPhone 12 - 2023-02-14 at 15 46 12

molobala commented 1 year ago

get to make it works. I don't know exactly what was the issue but I guess the problem was that I was creating Dimelo chat view from createChat, and at that moment flutter call view() method, the view is not fully loaded but flutter does not know.
I finally create a Dimelo ViewController as my class property and call view in view() method.

    private var dimeloViewController: UIViewController
    init(
        frame: CGRect,
        viewIdentifier viewId: Int64,
        arguments args: Any?,
        binaryMessenger messenger: FlutterBinaryMessenger?
    ) {
        let dimelo = Dimelo.sharedInstance()
        dimeloViewController = dimelo!.chatViewController()!
        super.init()
        DimeloView.initDimelo(args != nil ? args as! [String: Any] : [String: Any]())
        let decoration = args != nil ? ((args as! [String: Any])["decoration"] != nil ? (args as! [String: Any])["decoration"]  as! [String: Any]: [String: Any]()) : [String: Any]();
        DimeloView.customize(dimelo!, decoration)

        let navController = dimeloViewController as! UINavigationController
        navController.setNavigationBarHidden(true, animated: false)
        dimeloViewController.view.frame = frame
        dimeloViewController.view.backgroundColor = UIColor.cyan
        let _view = dimeloViewController.view!;
        _view.isHidden = false
        _view.backgroundColor = UIColor.clear

    }

    func view() -> UIView {
        return dimeloViewController.view
    }
DrissTM commented 1 year ago

thanks for the heads up @molobala and glad to hear that you managed to get it working :+1: