I'm trying to use the new (announced at WWDC 2023 and available in iOS 17 and macOS 14) API to observe scroll position of SwiftUI ScrollView.
I have the following view, but I can't make it work correctly. That is, using the scrollPosition(id:anchor) view modifier makes the scroll view go nuts. At some point, and in some cases even at the very beginning, the scroll view just starts jumping and is stuttering when trying to scroll. See the screen recording here: https://mastodon.social/@tomkraina/111249340792812592
The code:
struct ContentView: View {
private var itemSize: CGSize = .init(width: 50.0, height: 50.0)
// Annotated as @State to create the sections only once
@State private var sectionData = makeSections()
// Tracking scroll position
@State private var currentItemID: MyIdentifier?
var currentItemDescription: String { self.currentItemID?.stringId ?? "nil" }
var body: some View {
VStack {
// 1. Scroll View
ScrollView(.vertical) {
LazyVGrid(
columns: [.init(.adaptive(minimum: self.itemSize.width), spacing: Constants.columnSpacing, alignment: .center)],
alignment: .center,
spacing: Constants.sectionSpacing
) {
ForEach(self.sectionData) { section in
Section(section.title) {
ForEach(section.items) { item in
Text(item.text)
.frame(width: self.itemSize.width, height: self.itemSize.height)
}
}
}
}
.scrollTargetLayout()
}
.scrollPosition(id: self.$currentItemID) // TODO: Comment out this line to make the scrolling work
Divider()
// 2. Settings
Group {
Label(
title: { Text(self.currentItemDescription) },
icon: { Image(systemName: "42.circle") }
)
}
.padding()
}
#if os(macOS)
.frame(width: 320, height: 480, alignment: .center)
#endif
}
}
The whole code can be found in my GitHub repo: https://github.com/tomaskraina/feedbackassistant.apple.com/blob/master/ScrollPositionVsLazyVGrid/ScrollPositionVsLazyVGrid/ContentView.swift
Am I doing something wrong or is this a bug in SwiftUI?
Post
Replies
Boosts
Views
Activity
I have a problem with presenting the new find panel in an iPad app when Stage Manager is enabled. This happens both on device as well as in Simulator.
The problem is that UIFindInteraction’s find panel only flicks (appears and disappears in a fraction of second) and thus is not usable for actually searching anything.
Presumably, this is a UIKit bug. Has anyone found a way around it?
I'm attaching a link to a demo project that does nothing special:
setting isFindInteractionEnabled = true on a UITextView
preseting the find panel via textView.findInteraction?.presentFindNavigator(showingReplace: false)
https://github.com/tomaskraina/feedbackassistant.apple.com/tree/master/UIFindInteraction-StageManager-UIKit
e.g. via a keyboard shortcut? That would be really helpful when debugging.
Or is it possible to show the Quick Note window only on iPad with Pencil by swiping from the bottom right corner of the screen?
I'm trying to adopt Quick Note in a document-based app. Has anyone got the "Add Link" button to show up for documents located in iCloud?
For local documents, the button works but then userInfo dictionary is missing from the continued NSUserActivity...
I have prepared an Xcode project that demonstrates the issue, available here on GitHub with a README describing what I have tried and what's not working in more detail:
https://github.com/tomaskraina/feedbackassistant.apple.com/tree/master/QuickNote-UIDocumentVsUserActivity
UIContextMenuInteraction got a new property with iOS 14 for "Specifying Menu Appearance" (that's the name of the section in the docs):
https://developer.apple.com/documentation/uikit/uicontextmenuinteraction?changes=latest_minor
However, this property is ready-only! Is it read only by design or mistake? If it's by design, why the name of the section in the docs suggests we're able to specify the menu appearance?