In the last exercise we want to use containers to create a responsive screen. Again we are trying to copy the twitter page.
The twitter page has roughly 4 different layouts depending on its size.
Size 1 is for mobile with a menu on the bottom (not shown).
The other 3 look like this:
- Identify the main containers
- Create a container structure for the largest screen
- Add size breakpoints
- Show and hide the containers depending on size
- Add our component and a bit more
- Add the messages box
- Add the mobile view
- Add a tweet overlay
First of all we change the settings of our app, so our window will behave responsive.
In the display settings we turn Scale to fit off
. This will allow Power Apps to always use the available space to display our app.
We won't display too much detail, but want to use the main containers twitter consists of.
The left container is the home of the menu, tweet-button ad logo.
In the middle container we will have the timeline or other elements we selected in the menu (we won't actually build anything detailed here).
The right container shows the trends and a search bar.
The messages container floats in the bottom right corner and is expandable to the top.
We will create the structure for the left, middle and right container.
First we create a new horizontal Container
which will contain the other 3. We will call it con_main
.
Set the Width to Parent.Width
and Height to Parent.Height
, which makes sure that it always fills the whole screen.
We also set LayoutJustifyContent to LayoutJustifyContent.Center
to make sure we will center everything if there is leftover space.
Next we will create 3 vertical Container
we will call con_left
, con_middle
and con_right
. We will set the Height of all of those to Parent.Height
. And we will add some semi-transparent fill-colors, so we can distinguish them better.
The result should look like this:
We will turn the Flexible width of all containers off
. (That sets FillPortions to 0
).
We set the following Width for the containers:
- left:
260
- middle:
600
- right:
350
When you look closely at the twitter page you will notice a gap between the middle and right container.
We will add a label to con_main
and call it lbl_spacer
. Delete the Text and set Width to 40
. We know place it between con_middle
and con_right
.
The result should look like this:
We will now define the SizeBreakpoints of our App Object. We will set them to [700, 1080, 1300]
.
This means we want to distinguish between 4 different Layouts:
Size1
: ScreenWidth smaller 700 pxSize2
: ScreenWidth bigger 700 px, but smaller 1080 pxSize3
: ScreenWidth bigger 1080 px, but smaller 1300 pxSize4
: ScreenWidth bigger 1300 px
Layoutwise this means for us:
Size4
: everything visible and at full sizeSize3
: everything visible andcon_left
at reduzed sizeSize2
:con_right
hidden andcon_left
at reduzed sizeSize1
: mobile (we'll leave that for the side quest)
For the last step we simply need to hide the obejcts we don't need for our layout.
We set the Visible property of con_right
and lbl_spacer
to Screen1.Size >=3
.
Now we set the Width of con_left
to If(Screen1.Size=4, 260, 80)
.
And that is it, we successfully created the frame of our responsive layout. Publish your App and try it out in the browser and on your phone and start filling it with content in the side quests.
Add as much as you like.
Build a message box that hovers in the bottom right corner in Size4
.
Add a simple mobile view that just consists of con_middle
and a horizontal menu underneath.
Great exercise to use more nested containers: