commit 4a332c7ffaa939e0178b06c27170c1e98ac68791
parent 616f730ae5cc83b0059203c0a6fa1df109b4ab4b
Author: William Casarin <jb55@jb55.com>
Date: Sun, 14 Jul 2024 20:13:57 -0700
simplify CustomPicker and fix ios18 runtime error
This fixes a reflection runtime error for our custom picker
Fixes: https://github.com/damus-io/damus/issues/2332
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
6 files changed, 31 insertions(+), 43 deletions(-)
diff --git a/damus/Components/CustomPicker.swift b/damus/Components/CustomPicker.swift
@@ -12,31 +12,25 @@ let RECTANGLE_GRADIENT = LinearGradient(gradient: Gradient(colors: [
DamusColors.blue
]), startPoint: .leading, endPoint: .trailing)
-struct CustomPicker<SelectionValue: Hashable, Content: View>: View {
+struct CustomPicker<SelectionValue: Hashable>: View {
+ let tabs: [(String, SelectionValue)]
@Environment(\.colorScheme) var colorScheme
-
+
@Namespace var picker
@Binding var selection: SelectionValue
- @ViewBuilder let content: Content
-
+
public var body: some View {
- let contentMirror = Mirror(reflecting: content)
- let blocksCount = Mirror(reflecting: contentMirror.descendant("value")!).children.count
HStack {
- ForEach(0..<blocksCount, id: \.self) { index in
- let tupleBlock = contentMirror.descendant("value", ".\(index)")
- let text = Mirror(reflecting: tupleBlock!).descendant("content") as! Text
- let tag = Mirror(reflecting: tupleBlock!).descendant("modifier", "value", "tagged") as! SelectionValue
-
+ ForEach(tabs, id: \.1) { (text, tag) in
Button {
withAnimation(.spring()) {
selection = tag
}
} label: {
- text
- .padding(EdgeInsets(top: 15, leading: 0, bottom: 10, trailing: 0))
+ Text(text).padding(EdgeInsets(top: 15, leading: 0, bottom: 10, trailing: 0))
.font(.system(size: 14, weight: .heavy))
+ .tag(tag)
}
.background(
Group {
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -127,10 +127,12 @@ struct ContentView: View {
}
.safeAreaInset(edge: .top, spacing: 0) {
VStack(spacing: 0) {
- CustomPicker(selection: $filter_state, content: {
- Text("Notes", comment: "Label for filter for seeing only notes (instead of notes and replies).").tag(FilterState.posts)
- Text("Notes & Replies", comment: "Label for filter for seeing notes and replies (instead of only notes).").tag(FilterState.posts_and_replies)
- })
+ CustomPicker(tabs:
+ [("Notes", FilterState.posts),
+ ("Notes & Replies", FilterState.posts_and_replies)
+ ],
+ selection: $filter_state)
+
Divider()
.frame(height: 1)
}
diff --git a/damus/Views/DirectMessagesView.swift b/damus/Views/DirectMessagesView.swift
@@ -72,13 +72,11 @@ struct DirectMessagesView: View {
var body: some View {
VStack(spacing: 0) {
- CustomPicker(selection: $dm_type, content: {
- Text("DMs", comment: "Picker option for DM selector for seeing only DMs that have been responded to. DM is the English abbreviation for Direct Message.")
- .tag(DMType.friend)
- Text("Requests", comment: "Picker option for DM selector for seeing only message requests (DMs that someone else sent the user which has not been responded to yet). DM is the English abbreviation for Direct Message.")
- .tag(DMType.rando)
- })
-
+ CustomPicker(tabs: [
+ ("DMs", DMType.friend),
+ ("Requests", DMType.rando),
+ ], selection: $dm_type)
+
Divider()
.frame(height: 1)
diff --git a/damus/Views/FollowingView.swift b/damus/Views/FollowingView.swift
@@ -160,10 +160,10 @@ struct FollowingView: View {
.navigationBarTitle(NSLocalizedString("Following", comment: "Navigation bar title for view that shows who a user is following."))
.safeAreaInset(edge: .top, spacing: 0) {
VStack(spacing: 0) {
- CustomPicker(selection: $tab_selection, content: {
- Text("People", comment: "Label for filter for seeing only people follows.").tag(FollowingViewTabSelection.people)
- Text("Hashtags", comment: "Label for filter for seeing only hashtag follows.").tag(FollowingViewTabSelection.hashtags)
- })
+ CustomPicker(tabs: [
+ ("People", FollowingViewTabSelection.people),
+ ("Hashtags",FollowingViewTabSelection.hashtags)
+ ], selection: $tab_selection)
Divider()
.frame(height: 1)
}
diff --git a/damus/Views/Notifications/NotificationsView.swift b/damus/Views/Notifications/NotificationsView.swift
@@ -117,17 +117,11 @@ struct NotificationsView: View {
}
.safeAreaInset(edge: .top, spacing: 0) {
VStack(spacing: 0) {
- CustomPicker(selection: $filter_state, content: {
- Text("All", comment: "Label for filter for all notifications.")
- .tag(NotificationFilterState.all)
-
- Text("Zaps", comment: "Label for filter for zap notifications.")
- .tag(NotificationFilterState.zaps)
-
- Text("Mentions", comment: "Label for filter for seeing mention notifications (replies, etc).")
- .tag(NotificationFilterState.replies)
-
- })
+ CustomPicker(tabs: [
+ ("All", NotificationFilterState.all),
+ ("Zaps", NotificationFilterState.zaps),
+ ("Mentions", NotificationFilterState.replies),
+ ], selection: $filter_state)
Divider()
.frame(height: 1)
}
diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift
@@ -434,10 +434,10 @@ struct ProfileView: View {
aboutSection
VStack(spacing: 0) {
- CustomPicker(selection: $filter_state, content: {
- Text("Notes", comment: "Label for filter for seeing only your notes (instead of notes and replies).").tag(FilterState.posts)
- Text("Notes & Replies", comment: "Label for filter for seeing your notes and replies (instead of only your notes).").tag(FilterState.posts_and_replies)
- })
+ CustomPicker(tabs: [
+ ("Notes", FilterState.posts),
+ ("Notes & Replies", FilterState.posts_and_replies)
+ ], selection: $filter_state)
Divider()
.frame(height: 1)
}