Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

Posts under SwiftUI tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

iOS18 beta2 NavigationStack: Tapping Back from a lower-level View returns to the Root View / No transition animation
This is a report of an issue that appears to be a regression regarding NavigationStack. While investigating another issue [iOS18 beta2: NavigationStack, Views Being Popped Automatically] , I encountered this separate issue and wanted to share it. In a NavigationStack with three levels: RootView - ContentView - SubView, tapping the Back button from the SubView returned to the RootView instead of the ContentView. This issue is similar to one that I previously posted regarding iOS16.0 beta. https://developer.apple.com/forums/thread/715970 Additionally, there is no transition animation when moving from ContentView to SubView. The reproduction code is as follows: import SwiftUI struct RootView2: View { @State var kind: Kind = .a @State var vals: [Selection] = { return (1...5).map { Selection(num: $0) } }() @State var selection: Selection? var body: some View { if #available(iOS 16.0, *) { NavigationStack { NavigationLink { ContentView2(vals: $vals, selection: $selection) } label: { Text("album") } .navigationDestination(isPresented: .init(get: { return selection != nil }, set: { newValue in if !newValue { selection = nil } }), destination: { if let selection { SubView2(kind: .a, selection: selection) } }) } } else { EmptyView() } } } struct ContentView2: View { @Binding var vals: [Selection] @Binding var selection: Selection? @Environment(\.dismiss) private var dismiss var body: some View { list .onChange(of: self.selection) { newValue in print("changed: \(String(describing: newValue?.num))") } } @ViewBuilder private var list: some View { if #available(iOS 16.0, *) { List(selection: $selection) { ForEach(self.vals) { val in NavigationLink(value: val) { Text("\(String(describing: val))") } } } } } } // struct SubView2: View { let kind: Kind let selection: Selection var body: some View { Text("Content. \(kind): \(selection)") } }
5
0
123
1d
Question About Weak Self Usage
Hello everyone. I have a small question about Weak Self. In the example below, I am doing a long process to the data I query with SwiftData. (For this reason, I do it in the background.) I don't know if there is a possibility of a memory leak when the view is closed because this process takes a long time. import SwiftUI import SwiftData struct ActiveRegView: View { @Query(filter: #Predicate<Registration> { $0.activeRegistration }, animation: .default) private var regs: [Registration] @Environment(ViewModel.self) private var vm @State private var totalParkingFee: Decimal = 0 var body: some View { ... .onAppear { var totalParkingFee = Decimal() DispatchQueue.global(qos: .userInitiated).async { for reg in regs { totalParkingFee += vm.parkingFee(from: reg.entryRegistration.entryDate, to: .now, category: reg.category, isCustomPrice: reg.isCustomPrice) } DispatchQueue.main.async { withAnimation { totalParkingFee = totalParkingFee } } } } } } I use ViewModel with @Environment, so I don't initilize ViewModel every time view is initilized. I know it's a simple question and I thank you in advance for your answers.
0
0
68
4d
Xcode Accessibility audit in UI Tests gives less than stellar results
I have added a UI test that uses the newish app.performAccessibilityAudit() on each of the screens in my SwiftUI app. I get a handful of test failures for various accessibility issues. Some of them are related to iOS issues (like the "legal" button in a map view doesn't have a big enough tappable are; and, I think, there is a contrast issue with selected tabs in a tab bar, or maybe it is a false positive). Two of the error type I get are around Text elements that use default font styles (like headline) but that apparently get clipped at times and apparently "Dynamic Type font sizes are unsupported". For some of the errors it supplies a screenshot of the whole screen along with an image of the element that is triggering the error. For these text errors it only provides the overall image. After looking at the video I saw that part of the test runs the text size all the way up and I could see that at the largest size or two the text was getting cut off despite using default settings for the frames on all the Text elements. After a bit of trial and error I managed to get the text to wrap properly even at the largest of sizes and most of the related errors went away running on an iPhone simulator. I switched to an iPad simulator and the errors re-appeared even though the video doesn't show the text getting clipped. Does anyone have any tips for actually fixing these issues? Or am I in false positive land here? Also, is there any way to get more specific info out of the test failures? Looking at the entire screen and trying to guess where the issue is kinda sucks.
0
2
246
5d
Automatic Grammar Agreement with formatted number: use integer value to switch categories
Hello, I want to use Automatic Grammar Agreement to localise a string in my app, let say "three remaining activities". The string "three" is obtained by using a NumberFormatter with a numberStyle set to .spellOut (so I'm not using an Integer) var formatter: NumberFormatter = NumberFormatter() formatter.numberStyle = .spellOut let formattedCount: String = numberFormatter.string(from: count as NSNumber)! Text("key_with_string_\(formattedCount)") In my string catalog, I have translated the key key_with_string_%@ like this ^[%@ remaining activity](inflect: true), but it does not work. I've tried to add the integer value used by the number formatter in the key key_with_string_%@_%lld but it does not work. Should Automatic Grammar Agreement work normally just by using the formatted string provided by the NumberFormatter? If not, is there a way to specify to use a secondary variable (my count integer) to switch between different categories like one and other automatically? Thanks ! Axel
1
0
113
6d
Draggable Views with Child Drop Destination Elements not Draggable in iOS 18
I'm creating an app that has a number of draggable views, and each of these views themselves contain child dropDestination views. In iOS 17.x they are draggable as expected. However, in iOS 18 betas 1 & 2 a long press on these views does NOT pick them up (start the drag operation). I have not tested with macOS 15 betas but the issue may well exist there also. Is this a bug in iOS 18 betas 1 & 2 or does the implementation need to be updated somehow for iOS 18? Please see example code below: Views: import SwiftUI extension View { func dropTarget<T>(for payloadType: T.Type, withTitle title: String) -> some View where T: Transferable { modifier(DropTargetViewModifer<T>(title: title)) } } struct DropTargetViewModifer<T>: ViewModifier where T: Transferable { let title: String func body(content: Content) -> some View { content .dropDestination(for: T.self) { items, location in print("Item(s) dropped in \(title)") return true } isTargeted: { targted in if targted { print("\(title) targeted") } } } } struct InnerTestView: View { let title: String let borderColor: Color var body: some View { ZStack { Text(title) .padding() Rectangle() .stroke(borderColor) } .contentShape(Rectangle()) } } struct TestView: View { var body: some View { VStack(spacing: 0.0) { HStack(alignment: .top, spacing: 0.0) { InnerTestView(title: "Drop Zone 1", borderColor: .pink) .dropTarget(for: ItemType1.self, withTitle: "Drop Zone 1") InnerTestView(title: "Drop Zone 2", borderColor: .indigo) .dropTarget(for: ItemType2.self, withTitle: "Drop Zone 2") } InnerTestView(title: "Drop Zone 3", borderColor: .orange) .dropTarget(for: ItemType3.self, withTitle: "Drop Zone 3") } .contentShape(Rectangle()) .draggable(ItemType1(id: "Object 1")) } } struct ContentView: View { var body: some View { ScrollView { LazyVStack { TestView() TestView() InnerTestView(title: "Draggable 2", borderColor: .orange) .draggable(ItemType2(id: "Object 2")) InnerTestView(title: "Draggable 3", borderColor: .indigo) .draggable(ItemType3(id: "Object 3")) } .padding() } } } Transfer Representations: import UniformTypeIdentifiers import CoreTransferable extension UTType { static let itemType1 = UTType(exportedAs: "com.droptest.typeone") static let itemType2 = UTType(exportedAs: "com.droptest.typetwo") static let itemType3 = UTType(exportedAs: "com.droptest.typethree") } struct ItemType1: Codable, Transferable { var id: String public static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .itemType1) } } struct ItemType2: Codable, Transferable { var id: String public static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .itemType2) } } struct ItemType3: Codable, Transferable { var id: String public static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .itemType3) } }
3
0
130
4d
Using availablity checks with new .defaultWindowPlacement API
How can I use availability checks with the new defaultWindowPlacement API so I can ensure visionOS 2 users get the correct window placement and visionOS 1 users fall back to the old window placement mechanism? I have tried using if #available and @available in different ways, but end up with either an error that says control flow statements aren't allowed in SceneBuilders or that the return type of the two branches of my control flow statement do not match if I omit the SceneBuilder property. An example of how to use .defaultWindowPlacement with visionOS 1 support would be nice. Thank you!
1
0
142
6d
iOS 18 Translation API availability for UIKit
After reading the documentation for TranslationSession and other API methods I got an impression that it will not be possible to use the Translation API with UI elements built with UIKit. You don’t instantiate this class directly. Instead, you obtain an instance of it by adding a translationTask(_:action:) or translationTask(source:target:action:) function to the SwiftUI view containing the content you want to translate So the main question I have to the engineers of mentioned framework is will there be any support for UIKit or app developers will have to rewrite their apps in SwiftUI just to be able to use the Translation API?
1
1
212
4h
SwiftUI: listSectionSeparator not working on macOS
Hi, When I use 'listSectionSeparator' on hide the section separator on a List 'section', it works as expected on iOS, but doesn't have any effect on macOS. Is that a known issue? Are there any workarounds for this? Here's a basic reproducible example: import SwiftUI struct TestItem: Identifiable, Hashable { let id = UUID() let itemValue: Int var itemString: String { get { return "test \(itemValue)" } } } struct TestListSelection: View { let testArray = [TestItem(itemValue: 1), TestItem(itemValue: 2), TestItem(itemValue: 3), TestItem(itemValue: 4)] @State private var selectedItem: TestItem? = nil var body: some View { List (selection: $selectedItem) { Section("Header") { ForEach (testArray, id: \.self) { item in Button { print("main row tapped for \(item.itemValue)") } label: { HStack { Text(item.itemString) Spacer() Button("Tap me") { print("button tapped") } .buttonStyle(.borderless) } } .buttonStyle(.plain) } } .listSectionSeparator(.hidden) // has no effect on macOS Section("2nd Header") { ForEach (testArray, id: \.self) { item in Text(item.itemString) } } .listSectionSeparator(.hidden) // has no effect on macOS } .listStyle(.plain) } } #Preview { TestListSelection() }
0
1
80
1w
Crash After Presenting SwiftUI Alert
I’m seeing a crash in production for a small percentage of users, and have narrowed it down based on logging to happening as or very shortly after an alert is presented using SwiftUI. This seems to be isolated to iOS 17.5.1, but since it’s a low-volume crash I can’t be sure there aren’t other affected versions. What can I understand from the crash report? Here’s a simplified version of the code which presents the alert, which seems so simple I can’t understand why it would crash. And following that is the crash trace. // View (simplified) @MainActor public struct MyView: View { @ObservedObject var model: MyViewModel public init(model: MyViewModel) { self.model = model } public var body: some View { myViewContent .overlay(clearAlert) } var clearAlert: some View { EmptyView().alert( "Are You Sure?", isPresented: $model.isClearAlertVisible, actions: { Button("Keep", role: .cancel) { model.clearAlertKeepButtonWasPressed() } Button("Delete", role: .destructive) { model.clearAlertDeleteButtonWasPressed() } }, message: { Text("This cannot be undone.") } ) } } // Model (simplified) @MainActor public final class MyViewModel: ObservableObject { @Published var isClearAlertVisible = false func clearButtonWasPressed() { isClearAlertVisible = true } func clearAlertKeepButtonWasPressed() { // No-op. } func clearAlertDeleteButtonWasPressed() { // Calls other code. } } Incident Identifier: 36D05FF3-C64E-4327-8589-D8951C8BAFC4 Distributor ID: com.apple.AppStore Hardware Model: iPhone13,2 Process: My App [379] Path: /private/var/containers/Bundle/Application/B589E780-96B2-4A5F-8FCD-8B34F2024595/My App.app/My App Identifier: com.me.MyApp Version: 1.0 (1) AppStoreTools: 15F31e AppVariant: 1:iPhone13,2:15 Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.me.MyApp [583] Date/Time: 2024-06-21 20:09:20.9767 -0500 Launch Time: 2024-06-20 18:41:01.7542 -0500 OS Version: iPhone OS 17.5.1 (21F90) Release Type: User Baseband Version: 4.50.06 Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000001a69998c0 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [379] Triggered by Thread: 0 Kernel Triage: VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter Thread 0 name: Thread 0 Crashed: 0 libswiftCore.dylib 0x00000001a69998c0 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:144) 1 AttributeGraph 0x00000001d0cd61a4 Attribute.init<A>(body:value:flags:update:) + 352 (Attribute.swift:473) 2 SwiftUI 0x00000001ac034054 closure #1 in Attribute.init<A>(_:) + 128 (<compiler-generated>:0) 3 SwiftUI 0x00000001ac033cac partial apply for closure #1 in Attribute.init<A>(_:) + 32 (<compiler-generated>:0) 4 libswiftCore.dylib 0x00000001a6ad0450 withUnsafePointer<A, B>(to:_:) + 28 (LifetimeManager.swift:128) 5 SwiftUI 0x00000001ad624d14 closure #2 in UIKitDialogBridge.startTrackingUpdates(actions:) + 268 (UIKitDialogBridge.swift:370) 6 SwiftUI 0x00000001ad624ae0 UIKitDialogBridge.startTrackingUpdates(actions:) + 248 (UIKitDialogBridge.swift:369) 7 SwiftUI 0x00000001ad6250cc closure #4 in UIKitDialogBridge.showNewAlert(_:id:) + 72 (UIKitDialogBridge.swift:471) 8 SwiftUI 0x00000001abfdd050 thunk for @escaping @callee_guaranteed () -> () + 36 (:-1) 9 UIKitCore 0x00000001aa5722e4 -[UIPresentationController transitionDidFinish:] + 1096 (UIPresentationController.m:651) 10 UIKitCore 0x00000001aa571d88 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.114 + 320 (UIPresentationController.m:1390) 11 UIKitCore 0x00000001aa5cb9ac -[_UIViewControllerTransitionContext completeTransition:] + 116 (UIViewControllerTransitioning.m:304) 12 UIKitCore 0x00000001aa34a91c __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 36 (UIView.m:16396) 13 UIKitCore 0x00000001aa34a800 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 624 (UIView.m:16429) 14 UIKitCore 0x00000001aa349518 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 436 (UIView.m:0) 15 UIKitCore 0x00000001aa356b14 -[UIViewAnimationState animationDidStop:finished:] + 192 (UIView.m:2400) 16 UIKitCore 0x00000001aa356b84 -[UIViewAnimationState animationDidStop:finished:] + 304 (UIView.m:2422) 17 QuartzCore 0x00000001a96f8c50 run_animation_callbacks(void*) + 132 (CALayer.mm:7714) 18 libdispatch.dylib 0x00000001aff61dd4 _dispatch_client_callout + 20 (object.m:576) 19 libdispatch.dylib 0x00000001aff705a4 _dispatch_main_queue_drain + 988 (queue.c:7898) 20 libdispatch.dylib 0x00000001aff701b8 _dispatch_main_queue_callback_4CF + 44 (queue.c:8058) 21 CoreFoundation 0x00000001a808f710 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1780) 22 CoreFoundation 0x00000001a808c914 __CFRunLoopRun + 1996 (CFRunLoop.c:3149) 23 CoreFoundation 0x00000001a808bcd8 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420) 24 GraphicsServices 0x00000001ecf3c1a8 GSEventRunModal + 164 (GSEvent.c:2196) 25 UIKitCore 0x00000001aa6c490c -[UIApplication _run] + 888 (UIApplication.m:3713) 26 UIKitCore 0x00000001aa7789d0 UIApplicationMain + 340 (UIApplication.m:5303) 27 SwiftUI 0x00000001ac27c148 closure #1 in KitRendererCommon(_:) + 168 (UIKitApp.swift:51) 28 SwiftUI 0x00000001ac228714 runApp<A>(_:) + 152 (UIKitApp.swift:14) 29 SwiftUI 0x00000001ac2344d0 static App.main() + 132 (App.swift:114) 30 My App 0x00000001001e7bfc static MyApp.$main() + 52 (MyApp.swift:0) 31 My App 0x00000001001e7bfc main + 64 32 dyld 0x00000001cb73de4c start + 2240 (dyldMain.cpp:1298)
2
0
124
1d
UIVisualEffectView isn't blurred during the device rotation
Hey everyone, I’m facing a bug when using UIVisualEffectView in a SwiftUI context via UIViewRepresentable. When the SwiftUI view modifier .blur(radius: xx, opaque: true) is applied to it during rotation, the blur effect isn’t applied. Instead, the view becomes completely white or black, depending on the UIBlurEffect.Style applied to the UIVisualEffectView. I’m not sure how to proceed with this issue and am seeking your help. Below is a simple, reproducible piece of code: import SwiftUI struct ContentView: View { var body: some View { ZStack { Circle() .fill(.pink) GlassBackgroundView() .blur(radius: 7, opaque: true) } .ignoresSafeArea() } } #Preview { ContentView() } private struct GlassBackgroundView: UIViewRepresentable { func makeUIView(context: Context) -> UIVisualEffectView { UIVisualEffectView(effect: UIBlurEffect(style: .regular)) } func updateUIView(_ uiView: UIVisualEffectView, context: Context) { } }
0
0
80
1w
SwiftUI onDrop not working with DropDelegate on iOS18
I am new to SwiftUI, and I wrote a ReorderableForEach struct with onDrag and onDrop, which is working well on iOS17. However it's not wokring on iOS18 beta1 or beta2 on my iPhone or simulator. When I long press the item, nothing happens. When I remove onDrop, I can perform a Drag animation, so I think something wrong with my onDrop code. the whole code: import UIKit import SwiftUI public typealias Reorderable = Identifiable & Equatable struct GridData: Identifiable, Equatable { let id: Int } public struct ReorderableForEach<Item: Reorderable, Content: View, Preview: View>: View { @Binding private var active: Item? @State private var hasChangedLocation = false private let items: [Item] private let content: (Item) -> Content private let preview: ((Item) -> Preview)? private let moveAction: (IndexSet, Int) -> Void private var onDropAction: ((Item) -> Void)? private var allowReorder: Bool public init( _ items: [Item], active: Binding<Item?>, allowReorder: Bool, @ViewBuilder content: @escaping (Item) -> Content, @ViewBuilder preview: @escaping (Item) -> Preview, moveAction: @escaping (IndexSet, Int) -> Void, onDropAction: ((Item) -> Void)? = nil ) { self.items = items self._active = active self.allowReorder = allowReorder self.content = content self.preview = preview self.moveAction = moveAction self.onDropAction = onDropAction } public init( _ items: [Item], active: Binding<Item?>, allowReorder: Bool, @ViewBuilder content: @escaping (Item) -> Content, moveAction: @escaping (IndexSet, Int) -> Void, onDropAction: ((Item) -> Void)? = nil ) where Preview == EmptyView { self.items = items self._active = active self.allowReorder = allowReorder self.content = content self.preview = nil self.moveAction = moveAction self.onDropAction = onDropAction } public var body: some View { ForEach(items) { item in if !allowReorder { contentView(for: item) } else if let preview { contentView(for: item) .onDrag { return dragData(for: item) } preview: { preview(item) } } else { contentView(for: item) .onDrag { return dragData(for: item) } } } } private func contentView(for item: Item) -> some View { content(item) .opacity(active == item && hasChangedLocation ? 0.5 : 1) .onDrop( of: [.text], delegate: ReorderableDragRelocateDelegate( item: item, items: items, active: $active, hasChangedLocation: $hasChangedLocation ) { from, to in withAnimation { moveAction(from, to) } } onDropAction: { item in onDropAction?(item) } ) } private func dragData(for item: Item) -> NSItemProvider { active = item return NSItemProvider(object: "\(item.id)" as NSString) } } struct ReorderableDragRelocateDelegate<Item: Reorderable>: DropDelegate { let item: Item var items: [Item] @Binding var active: Item? @Binding var hasChangedLocation: Bool var moveAction: (IndexSet, Int) -> Void var onDropAction: ((Item) -> Void)? func dropEntered(info: DropInfo) { guard item != active, let current = active else { return } guard let from = items.firstIndex(of: current) else { return } guard let to = items.firstIndex(of: item) else { return } hasChangedLocation = true if items[to] != current { moveAction(IndexSet(integer: from), to > from ? to + 1 : to) } } func dropUpdated(info: DropInfo) -> DropProposal? { DropProposal(operation: .move) } func performDrop(info: DropInfo) -> Bool { hasChangedLocation = false active = nil onDropAction?(item) return true } } struct ReorderableDropOutsideDelegate<Item: Reorderable>: DropDelegate { @Binding var active: Item? func dropUpdated(info: DropInfo) -> DropProposal? { DropProposal(operation: .move) } func performDrop(info: DropInfo) -> Bool { active = nil return true } } public extension View { func reorderableForEachContainer<Item: Reorderable>( active: Binding<Item?> ) -> some View { onDrop(of: [.text], delegate: ReorderableDropOutsideDelegate(active: active)) } } #Preview { ReorderableForEach( (1...10).map { GridData(id: $0) }, active: .constant(nil), allowReorder: true ) { item in Text("Item \(item.id)") .padding() .background(Color.blue) .cornerRadius(8) } preview: { item in Text("Preview \(item.id)") .padding() .background(Color.red) .cornerRadius(8) } moveAction: { from, to in print("Move from \(from) to \(to)") } } Am I missing something or this is a bug on iOS18? Thanks in advance.
1
0
92
1d
iOS18 beta2: NavigationStack, Views Being Popped Automatically
This is a report of an issue that appears to be a regression regarding NavigationStack. I have been aware of an issue where views are being automatically popped within NavigationView / NavigationStack since iOS 15, and it seems to be reoccurring in iOS 18.0 beta2. Below is the reproducible code. Additionally, in my environment, this problem does not occur iOS 18 simulator, but it does happen on an iPhone XS Max(real device) with iOS 18 beta 2. Environment: Xcode: Version 16.0 beta (16A5171c) iOS: 18.0 (22A5297f) iPhone: XS Max (real device) import SwiftUI @main struct iOS16_4NavigationSample2App: App { var body: some Scene { WindowGroup { NavigationStack { NavigationLink { ContentView() } label: { Text("Content") } } } } } enum Kind { case none, a, b, c } struct Value: Hashable, Identifiable { let id: UUID = UUID() var num: Int } @MainActor class ContentModel: ObservableObject { @Published var kind: Kind = .a @Published var vals: [Value] = { return (1...5).map { Value(num: $0) } }() init() {} } struct ContentView: View { @StateObject private var model = ContentModel() @State private var selectedData: Value? @State private var isShowingSubView = false @Environment(\.dismiss) private var dismiss init() { } var body: some View { if #available(iOS 16.0, *) { List(selection: $selectedData) { ForEach(model.vals) { val in NavigationLink(value: val) { Text("\(val.num)") } } } .navigationDestination(isPresented: .init(get: { selectedData != nil }, set: { newValue in if !newValue && selectedData != nil { selectedData = nil } }), destination: { SubView(kind: model.kind) }) } } } struct SubView: View { init(kind: Kind) { print("init(kind:)") } init() { print("init") } var body: some View { Text("Content") } } This code was shared in a different issue [iOS 16.4 NavigationStack Behavior Unstable].
7
1
199
1d
Can an automaker app and a Carplay app (when automaker is not possible) live in the same App?
Hi, I'm trying to investigate if there is any way to have an app that displays an automaker app when the Carplay environment has the automaker protocol string, and displays a Carplay App (Driving Task) when there isn't the automaker protocol string. I was able to start developing an automaker app, but with an iOS16.0 deprecated method (with UIScreen Notifications), I'm not able to do it via the scene delegate... There is any kind of documentation of how to do it? I think the clue may be in the scene delegate with the property Preferred Default Scene Session Role, where I think the automaker app is a Window Application Session Role, but the scene delegate is not triggered when I open the Carplay App in the simulator. So am I missing something? Is there a way to do it or have I to publish two apps in order to use the two kind of carplay apps... ? Thank you very much.
1
0
98
1w
Is it possible to loop a ScrollView to repeat infinitely?
I have a horizontal scroll view and a fixed array. I would like to loop it such that when I scroll left and get near the end, the array will add the items in the beginning to the end so that the user can continue to scroll. I would like this to happen when scrolling both left and right and to not have the current position of the user jump around. Here is my code. What am I missing? Would appreciate any and all help. import SwiftUI import Algorithms struct ContentView: View { @State private var timePosition = ScrollPosition(idType: Int.self, edge: .leading) @State private var times: [Int] = Array(0...23) var body: some View { ScrollView(.horizontal, showsIndicators: false) { LazyHStack(spacing: 0) { ForEach(times, id:\.self) { time in Text("\(time)") .font(.system(.callout, design: .monospaced, weight: .semibold)) .padding(8) .frame(width: 180, height: 110, alignment: .topLeading) .border(width: 1, edges: [.leading, .trailing], color: .primary.opacity(0.05)) .id(time) } } .scrollTargetLayout() } .frame(height: 110) .scrollPosition($timeScrollPosition, anchor: .center) .onScrollTargetVisibilityChange(idType: Int.self) { timeIDs in if let currentViewID = model.timeScrollPosition.viewID { if timeIDs.contains(times[times.count - 2]) { times.rotate(toStartAt: times.count - 1) } if timeIDs.contains(times[1]) { times.rotate(toStartAt: times.count-1) } print("New times: \(times)") timeScrollPosition.scrollTo(id: currentViewID) } } } }
0
0
87
1w
Obscuration of Specific Content in Screenshots on visionOS
Hello, I am currently developing an app using visionOS, and I am looking for a way to obscure specific content in screenshots. My app includes certain content that is exclusive to premium users, and I need to hide these parts when screenshots are shared on social media. In iOS, I was able to achieve this by extending SecureField to hide specific Views or Images, but this method does not work in visionOS. I am seeking advice on the best approach to implement this feature in visionOS. https://github.com/yoxisem544/ScreenshotPreventing-iOS Specifically, I would appreciate guidance on the following points: The optimal method for obscuring specific Views or Images in screenshots on visionOS Any tips or tricks when using existing components similar to SecureField Techniques or approaches used by other developers to implement similar features Your assistance would be greatly appreciated. Thank you for your help.
0
0
96
1w
Pop to root view when selected tab is tapped again for WebKit
Hello everyone! I have a WKWebView in my swiftui app and would like to enable to "pop root view when selected tab is tapped again" feature, but I have been unable to figure out how to implement this. Here's the basic code: class TabIdentifierModel:ObservableObject { @Published var tabSelection:TabIdentifier { willSet { if newValue == tabSelection { NotificationCenter.default.post(name: .popRootView, object: nil, userInfo: ["tab": newValue.rawValue]) } } } init() { tabSelection = .home } } struct ContentView: View { @AppStorage(AppStorageKeys.enableShorts) var enableShorts = true @StateObject var storeVM = StoreVM() @StateObject var downloadURLManager = DownloadURLManager.shared @State var downloadViewIsOpen = false // ...... @State var tabSelection = TabIdentifierModel() var body: some View { TabView(selection: $tabSelection.tabSelection) { // ...... WebViewWrapper(url: $libraryTabURL) .tabItem { Label { Text("Library") } icon: { Image(systemName: "folder.fill") } }.tag(TabIdentifier.library) // ...... } .environmentObject(tabSelection) } } Tapping on the tab again doesn't seem to set the value again thus the NotificationCenter.default.post is not sent and the web view is not reloaded. Help would be much appreciated! Thanks in advance!
0
0
92
1w