Where to place floating buttons to move up/down based on presented sheet dynamic height?

72 Views Asked by At

I'm new to SwiftUI. I want to place a floating button on Map, but this needs to move based on bottom presenting sheet. Bottom present sheet height will be dynamic and it will minimise and maximise based on swipe up/down.

Here is the images for your reference:

enter image description here enter image description here

Here is the sample code:

Map {
       Annotation("", coordinate: CLLocationCoordinate2D(latitude: Double(deviceViewModel.currentDevice.lat) ?? 0,
                                                                  longitude: Double(deviceViewModel.currentDevice.lng) ?? 0)) {
            DropPinView(deviceViewModel: deviceViewModel)
         }
     }
     .sheet(isPresented: .constant(true)) {
        MapTabSheetView()
           .presentationDetents([.fraction(0.1), .fraction(0.3)])
           .presentationCornerRadius(32)
           .presentationDragIndicator(.automatic)
           .presentationBackgroundInteraction(.enabled(upThrough: .fraction(0.3)))
           .interactiveDismissDisabled()
     }
1

There are 1 best solutions below

0
lorem ipsum On

You can make them a part of the sheet then just make the background clear.

.presentationBackground(content: {
                    Color.clear
                })
.presentationDragIndicator(.hidden)

Here is an example.

import SwiftUI
import MapKit
struct MapSetupView: View {
    var body: some View {
        Map()
            .sheet(isPresented: .constant(true)) {
                VStack {
                    //Buttons
                    HStack {
                        Button("", systemImage: "person") {
                            
                        }.buttonStyle(.borderedProminent)
                        Spacer()
                        Button("", systemImage: "checkmark") {
                            
                        }.buttonStyle(.borderedProminent)
                    }.frame(height: 50)
                    //Sheet
                    RoundedRectangle(cornerRadius: 10)
                        .fill(Color(UIColor.systemBackground))
                        .shadow(radius: 5)
                }
                .presentationDetents([.fraction(0.2), .large])
                
                .presentationBackground(content: {
                    Color.clear
                })
                .presentationDragIndicator(.hidden)
                .ignoresSafeArea()
            }
    }
}

#Preview {
    MapSetupView()
}