Hi everyone
I am fighting with a weird problem
in my app I use swiftui and ai do not use tabs, but a hierarchy of view created by me that switch one to the other with a slide animation when I tap one of the elements
i don't use gesture, but only ontap.
The same app launched on two different iPhone has two different behaviours
on the iPhone 11 no problem, the animation is fluid and responsive, on the iPhone 10 I got some delay, and in the console I can read Gesture: System gesture gate timed out
I have searched but I have not found anything useful and more than this it is extremely difficult to find some info about this warning/error
How can I solve this?
on the iPhone 10 it seems like the animation got stuck for 1 seconds prior to be executed in the correct way
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I've discovered an issue with using iOS 16's Transferable drag-and-drop APIs for SwiftUI. The dropDestination modifier does not work when applied to a subview of a List.
This code below will not work, unless you replace the List with a VStack or any other container (which, of course, removes all list-specific rendering).
The draggable modifier will still work and the item will drag, but the dropDestination view won't react to it and neither closure will be called.
struct MyView: View {
var body: some View {
List {
Section {
Text("drag this title")
.font(.largeTitle)
.draggable("a title")
}
Section {
Color.pink
.frame(width: 400, height: 400)
.dropDestination(for: String.self) { receivedTitles, location in
true
} isTargeted: {
print($0)
}
}
}
}
}
Has anyone encountered this bug and perhaps found a workaround?
Hello and thanks for reading my post.
I have a SwiftUI view, the users should be able to click a button and take printout of that view. Clicking on the button should open the standard print sheet (select printer, pages, layout, etc.).
How can I implement such a functionality? I have been trying hard without any success. Please help.
It is an iPad app, using Xcode 14.3
I'm in the process of migrating to the Observation framework but it seems like it is not compatible with didSet. I cannot find information about if this is just not supported or a new approach needs to be implemented?
import Observation
@Observable class MySettings {
var windowSize: CGSize = .zero
var isInFullscreen = false
var scalingMode: ScalingMode = .scaled {
didSet {
...
}
}
...
}
This code triggers this error:
Instance member 'scalingMode' cannot be used on type 'MySettings'; did you mean to use a value of this type instead?
Anyone knows what needs to be done? Thanks!
I am using a LayzVStack embedded into a ScrollView. The list items are fetched from a core data store by using a @FetchResult or I tested it also with the new @Query command coming with SwiftData.
The list has one hundred items 1, 2, 3, ..., 100.
The user scrolled the ScrollView so that items 50, 51, ... 60 are visible on screen.
Now new data will be fetched from the server and updates the CoreData or SwiftData model. When I add new items to the end of the list (e.g 101, 102, 103, ...) then the ScrollView is keeping its position.
Opposite to this when I add new items to the top (0, -1, -2, -3, ...) then the ScrollView scrolls down.
Is there a way with the new SwiftData and SwiftUI ScrollView modifiers to update my list model without scrolling like with UIKit where you can query and set the scroll offset pixel wise?
When I update a variable inside my model that is marked @Transient, my view does not update with this change. Is this normal? If I update a non-transient variable inside the model at the same time that I update the transient one, then both changes are propagated to my view.
Here is an example of the model:
@Model public class WaterData {
public var target: Double = 3000
@Transient public var samples: [HKQuantitySample] = []
}
Updating samples only does not propagate to my view.
So I am trying to move an old project from ios16 to ios17... wanted to play around with the new previews, and animations and first error I get is the above.
When I create a new project I can use the macro just fine.
What is more: when I add a new swiftUI file I get the same error with the #Preview macro.
I went through the project and target settings, making sure everything is set to ios17 and Swift5, but can't find any other settings. Cleared the build cache and rebuilt from scratch.
Hoping someone else ran onto the same problem and found a solution?
Without using #Preview
Is it possible to specify a default window size for a 2D window in visionOS? I know this is normally achieved by modifying the WindowGroup with .defaultSize(width:height:), but I get an error that this was not included in "xrOS". I am able to specify .defaultSize(width:height:depth:) for a volumetric window, but this doesn't have any effect when applied to a 2D one.
Hi. The binding in a ForEach or List view doesn't work anymore when using the @Observable macro to create the observable object. For example, the following are the modifications I introduced to the Apple's example called "Migrating from the Observable Object Protocol to the Observable Macro" https://developer.apple.com/documentation/swiftui/migrating-from-the-observable-object-protocol-to-the-observable-macro
struct LibraryView: View {
@Environment(Library.self) private var library
var body: some View {
List($library.books) { $book in
BookView(book: book)
}
}
}
All I did was to add the $ to turn the reference to library.books into a binding but I got the error "Cannot find '$library' in scope"
Is this a bug or the procedure to use binding in lists changed?
Thanks
Apple docs for RealityView state:
You can also use the optional update closure on your RealityView to update your RealityKit content in response to changes in your view’s state."
Unfortunately, I've not been able to get this to work.
All of my 3D content is programmatically generated - I'm not using any external 3D modeling tools. I have an object that conforms to @ObservableObject. Its @Published variables define the size of a programmatically created Entity. Using the initializer values of these @Published variables, the 1st rendering of the RealityView { content in } works like a charm.
Basic structure is this:
var body: some View {
RealityView { content in
// create original 3D content using initial values of @Published variables - works perfect
} update: { content in
// modify 3D content in response to changes of @Published variables - never works
}
Debug statements show that the update: closure gets called as expected - based upon changes in the viewModel's @Published variables. However, the 3D content never changes - even though the 3D content is based upon the @Published variables.
Obviously, if the @Published variables are used in the 1st rendering, and the update: closure is called whenever changes occur to these @Published variables, then why isn't the update: closure updating the RealityKit content as described in the Apple docs?
I've tried everything I can think of - including removing all objects in the update: closure and replacing them with the same call that populated them in the 1st rendering. Debug statements show that the new @Published values are correct as expected when the update: closure is called, but the RealityView never changes.
Known limitation of the beta? Programmer error? Thoughts?
I am working on creating a file viewer to browse a network directory as a way to introduce myself to iOS app development, and was trying to implement a feature that would allow users to drag and drop both files and folders onto another folder inside of the app to move items around. However, it seems that if the View that is set to draggable, and then the view that is set as the Drop Destination is in the same List, then the Drop Destination will not detect when the draggable view has been dropped onto it. Here is the structure of my code:
List {
Section(header: Text("Folders")) {
ForEach($folders, id: \.id) { $folder in
FolderCardView()
.onDrop(of: [UTType.item], isTargeted: $fileDropTargeted, perform: { (folders, cgPoint) -> Bool in
print("Dropped")
return true
})
}
}
Section(header: Text("Files")) {
ForEach($files, id: \.id) { $file in
FileCardView()
.onDrag({
let folderProvider = NSItemProvider(object: file)
return folderProvider
})
}
}
}
I have verified that the issue comes down to the list, because if I move both of the ForEach loops out on their own, or even into their own respective lists, the code works perfectly. I have not only tested this with the older .onDrop and .onDrag modifiers as shown above, but also the newer .draggable and .dropDestination modifiers, and the result is the same.
Does anyone know if this is intended behavior? I really like the default styling that the List element applies to other elements within, so I am hoping that it might just be a bug or an oversight. Thanks!
Hi,
I'm trying to build iOS app, but I found out that .onPreferenceChange has strange behaviour if the view contains an if statement below view which sets .preference.
Here is an repository with minimal reproduction: https://github.com/Mordred/swiftui-preference-key-bug
There should be displayed title text on the top and bottom of the screen. But the bottom is empty.
If you delete if statement if true { at https://github.com/Mordred/swiftui-preference-key-bug/blob/main/PreferenceKeyBug/PreferenceKeyBug.swift then it works fine.
Please update charts framework to have z axis for 3D plotting
Hi,
In the visionOS documentation
Positioning and sizing windows - Specify initial window position
In visionOS, the system places new windows directly in front of people, where they happen to be gazing at the moment the window opens.
Positioning and sizing windows - Specify window resizability
In visionOS, the system enforces a standard minimum and maximum size for all windows, regardless of the content they contain.
The first thing I don't understand is why it talk about macOS in visionOS documentation.
The second thing, what is this page for if it's just to tell us that on visionOS we have no control over the position and size of 2D windows. Whereas it is precisely the opposite that would be interesting. I don't understand this limitation. It limits so much the use of 2D windows under visionOS.
I really hope that this limitation will disappear in future betas.
My usage of TextField.focused() works fine in Xcode 14.3.1 but is broken as of Xcode 15. I first noticed it in the second beta and it's still broken as of the 4th beta.
Feedback / OpenRadar # FB12432084
import SwiftUI
struct ContentView: View {
@State private var text = ""
@FocusState var isFocused: Bool
var body: some View {
ScrollView {
TextField("Test", text: $text)
.textFieldStyle(.roundedBorder)
.focused($isFocused)
Text("Text Field Is Focused: \(isFocused.description)")
}
}
}
SwiftUI Buttons in a List no longer highlight when tapped. Seems to have stopped highlighting after iOS 16.0 I've only tested on an iPhone/simulators so not sure if iPad has the same issue.
The issue has been carried over to iOS 17 Beta 4. My app does not feel Apple like as there is no visual feedback for the user when a button in the list is pressed.
Does anyone know why this is occurring? Is this a bug on Apple's end?
I have an app that uses RealityKit and ARKit, which includes some capturing features (to capture and image with added Entities). I have a navigationLink that allows the user to see the gallery of the images he has taken.
When launching the App, the rotation animation of the ARView happens smoothly, the navigationBar transitions from one orientation to another with the ARView keeping it's orientation.
However, when I go to the galeryView to see the images and go back to the root view where the ARView is, the rotation animation of the ARView changed:
When transitioning from one orientation to another, the ARView is flipped by 90° before transitioning to the new orientation.
The issue is shown in this gif (https://i.stack.imgur.com/IOvCx.gif)
Any idea why this happens and how I could resolve it without locking the App's orientation changes?
Thanks!
My SwiftUI code runs fine on macOS, iOS(iPad) and larger iPhones, but will not display the detail view on smaller iPhones.
Is there a way to force the smaller iPhones to display the detail view?
And if not,
When I put the App on the Apple store, for sale, will the Apple store be smart enough to flag the App as not appropriate for smaller iPhones, such as the SE (2nd and 3rd gen.) and prevent downloads?
Thanks in advance for any guidance.
I have a regular SwiftUI View embedded inside of a NavigationStack. In this view, I make use of the .searchable() view modifier to make that view searchable. I have a button on the toolbar placed on the .confirmationAction section, which is a problem when a User types into the search bar and the button gets replaced by the SearchBar's cancel button.
Thus, I conditionally place the button, depending on whether a User is searching, either on the navigationBar or on the keyboard. The latter does not work however, as the button does not show and when trying to debug the View Hierarchy, Xcode throws an error saying the View Hierarchy could not be displayed. If I set the button to be on the .bottomBar instead, it shows up perfectly and the View Hierarchy also displays with no further issue.
Has someone come across this issue and if so, how did you get it fixed?
Thank you in advance.
I'm using Xcode 14.3.1 on macOS 13.5, and I've managed to reproduce my issue in a trivial application. All the project settings are left at the defaults for a macOS project.
It looks like using a GroupBox breaks the ability of XCTest to find popovers connected to buttons (I suspect any UI element) inside the GroupBox.
The debug console output from the code below lists 15 descendants from my window with the outside-the-GroupBox popover open, and one of them is definitely a popover. With the inside-the-GroupBox popover open, my window only shows nine descendants, and no popover (the rest of the difference is the popover's contents). It's simple enough I don't see what I could be doing wrong:
import SwiftUI
@main
struct GroupBox_Popover_DemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State var outsidePopoverPresented: Bool = false
@State var insidePopoverPresented: Bool = false
var body: some View {
VStack {
Button("Outside GroupBox") {
outsidePopoverPresented = true
}
.popover(isPresented: $outsidePopoverPresented,
attachmentAnchor: .point(.leading),
arrowEdge: .leading) {
Popover(selected: .constant("Item A"), isPresented: $outsidePopoverPresented)
}
.padding()
GroupBox {
Button("Inside GroupBox") {
insidePopoverPresented = true
}
.popover(isPresented: $insidePopoverPresented,
attachmentAnchor: .point(.leading),
arrowEdge: .leading) {
Popover(selected: .constant("Item B"), isPresented: $insidePopoverPresented)
}
.padding()
}
}
.padding()
}
}
struct Popover: View {
@Binding var selected: String
@Binding var isPresented: Bool
var body: some View {
VStack(alignment: .leading) {
Picker("", selection: $selected) {
Text("Item A").tag("Item A")
Text("Item B").tag("Item B")
Text("Item C").tag("Item C")
}
.pickerStyle(.radioGroup)
HStack {
Spacer()
Button("Cancel") {
isPresented = false
}
}
}
.padding()
.frame(width: 200)
}
}
Then in my UI tests:
import XCTest
final class GroupBox_Popover_DemoUITests: XCTestCase {
let mainWindow = XCUIApplication().windows
override func setUpWithError() throws {
continueAfterFailure = false
XCUIApplication().launch()
}
func testPopovers() {
let myDescendants = mainWindow.descendants(matching: .any)
mainWindow.buttons["Outside GroupBox"].click()
print("Window descendants with outside popover open:")
print(myDescendants.debugDescription)
mainWindow.popovers.buttons["Cancel"].click()
mainWindow.buttons["Inside GroupBox"].click()
print("Window descendants with inside popover open:")
print(myDescendants.debugDescription)
mainWindow.popovers.buttons["Cancel"].click()
XCTAssert(true, "Test was able to hit cancel on both popovers.")
}
}
Any ideas? Have I missed unchecking some "Ignore anything in a GroupBox" checkbox somewhere?