Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Created February 6, 2020 13:17
Show Gist options
  • Save Thomvis/cf4d492ee7352d64825bc3d5767d15d2 to your computer and use it in GitHub Desktop.
Save Thomvis/cf4d492ee7352d64825bc3d5767d15d2 to your computer and use it in GitHub Desktop.

Revisions

  1. Thomvis created this gist Feb 6, 2020.
    10 changes: 10 additions & 0 deletions onPreferenceChangeWorkAround.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    content
    .onPreferenceChange(SizeKey.self, perform: { sizes in
    // this is not always called
    })
    .overlayPreferenceValue(SizeKey.self) { sizes in
    EmptyView().onAppear {
    // this is called more reliably
    // the view's id controls for which changes this is called
    }.id(sizes.map { $0.width*1000+$0.height })
    }