Any UIRefresh Work Around for Mac?

It says UIRefreshControl is not supported when running Catalyst apps in the Mac idiom. Consider using a Refresh menu item bound to ⌘-R what would I need to do to fix this to make my apps work with Catalyst?

Replies

Anyway I could make Mac OS detect that it's only an iOS Compatible Control?

Seems like at the moment we gotta work around by excluding the UIRefreshControl from being executed on Mac Catalyst.

Consider having an extension like this:

extension UIDevice {
	  // Checks if we run in Mac Catalyst Optimized For Mac Idiom
	  var isCatalystMacIdiom: Bool {
		    if #available(iOS 14, *) {
			      return UIDevice.current.userInterfaceIdiom == .mac
		    } else {
			      return false
		    }
	  }
}
  • Thank you so much

Add a Comment

Attempting to use Catalyst for the first time. I just switched on "Optimize for Mac" and got this on launch. Some compiler warnings for this would be nice....

I'm supposed to just run the app and find forbidden objects for the "Mac idiom" by trial and error?

// MARK: Refreshable - Modifier for Refreshable based on OS: **(note: inline code does NOT work... is not my fault...) **

// accesory: public func isCatalyst()->Bool { //tolerate warnings!

#if targetEnvironment(macCatalyst) return true #endif return false }

public typealias RefreshAction = ()->()

private struct MyRefreshableModifier: ViewModifier {

internal init(action: @escaping RefreshAction) {
    self.action = action
}

private let action: RefreshAction

public func body(content: Content) -> some View {

#if os(iOS) // Catalyst IS under iOS:

    if isCatalyst(){
        content
    }else{
        content
        .refreshable {
            action()
        }
    }

#elseif os(macOS) content // nada. We throw away #endif } }

public extension View { func portableRefreshableModifier(action: @escaping RefreshAction) -> some View { modifier(MyRefreshableModifier(action: action) ) } }

// usage: /*

List { Text("Hello World") Text("Hello World") Text("Hello World") }.refreshable { print("refresh....") } will be: List { Text("Hello World") Text("Hello World") Text("Hello World") }.portableRefreshableModifier { print("refresh....") } */