AnyChart-iOS icon indicating copy to clipboard operation
AnyChart-iOS copied to clipboard

Doesn't support multiple `AnyChartView` instances

Open devpolant opened this issue 4 years ago • 2 comments

Precondition

  • I'm trying to display 2 charts on the same screen. First one on left half of the screen and second one on the right half.
  • But I see that only one of them is displayed on the screen

Problem

  • I looked at the init method inside AnyChartView.swift and I see APIlib.sharedInstance.jsDelegate = self there
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initSubviews()
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initSubviews()
    }
    
    func initSubviews() {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: "AnyChartView", bundle: bundle)
        nib.instantiate(withOwner: self, options: nil)
        container.frame = bounds
        addSubview(container)
        
        let webConfiguration = WKWebViewConfiguration()
        let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: container.frame.size.height))
        webView = WKWebView (frame: customFrame , configuration: webConfiguration)
        webView.translatesAutoresizingMaskIntoConstraints = false
        container.addSubview(webView)
        webView.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
        webView.rightAnchor.constraint(equalTo: container.rightAnchor).isActive = true
        webView.leftAnchor.constraint(equalTo: container.leftAnchor).isActive = true
        webView.bottomAnchor.constraint(equalTo: container.bottomAnchor).isActive = true
        webView.heightAnchor.constraint(equalTo: container.heightAnchor).isActive = true

        APIlib.sharedInstance.jsDelegate = self
    }

So it is impossible to use more than one AnyChartView object instance simultaneously.

Is it possible to make a workaround for that?

devpolant avatar May 17 '20 12:05 devpolant

@AntonPoltoratskyi Unfortunately, the current version of the library doesn't support multiple Views. We have been asked about that frequently, so we will take into account for future updates.

Shestac92 avatar May 18 '20 05:05 Shestac92

Thanks for your reply!

devpolant avatar May 18 '20 06:05 devpolant