The second exercise will be all about containers. First we'll be building a modal that you need in every Canvas App.
- Create the container structure
- Populate the inner container
- Show and hide the modal
- Make the height of the modal responsive
- add a second button
- Create a background blur effect
We will continue with a new screen in our existing app.
First, we need to insert a vertical container, that covers the whole screen.
- make sure to set the
X
andY
properties to0
- set
Width
toParent.Width
- set
Height
toParent.Height
- set
Fill
toRGBA(0, 0, 0, 0.5)
which will grey out the background, while the modal is visible
Inside this container we will create another vertical container
- set
Width
to400
- set
Height
to300
(change later to an appropriate amount) - set
Fill
toColor.White
- set
Border Radius
to4
- set all the
Padding
properties to16
- set
Gap
to8
Now we center the inner container. Select the outer container and set Justify
and Align
Center
.
Add some content to the inner container. Make sure to create a Close-Icon on top and a Button on the bottom to confirm your action. Align all the content in the container as needed. (Close-Icon to the right, stretch labels, center the button)
This shouldn't be new for you. We will create a local variable that triggers the visibility of the outer container.
- create an Icon or Button and set the
OnSelect
toUpdateContext({locShowModal: true})
- set the
OnSelect
of the Close-Icon toUpdateContext({locShowModal: false})
- set the
Visible
property of the outer container tolocShowModal
Small tip if you don't know the exact height of your modal (for example, when there are auto-height texts inside):
You set the Height
of the inner container to the position of the last element inside it:
btn_Confirm.Y+btn_Confirm.Height+Self.PaddingBottom
This should be the result:
Modals with two side by side buttons are pretty common. Add a horizontal container inside to position the 2 buttons.
Use an html-Text to create a blurre background instead of the greyed out background. You can get the css code in this Glassmorphism-Generator.