swiftswiftuiuiviewrepresentable

Disable scrolling in UIViewRepresentable


I have an AAInfographics chart, that I have added to a UIViewRepresentable, and then place this in my SwiftUI view.

For some reason, this is scrollable (I mean, you can drag the contents of the view up and down). The content fits the view — when you release the drag it lands in the same position.

I have no idea why this would be, as there is no ScrollView, and nothing I can see in the code that would cause this.

I tried adding self.scrollDisabled(true), which did not fix the issue. I don't know what else to try, so would appreciate any advice. Here is the entire code:

import SwiftUI
import AAInfographics

struct PolarAreaChart: UIViewRepresentable {
    func updateUIView(_ uiView: AAChartView, context: Context) {
        
    }
        
    func makeUIView(context: Context) -> AAChartView {
        let aaChartView = AAChartView()
        
        let aaChartModel = AAChartModel()
            .chartType(.column)//Can be any of the chart types listed under `AAChartType`.
            .polar(true)
            .animationType(.bounce)
            .yAxisLabelsEnabled(false)
            .xAxisLabelsEnabled(false)
            .tooltipEnabled(false)
            .legendEnabled(false)
            .dataLabelsEnabled(false) //Enable or disable the data labels. Defaults to false
            .categories(["a", "b", "c", "d", "e", "f"])
            .colorsTheme(["#403d39","#ffbe0b","#00b4d8","#e73265", "#90be6d", "#ada7c9"])
            .yAxisMax(100)
            .series([
                AASeriesElement()
                    .colorByPoint(true)
                    .data([22.0, 60.9, 38.0, 74.0, 92.0, 42.0]),
                    
                    ])
        
        aaChartView.aa_drawChartWithChartModel(aaChartModel)
        return aaChartView
    }
}

Solution

  • AAChartView itself contains a scrollView, so you need to disable the scrolling on that. This can be done using the isScrollEnabled property.

    func makeUIView(context: Context) -> AAChartView {
      let aaChartView = AAChartView()
      aaChartView.isScrollEnabled = false