Is it possible to rebuild overlay only and not the body?

Hi. I am not sure how to do this case scenario I am having.

Please see sample code

@State private var tileLayers: [GMSURLTileLayer]?   
@State private var isShowingLegend = true
   
var body: some View {
    MapView(
      tileLayers: tileLayers
    )
    .task {
      setupMenuItems()
       
      if load {
        load = false
        processRainWatcher()
      }
    }
    .overlay(
      isShowingLegend ?
        HStack {
          RainWatcherLegendView()
          Spacer()
        }
        .transition(.move(edge: isShowingLegend ? .leading : .trailing))
      : nil,
      alignment: .bottom
    )
}

This is not a working code. But i wish to ask suggestion. because the overlay shows a legend view. If isShowingLegend.toggle() is triggered, it animates sliding in and out of the screen.

Problem mis, everything gets rebuilt. so the tile layer in the MapView() gets re-rendered again.

is there a way not to let this happen, but still let the legend animate sliding in and out?

or perhaps pass a binding variable to the legend view? and do the animation in that view? so that the parent view does not get rebuilt?

thoughts?

Answered by chitgoks in 737944022

Use state binding in the child view.

Guess the solution is to use state and binding (in the child view)

Accepted Answer

Use state binding in the child view.

Is it possible to rebuild overlay only and not the body?
 
 
Q