4

I'm trying to have a button which when pressed animates into anther button to press again to confirm. I would like to be able to dismiss this then (and revert to the original button) by touching anywhere outside the new button. (eg anywhere on the screen).

I thought I could archive this by placing a (transparent) absolute overlay on the entire screen. (I know I can do this if my dismisser is the outer most view, but that is not what I want, since I would like to make this a simple drop in component eg a DismissableButton or something.)

So basically I'm looking for something like CSS's fixed position.

How can I achieve this? This (simplified is basically my current setup)

var body: some View {
        
        return Group {
            if (!self.showConfirmation) {
                self.initialButton
            } else {
                ZStack {
                    self.dismisser // So I thought either position this absolute in regards to the screen with full height and width
                    self.confirmButton // Or if there's some way to attach an gesture recogniser that registers touches outside of it
                }
            }
        }
        
    }
Matthijn
  • 3,126
  • 9
  • 46
  • 69
  • 1
    The idea from https://stackoverflow.com/a/63259094/12299030 should be helpful... it is not a duplicate but something close. – Asperi Oct 26 '20 at 19:41
  • This is [how you can dismiss a view from the presented view itself](https://stackoverflow.com/a/63909251/5623035) (like alerts) – Mojtaba Hosseini Oct 26 '20 at 20:12
  • The scenario is ambiguous. Is this body of root view, or a view that can be placed anywhere in view hierarchy? For SwiftUI it is important to clarify. – Asperi Oct 29 '20 at 15:51
  • It's not the root body, then it would be easy. I want one of the nested views displayed relative to the screen (or main window on Mac OS) (eg 0,0) would be top left of screen, not top left of the parent view. – Matthijn Oct 30 '20 at 13:58
  • Can express yourself with some images at least ? – Mojtaba Hosseini Oct 30 '20 at 17:49

0 Answers0