Fix Compose toolbar not displaying on Catalyst and visionOS
This commit is contained in:
parent
ae226508b0
commit
618dc78fe9
@ -77,14 +77,21 @@ struct FocusedInputModifier: ViewModifier {
|
||||
// This property wrapper abstracts over them both.
|
||||
@propertyWrapper
|
||||
struct FocusedInput: DynamicProperty {
|
||||
@Environment(\.toolbarInjectedFocusedInputBox) private var box
|
||||
@FocusedValue(\.composeInput) private var input
|
||||
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
||||
@Environment(\.toolbarInjectedFocusedInputBox) private var box
|
||||
@StateObject private var updater = Updater()
|
||||
#endif
|
||||
|
||||
var wrappedValue: (any ComposeInput)? {
|
||||
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
||||
box?.wrappedValue ?? input ?? nil
|
||||
#else
|
||||
input ?? nil
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
||||
func update() {
|
||||
updater.update(box: box)
|
||||
}
|
||||
@ -98,4 +105,5 @@ struct FocusedInput: DynamicProperty {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ public struct ComposeView: View {
|
||||
)
|
||||
.environment(\.composeUIConfig, config)
|
||||
.environment(\.currentAccount, currentAccount)
|
||||
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
||||
.injectInputAccessoryHost(state: state, mastodonController: mastodonController, focusedField: $focusedField)
|
||||
#endif
|
||||
.onReceive(NotificationCenter.default.publisher(for: .NSManagedObjectContextObjectsDidChange, object: DraftsPersistentContainer.shared.viewContext), perform: self.managedObjectsDidChange)
|
||||
}
|
||||
|
||||
@ -160,17 +162,23 @@ private struct ComposeViewBody: View {
|
||||
|
||||
// When we're using the input accessory toolbar, hide the overlay toolbar so that,
|
||||
// on iPad, we don't get two toolbars showing.
|
||||
#if targetEnvironment(macCatalyst) || os(visionOS)
|
||||
let showOverlayToolbar = true
|
||||
#else
|
||||
let showOverlayToolbar = if #available(iOS 16.0, *) {
|
||||
focusedField == nil
|
||||
} else {
|
||||
true
|
||||
}
|
||||
#endif
|
||||
|
||||
if config.showToolbar,
|
||||
showOverlayToolbar {
|
||||
toolbarView
|
||||
.frame(maxHeight: .infinity, alignment: .bottom)
|
||||
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
||||
.modifier(IgnoreKeyboardSafeAreaIfUsingInputAccessory())
|
||||
#endif
|
||||
.transition(.move(edge: .bottom))
|
||||
.animation(.snappy, value: config.showToolbar)
|
||||
}
|
||||
@ -307,6 +315,7 @@ private struct ToolbarSafeAreaInsetModifier: ViewModifier {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !targetEnvironment(macCatalyst) && !os(visionOS)
|
||||
private struct IgnoreKeyboardSafeAreaIfUsingInputAccessory: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
if #available(iOS 16.0, *) {
|
||||
@ -419,6 +428,7 @@ private struct InputAccessoryToolbarView: View {
|
||||
.tint(accentColor.color.map(Color.init(uiColor:)))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//#Preview {
|
||||
// ComposeView()
|
||||
|
@ -92,7 +92,6 @@ private struct LanguageButtonStyle: ButtonStyle {
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS, obsoleted: 16.0)
|
||||
private struct LanguageButtonStyleAnimationModifier: ViewModifier {
|
||||
let isPressed: Bool
|
||||
|
||||
|
@ -64,11 +64,11 @@ struct EmojiTextField: UIViewRepresentable {
|
||||
|
||||
#if !os(visionOS)
|
||||
uiView.backgroundColor = colorScheme == .dark ? UIColor(fillColor) : .secondarySystemBackground
|
||||
#endif
|
||||
|
||||
if uiView.inputAccessoryView !== inputAccessoryToolbarHost {
|
||||
uiView.inputAccessoryView = inputAccessoryToolbarHost
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
|
@ -95,9 +95,11 @@ private struct NewMainTextViewRepresentable: UIViewRepresentable {
|
||||
// uiView.backgroundColor = colorScheme == .dark ? UIColor(fillColor) : .secondarySystemBackground
|
||||
// #endif
|
||||
|
||||
#if !os(visionOS)
|
||||
if uiView.inputAccessoryView !== inputAccessoryToolbarHost {
|
||||
uiView.inputAccessoryView = inputAccessoryToolbarHost
|
||||
}
|
||||
#endif
|
||||
|
||||
// Trying to set this with the @FocusState binding in onAppear results in the
|
||||
// keyboard not appearing until after the sheet presentation animation completes :/
|
||||
|
@ -59,7 +59,9 @@ public struct MenuPicker<Value: Hashable>: UIViewRepresentable {
|
||||
#if targetEnvironment(macCatalyst)
|
||||
config.macIdiomStyle = .bordered
|
||||
#endif
|
||||
#if !os(visionOS)
|
||||
config.contentInsets = .zero
|
||||
#endif
|
||||
return config
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user