summaryrefslogtreecommitdiff
path: root/makima/ios/Sources/Makima/Design/Components/JapaneseLongPressText.swift
diff options
context:
space:
mode:
Diffstat (limited to 'makima/ios/Sources/Makima/Design/Components/JapaneseLongPressText.swift')
-rw-r--r--makima/ios/Sources/Makima/Design/Components/JapaneseLongPressText.swift37
1 files changed, 37 insertions, 0 deletions
diff --git a/makima/ios/Sources/Makima/Design/Components/JapaneseLongPressText.swift b/makima/ios/Sources/Makima/Design/Components/JapaneseLongPressText.swift
new file mode 100644
index 0000000..fb57154
--- /dev/null
+++ b/makima/ios/Sources/Makima/Design/Components/JapaneseLongPressText.swift
@@ -0,0 +1,37 @@
+import SwiftUI
+
+/// Mobile-native equivalent of the web's `JapaneseHoverText`.
+/// Shows the Japanese term; long-press (or tap) reveals the English gloss
+/// via a brief animated flip.
+struct JapaneseLongPressText: View {
+ let japanese: String
+ let english: String
+
+ @State private var revealed = false
+
+ var body: some View {
+ HStack(spacing: 6) {
+ Text(japanese)
+ .font(Typography.japanese)
+ .foregroundStyle(Palette.foreground)
+ .padding(.vertical, 3)
+ .padding(.horizontal, 6)
+ .background(Palette.panel)
+ .overlay(
+ Rectangle().strokeBorder(Palette.borderMuted, lineWidth: 1)
+ )
+ .contentShape(Rectangle())
+ .onTapGesture { withAnimation(.easeInOut(duration: 0.2)) { revealed.toggle() } }
+ .onLongPressGesture(minimumDuration: 0.15, pressing: { pressing in
+ withAnimation(.easeInOut(duration: 0.15)) { revealed = pressing }
+ }, perform: {})
+
+ Text(english)
+ .font(Typography.navLabel)
+ .foregroundStyle(revealed ? Palette.accent : Palette.foregroundMuted.opacity(0.4))
+ .animation(.easeInOut(duration: 0.2), value: revealed)
+ }
+ .accessibilityElement(children: .combine)
+ .accessibilityLabel("\(japanese), \(english)")
+ }
+}