| @@ -805,12 +805,20 @@ struct EditorTextView: UIViewRepresentable { |
| 805 | let palette: () -> Void |
805 | let palette: () -> Void |
| 806 | |
806 | |
| 807 | func makeUIView(context: Context) -> UITextView { |
807 | func makeUIView(context: Context) -> UITextView { |
| 808 | let bar = UIHostingController(rootView: KeyBar(editor: editor, palette: palette)) |
808 | let bar = UIHostingController(rootView: KeyBar(editor: editor, palette: palette).dynamicTypeSize(...KeyBar.largestSize)) |
| 809 | bar.view.frame = CGRect(x: 0, y: 0, width: 400, height: 48) |
809 | bar.view.frame = CGRect(x: 0, y: 0, width: 400, height: 2 * KeyBar.padding + KeyBar.target) |
| 810 | bar.view.backgroundColor = .clear |
810 | bar.view.backgroundColor = .clear |
| 811 | bar.sizingOptions = [] |
811 | // As tall as its buttons: the input accessory takes the intrinsic height. |
| |
812 | bar.sizingOptions = .intrinsicContentSize |
| |
813 | bar.safeAreaRegions = [] |
| |
814 | bar.view.autoresizingMask = .flexibleHeight |
| 812 | view.inputAccessoryView = bar.view |
815 | view.inputAccessoryView = bar.view |
| 813 | context.coordinator.bar = bar |
816 | context.coordinator.bar = bar |
| |
817 | // The bar's height follows the text size. |
| |
818 | view.registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (view: UITextView, _) in |
| |
819 | view.inputAccessoryView?.invalidateIntrinsicContentSize() |
| |
820 | view.reloadInputViews() |
| |
821 | } |
| 814 | return view |
822 | return view |
| 815 | } |
823 | } |
| 816 | |
824 | |
| @@ -852,6 +860,12 @@ struct KeyBar: View { |
| 852 | ("Code", "chevron.left.forwardslash.chevron.right", "org.emphasize.code"), |
860 | ("Code", "chevron.left.forwardslash.chevron.right", "org.emphasize.code"), |
| 853 | ] |
861 | ] |
| 854 | |
862 | |
| |
863 | /// The bar's buttons are at least 44 points square, scaled with the text size up to here. |
| |
864 | static let largestSize = DynamicTypeSize.accessibility2 |
| |
865 | static let target: CGFloat = 44 |
| |
866 | static let padding: CGFloat = 4 |
| |
867 | @ScaledMetric(relativeTo: .body) private var size = KeyBar.target |
| |
868 | |
| 855 | var body: some View { |
869 | var body: some View { |
| 856 | ScrollView(.horizontal, showsIndicators: false) { |
870 | ScrollView(.horizontal, showsIndicators: false) { |
| 857 | HStack(spacing: 4) { |
871 | HStack(spacing: 4) { |
| @@ -870,14 +884,29 @@ struct KeyBar: View { |
| 870 | Button("Hide keyboard", systemImage: "keyboard.chevron.compact.down") { editor.textView.resignFirstResponder() } |
884 | Button("Hide keyboard", systemImage: "keyboard.chevron.compact.down") { editor.textView.resignFirstResponder() } |
| 871 | } |
885 | } |
| 872 | .labelStyle(.iconOnly) |
886 | .labelStyle(.iconOnly) |
| 873 | .buttonStyle(.bordered) |
887 | .buttonStyle(KeyStyle(size: size)) |
| 874 | .padding(.horizontal, 8) |
888 | .padding(.horizontal, 8) |
| 875 | .padding(.vertical, 6) |
889 | .padding(.vertical, Self.padding) |
| 876 | } |
890 | } |
| 877 | .background(.bar) |
891 | .background(.bar) |
| 878 | } |
892 | } |
| 879 | } |
893 | } |
| 880 | |
894 | |
| |
895 | /// A key bar button: a tinted symbol on a capsule, at least `size` square. |
| |
896 | private struct KeyStyle: ButtonStyle { |
| |
897 | let size: CGFloat |
| |
898 | |
| |
899 | func makeBody(configuration: Configuration) -> some View { |
| |
900 | configuration.label |
| |
901 | .foregroundStyle(.tint) |
| |
902 | .padding(.horizontal, 10) |
| |
903 | .frame(minWidth: size, minHeight: size) |
| |
904 | .background(.fill.tertiary, in: .capsule) |
| |
905 | .opacity(configuration.isPressed ? 0.5 : 1) |
| |
906 | .contentShape(.capsule) |
| |
907 | } |
| |
908 | } |
| |
909 | |
| 881 | /// A command's question: text with choices, a date, or fast selection by keys. |
910 | /// A command's question: text with choices, a date, or fast selection by keys. |
| 882 | struct PromptSheet: View { |
911 | struct PromptSheet: View { |
| 883 | let prompt: Prompt |
912 | let prompt: Prompt |