# Trouble with getting a sheet to slide into view

**URL:** <https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081>\
**Category:** Swift\
**Created:** [June 20, 2024, 5:05pm UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081 "2024-06-20T17:05:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanec](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/seanec/32/105896_2.png) [@seanec](https://forums.kodeco.com/u/seanec)\
**Post date:** [June 20, 2024, 5:05pm UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/1 "2024-06-20T17:05:21Z")

</div>

I am putting an app together that consists of several buttons. To help clean code I created a view for the buttons and did all the design on them there. I then created a background view to lay out the buttons that will be seen when contentView loads. I created a State variable in my background view and added my .sheet code (see below) but when I click on it I do not get a sheet sliding in. I am not seeing what I am missing so any guidance would be greatly appreciated. The view the sheet should display is called Wetlab104. So when I click the button I would like the sheet for that room to appear.

///swift  
struct BackgroundView: View {  
@State private var Wetlab104IsShowing = false  
@State private var rm105IsShowing = false  
var body: some View {  
VStack {  
HStack {  
Button {  
Wetlab104IsShowing = true  
} label: {  
ButtonView(text: “Rm 104”)  
}  
.sheet(isPresented: $Wetlab104IsShowing) {  
Wetlab104()  
}  
Spacer()  
Button {  
rm105IsShowing = true  
} label: {  
ButtonView(text: “Rm 105”)  
}  
.sheet(isPresented: $rm105IsShowing) {  
Wetlab105()  
}  
}  
HStack {  
Button {  
// show room 107  
} label: {  
ButtonView(text: “Rm 107”)  
}  
Spacer()  
Button {  
// show room 108  
} label: {  
ButtonView(text: “Rm 108”)  
}  
}  
HStack {  
Button {  
// show room 118  
} label: {  
ButtonView(text: “Rm 118”)  
}  
Spacer()  
Button {  
// show room 120  
} label: {  
ButtonView(text: “Rm 120”)  
}  
}  
Button {  
// show room 120  
} label: {  
ButtonView(text: “Q-Lab”)  
}  
}  
}  
}  
struct BackgroundView\_Previews: PreviewProvider {  
@Binding var rm104IsShowing: Bool  
static var previews: some View {  
BackgroundView()  
BackgroundView()  
.preferredColorScheme(.dark)  
.previewDevice(“iPhone 15”)  
}  
}  
///

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [June 21, 2024, 1:49am UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/2 "2024-06-21T01:49:39Z")

</div>

Hi @seanec - would you be kind enough to repost/edit your code? It’s broken up and difficult to read. Try using the three backticks, followed by swift ` ` `swift (without the spaces) and put the code after, then three backticks to close the code. Thanks!

---

<div class="post-metadata">

**Author:** ![seanec](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/seanec/32/105896_2.png) [@seanec](https://forums.kodeco.com/u/seanec)\
**Post date:** [June 21, 2024, 11:45am UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/3 "2024-06-21T11:45:12Z")

</div>

Thanks Roberto for the suggestion. Hopefully it’s more readable now. I appreciate any suggestions you can provide.

---

<div class="post-metadata">

**Author:** ![marcst](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@marcst](https://forums.kodeco.com/u/marcst)\
**Post date:** [June 22, 2024, 3:55am UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/4 "2024-06-22T03:55:36Z")

</div>

You directly added the .sheet() statement to the button. Try adding it to the main view instead…

---

<div class="post-metadata">

**Author:** ![seanec](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/seanec/32/105896_2.png) [@seanec](https://forums.kodeco.com/u/seanec)\
**Post date:** [June 24, 2024, 11:42am UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/5 "2024-06-24T11:42:19Z")

</div>

Thanks for the support. I tried as you suggested and it still will not slide a sheet in. I thought it did have to be attached to the button in order for it to work when the button is tapped. I also tried to put it in a ZStack to see if that would help but to no avail. Still stuck on this one

---

<div class="post-metadata">

**Author:** ![seanec](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/seanec/32/105896_2.png) [@seanec](https://forums.kodeco.com/u/seanec)\
**Post date:** [June 28, 2024, 5:51pm UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/6 "2024-06-28T17:51:26Z")

</div>

> [@seanec](#):
>
> Button {  
> Wetlab104IsShowing = true  
> } label: {  
> ButtonView(text: “Rm 104”)  
> }

I finally got the sheet to slide in. Unfortunately I had to remove my ButtonView() which had all the styling for the button and then add the styling to each button individually. In an app with many buttons that makes for a lot of repeat code. I was hoping to style the buttons once in a separate view then bring that in for each button. Is this possible. Perhaps I should not be using a view to do this but something else?

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [June 28, 2024, 8:10pm UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/7 "2024-06-28T20:10:22Z")

</div>

Yes, you want to do that. It will keep the code cleaner and DRY (Don’t Repeat Yourself).

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [December 4, 2024, 9:06am UTC](https://forums.kodeco.com/t/trouble-with-getting-a-sheet-to-slide-into-view/205081/8 "2024-12-04T09:06:12Z")

</div>

Closed on December 4, 2024, 9:06am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
