Skip to content

Commit

Permalink
Make toolbar menu prefer fixed menu order
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Jun 15, 2023
1 parent ece1e33 commit 675f9e1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
14 changes: 13 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ Until then, deprecated features may be removed in the next minor version.



## 0.7.3

This version makes keyboard toolbar menu prefer fixed menu order.



## 0.7.2

This version adjusts the tweaks the new color picker component a little.



## 0.7.1

This version tweaks the new color picker component a little.



## 0.7
Expand Down
3 changes: 2 additions & 1 deletion Sources/RichTextKit/Data/RichTextDataReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private extension RichTextDataReader {
func richTextArchivedData() throws -> Data {
try NSKeyedArchiver.archivedData(
withRootObject: richText,
requiringSecureCoding: false)
requiringSecureCoding: false
)
}

/**
Expand Down
46 changes: 44 additions & 2 deletions Sources/RichTextKit/Keyboard/RichTextKeyboardToolbarMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import SwiftUI

The glitch is that the menu label can be incorrectly offset
vertically, beyound the bounds of the menu. If that happens,
use this view instead to ensure that the label is correctly
positioned.
use this view to ensure that it's correctly positioned.
*/
public struct RichTextKeyboardToolbarMenu<Label: View, Content: View>: View {

Expand All @@ -40,7 +39,50 @@ public struct RichTextKeyboardToolbarMenu<Label: View, Content: View>: View {
} label: {
label().opacity(0)
}
.preferesMenuOrderFixed()
.background(label())
}
}

private extension Menu {

@ViewBuilder
func preferesMenuOrderFixed() -> some View {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
self.menuOrder(.fixed)
} else {
self
}
}
}

struct RichTextKeyboardToolbarMenu_Previews: PreviewProvider {

@ViewBuilder
static var buttons: some View {
Button("1") {}
Button("2") {}
Button("3") {}
}

static var previews: some View {
RichTextKeyboardToolbarMenu {
if #available(iOS 15.0, *) {
Section("Title") {
buttons
}
Section {
ControlGroup {
buttons
}
}
} else {
buttons
}
} label: {
Label("Menu", systemImage: "ellipsis.circle")
}

}
}
#endif

0 comments on commit 675f9e1

Please sign in to comment.