HomeiOS DevelopmentCarPlay CPListImageRowItem causes Inverted Scrolling and Aspect Button malfunction

CarPlay CPListImageRowItem causes Inverted Scrolling and Aspect Button malfunction


In my CarPlaySceneDelegate.swift, I’ve two tabs:

  • The primary tab makes use of a CPListImageRowItem with a CPListImageRowItemRowElement. The scroll path is inverted, and the facet button doesn’t operate appropriately.
  • The second tab makes use of a number of CPListItem objects. There aren’t any points: scrolling works within the appropriate path, and the facet button behaves as anticipated.

Steps To Reproduce

  1. Launch the app.
  2. Connect with CarPlay.
  3. Within the first tab, scroll up and down, then use the facet button to navigate.
  4. Within the second tab, scroll up and down, then use the facet button to navigate.
  5. As noticed, the scrolling habits is totally different between the 2 tabs.

Code Instance:

import CarPlay
import UIKit

class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {

    var interfaceController: CPInterfaceController?

    func templateApplicationScene(
        _ templateApplicationScene: CPTemplateApplicationScene,
        didConnect interfaceController: CPInterfaceController
    ) {
        self.interfaceController = interfaceController
        downloadImageAndSetupTemplates()
    }

    func templateApplicationScene(
        _ templateApplicationScene: CPTemplateApplicationScene,
        didDisconnectInterfaceController interfaceController: CPInterfaceController
    ) {
        self.interfaceController = nil
    }

    personal func downloadImageAndSetupTemplates() {
        let urlString = "https://encrypted-tbn0.gstatic.com/photographs?q=tbn:ANd9GcRcYUjd1FYkF04-8Vb7PKI1mGoF2quLPHKjvnR7V4ReZR8UjW-0NJ_kC7q13eISZGoTCLHaDPVbOthhH9QNq-YA0uuSUjfAoB3PPs1aXQ&s=10"

        guard let url = URL(string: urlString) else {
            setupTemplates(with: UIImage(systemName: "picture")!)
            return
        }

        URLSession.shared.dataTask(with: url) { [weak self] information, _, _ in
            let picture: UIImage
            if let information = information, let downloaded = UIImage(information: information) {
                picture = downloaded
            } else {
                picture = UIImage(systemName: "picture")!
            }

            DispatchQueue.major.async {
                self?.setupTemplates(with: picture)
            }
        }.resume()
    }

    personal func setupTemplates(with picture: UIImage) {
        // Tab 1 : un seul CPListImageRowItem avec 12 CPListImageRowItemRowElement
        let components: [CPListImageRowItemRowElement] = (1...12).map { index in
            CPListImageRowItemRowElement(picture: picture, title: "take a look at (index)", subtitle: nil)
        }
        let rowItem = CPListImageRowItem(textual content: "Photographs", components: components, allowsMultipleLines: true)
        rowItem.listImageRowHandler = { merchandise, elementIndex, completion in
            print("tapped factor (elementIndex)")
            completion()
        }
        let tab1Section = CPListSection(objects: [rowItem])
        let tab1Template = CPListTemplate(title: "CPListImageRowItemRowElement", sections: [tab1Section])

        // Tab 2 : 12 CPListItem simples
        let tab2Items: [CPListItem] = (1...12).map { index in
            let merchandise = CPListItem(textual content: "Merchandise (index)", detailText: "Element (index)")
            merchandise.handler = { _, completion in
                print("handler Tab 2")
                completion()
            }
            return merchandise
        }
        let tab2Section = CPListSection(objects: tab2Items)
        let tab2Template = CPListTemplate(title: "CPListItem", sections: [tab2Section])

        // CPTabBarTemplate avec les deux tabs
        let tabBar = CPTabBarTemplate(templates: [tab1Template, tab2Template])
        interfaceController?.setRootTemplate(tabBar, animated: true)
    }
}

Here’s a fast video:

CarPlay CPListImageRowItem causes Inverted Scrolling and Aspect Button malfunction

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments