swift posts

Subscribe to just swift posts via RSS.

Fixing Scroll Indicators in Non-Opaque WKWebViews

Update: Since this post was published, the situation has changed and the workaround presented here is no longer valid. See the follow-up.

Here’s a stupid bug I ran into recently: if you’ve got a WKWebView in an iOS app and it shows something that’s not a normal webpage[1], the scroll indicator appearance switching doesn’t work. What I mean by that is, while the indicators appear correctly (with a dark color) when the system is in light mode, they do not take on a light color when dark mode is enabled. This renders the scroll indicators invisible against dark backgrounds, which can be annoying if you’re using the web view to display potentially lengthy content.

Automatically Changing Scroll Direction Based on USB Devices

Last time I wrote about programmatically toggling natural scrolling on macOS and building a menu bar app to let me do that quickly. It works very well, but there’s still a little bit of friction with having to click the menu bar icon—or, more accurately, forgetting to click it and then scrolling backwards and realizing you forgot. As I mentioned at the end of my previous post, one obvious way to extend it, now that the ability to programmatically set direction is in place, would be toggling it automatically based on what’s currently connected. This turned out to not be terribly complicated, but dealing with IOKit was somewhat annoying, so I thought I’d write it up.

A Mac Menu Bar App to Toggle Natural Scrolling

There are two ways you can configure the scroll direction on a computer: normal or inverted (what Apple calls “natural”). If you, like most, use a mouse with a wheel, the normal scrolling scheme is probably what you use. Under it, moving the mouse wheel down (i.e., so that a point on the top of the wheel moves down/closer to you) causes the content to move up and the viewport (the window into the content) to move down. Similarly on a multitouch trackpad, under normal scrolling, as your two fingers move down, the content moves up and the viewport down.

The other option—natural scrolling—flips this, so as your fingers move down on the trackpad, the content moves down and viewport moves up, and similarly for rotating the mouse wheel. When using a mouse, this feels to most people obviously backwards. But this setting doesn’t exist without reason. It’s transposing the paradigm of touchscreens on to the trackpad, where your finger remains pinned to the point in the content where you first touched. You move the content directly, rather than moving the viewport.

This generally isn’t a big deal; most people just find the mode they prefer, change the setting, and then never touch it again. But what if you prefer both?

On SwiftUI

Over the past several days, I built a complete, functioning app in SwiftUI, and, well, I have some thoughts.

Debugging My Gemini NWProtocolFramer Implementation

I recently ran into an issue with the Network.framework Gemini client I’d previously implemented that turned out to be somewhat perplexing. So, I thought I’d write a brief post about it in case anyone finds it interesting or helpful.