This commit adds a highlighting extension for web pages. This works on Safari, and can be used by selecting a text on a page and hitting the share button at the bottom of the Safari UI To make this possible, some refactoring was necessary: 1. Several sources were included in the extension bundle to provide access to DamusState, PostView, and the postbox 2. UIApplication.shared was replaced with `this_app`, which routes to UIApplication.shared on the main app bundle, and routes to a bogus UIApplication() in the extension. This is needed because UIApplication.shared cannot be used on an extension. 3. Some items were moved to different files to facilitate the transition. The extension itself uses PostView, and implements views for several edge cases, and tries to handle the note publishing process gracefully. Changelog-Added: Add highlighter for web pages Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
41 lines
833 B
Swift
41 lines
833 B
Swift
//
|
|
// InputDismissKeyboard.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2022-07-02.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
public extension View {
|
|
func dismissKeyboardOnTap() -> some View {
|
|
modifier(DismissKeyboardOnTap())
|
|
}
|
|
}
|
|
|
|
public struct DismissKeyboardOnTap: ViewModifier {
|
|
public func body(content: Content) -> some View {
|
|
#if os(macOS)
|
|
return content
|
|
#else
|
|
return content.gesture(tapGesture)
|
|
#endif
|
|
}
|
|
|
|
private var tapGesture: some Gesture {
|
|
TapGesture().onEnded(end_editing)
|
|
}
|
|
|
|
}
|
|
|
|
public func end_editing() {
|
|
this_app.connectedScenes
|
|
.filter {$0.activationState == .foregroundActive}
|
|
.map {$0 as? UIWindowScene}
|
|
.compactMap({$0})
|
|
.first?.windows
|
|
.filter {$0.isKeyWindow}
|
|
.first?.endEditing(true)
|
|
}
|