Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. ######
  2. The code that is called in my app.app
  3. ######
  4.  
  5. struct ContentView: View {
  6. var body: some View {
  7.  
  8. TabView {
  9. ContactsView()
  10. .tabItem {
  11. VStack {
  12. Image(systemName: "house.fill")
  13. Text("Messages")
  14. }
  15. }
  16.  
  17. Text("Second View")
  18. .tabItem {
  19. Image(systemName: "phone")
  20. Text("Dialer")
  21. }
  22.  
  23. Text("Third View")
  24. .tabItem {
  25. Image(systemName: "star")
  26. Text("Favourits")
  27. }
  28.  
  29. Text("Fourth View")
  30. .tabItem {
  31. Image(systemName: "person.2")
  32. Text("Presence")
  33. }
  34.  
  35. Text("Fifth View")
  36. .tabItem {
  37. Image(systemName: "ellipsis")
  38. Text("More")
  39. }
  40. }
  41.  
  42. }
  43. }
  44.  
  45. ######
  46. contactview
  47. ######
  48.  
  49. struct ContactsView: View {
  50. @State private var searchText = ""
  51. @State private var users: [User] = randomAccounts
  52.  
  53. var body: some View {
  54.  
  55. VStack {
  56. TenantListView(userList: users)
  57.  
  58. ContactListView(searchText: searchText, userList: users)
  59. }
  60.  
  61.  
  62. }
  63. }
  64.  
  65. ######
  66. contactlistview
  67. ######
  68.  
  69. struct ContactListView: View {
  70. @State private var searchText: String
  71. @State private var showSearchBar = false
  72. var userList: [User]
  73.  
  74. init(searchText: String, userList: [User]) {
  75. self.searchText = searchText
  76. self.userList = userList
  77. }
  78.  
  79. var body: some View {
  80. NavigationStack {
  81. List(searchResults, id: \.self) { username in
  82. if let user = userList.first(where: { $0.username == username }) {
  83. NavigationLink(destination: ChatView(user: user)) {
  84. HStack {
  85. Image(user.imageName)
  86. .resizable()
  87. .frame(width: 40, height: 40)
  88. .overlay(Circle().stroke(Color.gray, lineWidth: 2))
  89.  
  90. VStack(alignment: .leading) {
  91. Text(user.username)
  92. Text("\(user.number)")
  93. .font(.caption)
  94. }
  95. }
  96. }
  97. .padding(.horizontal)
  98. }
  99. }
  100. .listStyle(.plain)
  101. }
  102.  
  103. .searchable(text: $searchText, placement: .toolbar) {
  104. ForEach(searchResults, id: \.self) { result in
  105. Text("Are you looking for \(result)?").searchCompletion(result)
  106. }
  107. }
  108. }
  109.  
  110. var searchResults: [String] {
  111. if searchText.isEmpty {
  112. return userList.map { $0.username } // Return an array of usernames
  113. } else {
  114. return userList.filter { $0.username.contains(searchText) }
  115. .map { $0.username } // Return an array of filtered usernames
  116. }
  117. }
  118.  
  119. }
  120.  
  121. ######
  122. tenantlistview
  123. ######
  124.  
  125. struct TenantListView: View {
  126. var userList: [User]
  127.  
  128. init(userList: [User]) {
  129. self.userList = userList
  130. }
  131. var body: some View {
  132. HStack {
  133. ScrollView(.horizontal, showsIndicators: false) {
  134. HStack {
  135. ToolbarItem(name: "Me")
  136. .padding(.horizontal, 5)
  137. ForEach(userList, id: \.username) { user in
  138. ToolbarItem(name: "\(user.username)")
  139. }
  140. }
  141. }
  142. .mask(HorizontalGradientMask())
  143.  
  144. NavigationLink(destination: AccountDetailView()) {
  145. Image("avataaars")
  146. .resizable()
  147. .frame(width: 40, height: 40)
  148. .overlay(Circle().stroke(Color.gray, lineWidth: 2))
  149. .padding()
  150. }
  151.  
  152.  
  153. }
  154. .background(Color("XelionGreenish"))
  155. }
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement