Advertisement
IbrahimHassan

Untitled

Feb 3rd, 2022 (edited)
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 7.59 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. import Introspect
  4. // TODO: install `SwiftUI-Introspect` package from https://github.com/siteline/SwiftUI-Introspect
  5.  
  6. // --------------------------------------------------------------------------------
  7. // EditMembersViewController
  8. // --------------------------------------------------------------------------------
  9. struct EditMembersView: View {
  10.     @State private var items = ["1", "2"]
  11.     @State private var selectedItem: String?
  12.     // TODO: Replace the `minimumValue` below from the conversion result of UICollectionViewCell xib
  13.     let gridLayout = [GridItem(.adaptive(minimum: 150), spacing: 8)]
  14.     @State private var collectionViewItems = ["1", "2"]
  15.    
  16.     var body: some View {
  17.         NavigationView {
  18.             ZStack(alignment: .topLeading) {
  19.                 GeometryReader { geometry in
  20.                     ScrollView {
  21.                         ZStack(alignment: .topLeading) {
  22.                             GeometryReader { geometry in
  23.                                 Text("GROUP MEMBERS")
  24.                                     .frame(dynamicWidth: 414, dynamicHeight: 40, alignment: .leading)
  25.                                     .font(.custom(".AppleSystemUIFont", size: 13))
  26.                                     .background(Color(.groupTableViewBackground))
  27.                                
  28.                                 ScrollView(.vertical) {
  29.                                     LazyVGrid(columns: gridLayout, spacing: 8) {
  30.                                         ForEach(items, id: \.self) { item in
  31.                                             // No UICollectionViewCell cell found in the storyboard
  32.                                             // If you have added the UICollectionViewCell through a `xib`, please convert the `xib` and use the result here.
  33.                                         }
  34.                                     }
  35.                                 }
  36.                                 .frame(dynamicWidth: 398, dynamicHeight: 92)
  37.                                 .background(Color.red)
  38.                                 .clipped()
  39.                                 .offset(dynamicX: 8, dynamicY: 40)
  40.                                
  41.                                 Text("ALL USERS")
  42.                                     .frame(dynamicWidth: 414, dynamicHeight: 40, alignment: .leading)
  43.                                     .font(.custom(".AppleSystemUIFont", size: 13))
  44.                                     .background(Color(.groupTableViewBackground))
  45.                                     .offset(dynamicX: 0, dynamicY: 132)
  46.                                
  47.                                 List {
  48.                                     Section(footer: EditMembersViewControllerListFooterView()) {
  49.                                         ForEach(items, id: \.self) { item in
  50.                                             CustomTableViewCell()
  51.                                                 .listRowInsets(EdgeInsets())
  52.                                                 .contentShape(Rectangle())
  53.                                         }
  54.                                     }
  55.                                 }
  56.                                 .introspectTableView(customize: { tableView in
  57.                                     tableView.alwaysBounceHorizontal = true
  58.                                     tableView.alwaysBounceVertical = true
  59.                                     tableView.clipsToBounds = true
  60.                                 })
  61.                                 .frame(dynamicWidth: 414, dynamicHeight: 488)
  62.                                 .listStyle(.plain)
  63.                                 .offset(dynamicX: 0, dynamicY: 172)
  64.                             }
  65.                         }
  66.                         .frame(dynamicWidth: 414, dynamicHeight: 660)
  67.                     }
  68.                     .clipped()
  69.                     .frame(dynamicWidth: 414, dynamicHeight: 660)
  70. //                    .offset(dynamicX: 0, dynamicY: 56)
  71.                 }
  72.             }
  73. //            .frame(dynamicWidth: 414, dynamicHeight: 716)
  74. //            .edgesIgnoringSafeArea(.all)
  75.             .navigationTitle("Edit Members")
  76.             .navigationBarTitleDisplayMode(.automatic)
  77.             .navigationBarItems(leading: Button(action: {}) {
  78.                 Text("Cancel")
  79.             },
  80.             trailing: Button(action: {}) {
  81.                 Text("Save")
  82.             })
  83.         }
  84.     }
  85. }
  86.  
  87. struct EditMembersView_Previews: PreviewProvider {
  88.     static var previews: some View {
  89.         EditMembersView()
  90.             .previewDevice(PreviewDevice(rawValue: "iPhone 8 Plus"))
  91.             .previewInterfaceOrientation(.portrait)
  92.             .preferredColorScheme(.light)
  93.     }
  94. }
  95.  
  96. // --------------------------------------------------------------------------------
  97. // EditMembersViewControllerListFooterView
  98. // --------------------------------------------------------------------------------
  99. struct EditMembersViewControllerListFooterView: View {
  100.     var body: some View {
  101.         ZStack(content: {})
  102.             .frame(dynamicWidth: 414, dynamicHeight: 100)
  103.             .listRowInsets(EdgeInsets())
  104.             .background(Color.blue)
  105.     }
  106. }
  107.  
  108. // --------------------------------------------------------------------------------
  109. // Dynamic Size Helper
  110. // --------------------------------------------------------------------------------
  111. struct DynamicSize {
  112.     static private let baseViewWidth: CGFloat = 414.0
  113.     static private let baseViewHeight: CGFloat = 716.0
  114.  
  115.     static func getHeight(_ height: CGFloat) -> CGFloat {
  116.         return (height / baseViewHeight) * UIScreen.main.bounds.height
  117.     }
  118.  
  119.     static func getWidth(_ width: CGFloat) -> CGFloat {
  120.         return (width / baseViewWidth) * UIScreen.main.bounds.width
  121.     }
  122.  
  123.     static func getOffsetX(_ x: CGFloat) -> CGFloat {
  124.         return (x / baseViewWidth) * UIScreen.main.bounds.width
  125.     }
  126.  
  127.     static func getOffsetY(_ y: CGFloat) -> CGFloat {
  128.         return (y / baseViewHeight) * UIScreen.main.bounds.height
  129.     }
  130. }
  131.  
  132. // --------------------------------------------------------------------------------
  133. // Frame and Offset Helper
  134. // --------------------------------------------------------------------------------
  135. extension View {
  136.     func frame(dynamicWidth: CGFloat? = nil, dynamicHeight: CGFloat? = nil, alignment: Alignment = .center) -> some View {
  137.         frame(
  138.             width: DynamicSize.getWidth(dynamicWidth ?? 0),
  139.             height: DynamicSize.getHeight(dynamicHeight ?? 0),
  140.             alignment: alignment)
  141.     }
  142.  
  143.     func offset(dynamicX: CGFloat = 0, dynamicY: CGFloat = 0) -> some View {
  144.         offset(x: DynamicSize.getOffsetX(dynamicX), y: DynamicSize.getOffsetY(dynamicY))
  145.     }
  146. }
  147.  
  148. // --------------------------------------------------------------------------------
  149. // CustomTableViewCell
  150. // --------------------------------------------------------------------------------
  151. struct CustomTableViewCell: View {
  152.     var body: some View {
  153.         ZStack(alignment: .topLeading) {
  154.             GeometryReader { geometry in
  155.                 Text("Test")
  156.                     .frame(dynamicWidth: 374, dynamicHeight: 360, alignment: .center)
  157.                     .font(.system(size: 52, weight: .regular))
  158.                     .multilineTextAlignment(.center)
  159.                     .foregroundColor(Color(white: 1.0))
  160.                     .background(Color(red: 0.7176471, green: 0.60784316, blue: 0.49411765))
  161.                     .offset(dynamicX: 20, dynamicY: 20)
  162.             }
  163.         }
  164.         .frame(dynamicWidth: 414, dynamicHeight: 400)
  165.         .background(Color(.systemPink))
  166.     }
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement