-
Notifications
You must be signed in to change notification settings - Fork 28
Description
A shot at a platform-agnostic implementation of the famous collapsible toolbar layout UX.
Could implement successfully #325.
A CollapsibleToolbarLayout has 2 main properties
| Name | Type | Description |
|---|---|---|
| Toolbar | ICollapsibleToolbar |
the toolbar to be collapsed or expanded |
| Content | object |
the body of page that will be wrapped in a ScrollViewer |
interface ICollapsibleToolbar
{
TextBlock Title { get; }
Brush Background { get; }
/// <summary>
/// Called when the collapsible layout header height is changing (in fact it is just scroll up)
/// </summary>
/// <param name="state">The current state of the layout.</param>
/// <param name="expandedRatio">The expanded ratio: 1 is fully expanded (the state will be Expanded), 0 fully collapsed (Collapsed), else would be InBetween.</param>
void OnCollapsing(CollapsibleLayoutState state, double expandedRatio);
}For now, we have the NavigationBar in the toolkit, so we could just made it implement ICollapsibleToolbar.
Now we would like also to support collapsibles background images:
I propose the following properties:
| Name | Type | Description |
|---|---|---|
| ExpandedHeight | double |
the bar height when expanded |
| State | CollapsibleToolbarLayoutState |
enum: Collapsed, InBetween, Expanded |
| ExpandedTitleMargin | Thickness |
the title margins when expanded |
| ExpandedTitleFontSize | double |
the title font size when expanded |
| ExpandedImage | sting |
the image path displayed on the background when expanded |
The pseudo-xaml implementation would look like this:
<Grid>
<ScrollViewer>
<StackPanel>
<ExpandedToolbarContent>
<Content>
<StackPanel>
</ScrollViewer>
<Toolbar>
</Grid>Basically the 'ExpandedToolbarContent' would contain the expanded UI, the title with expanded title font size and the background image.
And we used it like this:
<CollapsibleToolbarLayout ExpandedHeight="160"
State="Expanded"
ExpandedTitleFontSize="26"
ExpandedImage="MontrealSnowTornado.png">
<CollapsibleToolbarLayout.Toolbar>
<Toolbar />
</CollapsibleToolbarLayout.Toolbar>
</CollapsibleToolbarLayout>Use case: from expanded to collapsed
We are in expanded state: the ExpandedToolbarContent is displaying a montreal image in the background and a title with a font size of 26, height is 160dp.
In this state the Toolbar background is transparent, and the title is hidden, its CollapsibleState = "Expanded".
Our CollapsibleToolbarLayout state = "Expanded".
- Scroll up is detected. Our
CollapsibleToolbarLayoutand ourToolbarstates = "InBetween". - Thanks to interpolation based on the bottom of the
ExpandedToolbarContentrespectively to the Y scroll axis we are slowly fading background from image to our toolbar background. And scaling title font size toToolbarfont size. - When the bottom of the
ExpandedToolbarContentreaches the bottom of theToolbar, we set ourCollapsibleToolbarLayoutstate to "Collapsed". We also setToolbarstates = "Collapsed". It does make visible theToolbarbackground and title.
This way we can mimic with little effort a collapsible bar.
