Post

Replies

Boosts

Views

Activity

Reply to .sheet no longer dismissable in WatchOS 7?
The fix is actually much simpler (at least for me running watchOS 10). If you embed your sheet view in a navigation stack like this, there will be a little circular "X" button at the top left of your sheet. MyMainView() .sheet { NavigationStack { MySheetView() } } As it turns out, the default cancel button is embedded in the toolbar, and the toolbar doesn't show up at all unless your view is embedded in a navigation stack
Oct ’23
Reply to In SwiftUI on macOS, how to make a scroll wheel scroll horizontally?
Fixed here: import AppKit struct CaptureVerticalScrollWheelModifier: ViewModifier { func body(content: Content) -> some View { content .background(ScrollWheelHandlerView()) } struct ScrollWheelHandlerView: NSViewRepresentable { func makeNSView(context: Context) -> NSView { let view = ScrollWheelReceivingView() return view } func updateNSView(_ nsView: NSView, context: Context) {} } class ScrollWheelReceivingView: NSView { private var scrollVelocity: CGFloat = 0 private var decelerationTimer: Timer? override var acceptsFirstResponder: Bool { true } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() window?.makeFirstResponder(self) } override func scrollWheel(with event: NSEvent) { var scrollDist = event.deltaX var scrollDelta = event.scrollingDeltaX if abs(scrollDist) < abs(event.deltaY) { scrollDist = event.deltaY scrollDelta = event.scrollingDeltaY } if event.phase == .began || event.phase == .changed || event.phase.rawValue == 0 { // Directly handle scrolling handleScroll(with: scrollDist, precise: event.hasPreciseScrollingDeltas) scrollVelocity = scrollDelta } else if event.phase == .ended { // Begin decelerating decelerationTimer = Timer.scheduledTimer(withTimeInterval: 0.016, repeats: true) { [weak self] timer in guard let self = self else { timer.invalidate(); return } self.decelerateScroll() } } else if event.momentumPhase == .ended { // Invalidate the timer if momentum scrolling has ended decelerationTimer?.invalidate() decelerationTimer = nil } } private func handleScroll(with delta: CGFloat, precise: Bool) { var scrollDist = delta if !precise { scrollDist *= 2 } guard let scrollView = self.enclosingScrollView else { return } let contentView = scrollView.contentView let contentSize = contentView.documentRect.size let scrollViewSize = scrollView.bounds.size let currentPoint = contentView.bounds.origin var newX = currentPoint.x - scrollDist // Calculate the maximum allowable X position (right edge of content) let maxX = contentSize.width - scrollViewSize.width // Ensure newX does not exceed the bounds newX = max(newX, 0) // No less than 0 (left edge) newX = min(newX, maxX) // No more than maxX (right edge) // Scroll to the new X position if it's within the bounds scrollView.contentView.scroll(to: NSPoint(x: newX, y: currentPoint.y)) scrollView.reflectScrolledClipView(scrollView.contentView) } private func decelerateScroll() { if abs(scrollVelocity) < 0.8 { decelerationTimer?.invalidate() decelerationTimer = nil return } handleScroll(with: scrollVelocity, precise: true) scrollVelocity *= 0.95 } } } extension View { func captureVerticalScrollWheel() -> some View { self.modifier(CaptureVerticalScrollWheelModifier()) } }
Mar ’24
Reply to NWParemeters.requiredLocalEndpoint is ignored in VisionOS
Unfortunately I don't have a real device to confirm and won't have the funds to get one anytime soon, but your asking did make me recheck and I found some interesting behavior. Working on iOS Real Device iPad, iPhone (Uses port 6970) Working on macOS Real Device (Uses port 6970) Not working on iOS Simulator (Uses random port) Not working on VisionOS Simulator (Uses random port) I thought I had already checked and it worked on iOS simulator, but I guess I mis-remembered. I'll consider this closed for now until I get a VisionOS bug report saying that it's an issue there on real devices.
Mar ’24
Reply to No Devices Registered Error tvOS
This response is incorrect. Currently there isn't a way to publish an tvOS app to the App Store or even archive the app without owning an Apple TV. You can however build and test your application on the simulator without owning an Apple TV. Interestingly enough, this isn't a requirement with visionOS as of now (and hopefully, fingers crossed it won't be added).
Mar ’24