Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow container #638

Merged
merged 34 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
615614e
feat(ShadowContainer): added shadow container component with sample a…
roubachof May 5, 2023
2f9323b
docs: added remarks for shadows
roubachof May 16, 2023
98dbdd8
fix: style cleanup after pr review
roubachof May 29, 2023
e9f5da5
fix(ShadowContainer): fixes the weird compilation issue asking to ref…
roubachof May 31, 2023
5d6fff1
feat(ShadowContainer): inner shadows implementation
roubachof Jun 5, 2023
c18a3b2
style: ShadowContainer.xaml wasn't in mixed mode (tabs + spaces)
roubachof Jun 5, 2023
91ad1b4
style: fixes after pr review
roubachof Jun 6, 2023
f29a5ac
chore: update SkiaSharp packages to 2.88.3
eriklimakc Jul 6, 2023
c5c0c14
build: fix winui packages errors
Xiaoy312 Jul 10, 2023
159d055
ci: Forcing IsUiAutomationMappingEnabled to true on wasm
eriklimakc Jul 13, 2023
294df6a
ci: Attempt to build with Skia preview.84
eriklimakc Jul 14, 2023
a8f2318
chore: SkiaSharp.Views on 2.88.3
eriklimakc Jul 18, 2023
7b07285
ci: Update chrome driver
jeromelaban Jul 18, 2023
d149267
chore: Solving comments after review
eriklimakc Jul 19, 2023
fa8f428
chore: Solving comments after review
eriklimakc Jul 20, 2023
c04a3f9
chore: SkiaSharp Bump to 2.88.4-preview.84
eriklimakc Jul 20, 2023
29456e4
chore: Inverting logic for SizeChanged
eriklimakc Jul 21, 2023
7dcf507
fix: dispatch measure invalidation
kazo0 Jul 24, 2023
7926622
fix: allow empty shadow list when resizing canvas
kazo0 Jul 24, 2023
9ac07b2
fix: update shadow subscription logic
kazo0 Jul 25, 2023
905831c
fix: add corner radius subscription
kazo0 Jul 25, 2023
eed6b71
chore: add tests
kazo0 Jul 26, 2023
44bdea0
fix: remove IsNegative call
kazo0 Jul 26, 2023
586a733
feat: add new Toolkit.Skia packages
kazo0 Jul 26, 2023
d44ac1b
ci: update to 7.0.302
kazo0 Jul 27, 2023
b30e3e0
ci: update uno.check
kazo0 Jul 27, 2023
b35c472
build: remove uwp skia package
kazo0 Jul 31, 2023
79676e4
ci: uno-check version
kazo0 Aug 1, 2023
713d775
fix(WinUI): Lambda func method call to avoid cast exception
eriklimakc Jul 31, 2023
0d943a0
docs: Adjusting Shadows docs after review
eriklimakc Jul 31, 2023
d8d9b93
ci: revert unocheck version
kazo0 Aug 1, 2023
ee5bf38
chore: remove winui specific files from uwp
Xiaoy312 Aug 1, 2023
ca3b4e0
build: fix csproj
kazo0 Aug 2, 2023
6a1bff6
Merge branch 'main' into dev/jmaf/shadow-container
kazo0 Aug 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/workflow/scripts/wasm-uitest-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fi

cd $BUILD_SOURCESDIRECTORY/build/$SAMPLEAPP_ARTIFACT_NAME

npm i chromedriver@86.0.0
npm i puppeteer@5.3.1
npm i chromedriver@102.0.0
npm i puppeteer@14.1.0

# install dotnet serve / Remove as needed
dotnet tool uninstall dotnet-serve -g || true
Expand All @@ -27,7 +27,7 @@ export PATH="$PATH:$BUILD_SOURCESDIRECTORY/build/tools"
export BASE_ARTIFACTS_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/wasm/$XAML_FLAVOR_BUILD/$UITEST_TEST_MODE_NAME
export UNO_UITEST_TARGETURI=http://localhost:5000
export UNO_UITEST_DRIVERPATH_CHROME=$BUILD_SOURCESDIRECTORY/build/$SAMPLEAPP_ARTIFACT_NAME/node_modules/chromedriver/lib/chromedriver
export UNO_UITEST_CHROME_BINARY_PATH=$BUILD_SOURCESDIRECTORY/build/$SAMPLEAPP_ARTIFACT_NAME/node_modules/puppeteer/.local-chromium/linux-800071/chrome-linux/chrome
export UNO_UITEST_CHROME_BINARY_PATH=$BUILD_SOURCESDIRECTORY/build/$SAMPLEAPP_ARTIFACT_NAME/node_modules/puppeteer/.local-chromium/linux-991974/chrome-linux/chrome
export UNO_UITEST_SCREENSHOT_PATH=$BASE_ARTIFACTS_PATH/screenshots
export UNO_UITEST_PLATFORM=Browser
export UNO_UITEST_CHROME_CONTAINER_MODE=true
Expand Down
2 changes: 1 addition & 1 deletion build/workflow/stage-uitests-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
- task: DownloadBuildArtifacts@0
displayName: 'Download UITest Binaries'
inputs:
artifactName: toolkit-uitest-binaries
artifactName: toolkit-uitest-binaries-$(XAML_FLAVOR_BUILD)
downloadPath: '$(build.sourcesdirectory)/build'

- template: templates/dotnet-workload-install-mac.yml
Expand Down
12 changes: 10 additions & 2 deletions build/workflow/stage-uitests-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ jobs:
- job: Toolkit_UITests_Build
displayName: 'Build Toolkit UI Tests'

strategy:
maxParallel: 2
matrix:
UWP:
XAML_FLAVOR_BUILD: UWP
WinUI:
XAML_FLAVOR_BUILD: WinUI

variables:
CI_Build: true

Expand All @@ -18,7 +26,7 @@ jobs:
displayName: 'Build UI Tests'
inputs:
solution: src/Uno.Toolkit.UITest/Uno.Toolkit.UITest.csproj
msbuildArguments: /r /m /p:Configuration=Release /detailedsummary /m /bl:$(build.artifactstagingdirectory)\build.binlog
msbuildArguments: /r /m /p:Configuration=Release /p:FrameworkLineage=$(XAML_FLAVOR_BUILD) /detailedsummary /m /bl:$(build.artifactstagingdirectory)\build.binlog

- task: CopyFiles@2
displayName: 'Publish UITest binaries'
Expand All @@ -34,5 +42,5 @@ jobs:
retryCountOnTaskFailure: 3
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
ArtifactName: toolkit-uitest-binaries
ArtifactName: toolkit-uitest-binaries-$(XAML_FLAVOR_BUILD)
ArtifactType: Container
2 changes: 1 addition & 1 deletion build/workflow/stage-uitests-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
- task: DownloadBuildArtifacts@0
displayName: 'Download UITest Binaries'
inputs:
artifactName: toolkit-uitest-binaries
artifactName: toolkit-uitest-binaries-$(XAML_FLAVOR_BUILD)
downloadPath: '$(build.sourcesdirectory)/build'

- template: templates/dotnet-workload-install-mac.yml
Expand Down
2 changes: 1 addition & 1 deletion build/workflow/stage-uitests-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
- task: DownloadBuildArtifacts@0
displayName: 'Download UITest Binaries'
inputs:
artifactName: toolkit-uitest-binaries
artifactName: toolkit-uitest-binaries-$(XAML_FLAVOR_BUILD)
downloadPath: '$(build.sourcesdirectory)/build'

- task: UseDotNet@2
Expand Down
6 changes: 3 additions & 3 deletions build/workflow/templates/dotnet-workload-install-mac.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
DotNetVersion: '7.0.102'
UnoCheck_Version: '1.11.0-dev.2'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/146b0b4b23d866bef455494a12ad7ffd2f6f2d20/manifests/uno.ui.manifest.json'
DotNetVersion: '7.0.302'
UnoCheck_Version: '1.13.0'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/c3b289d7bb16a2a2df7f7f7f848d76fe1e74036d/manifests/uno.ui.manifest.json'
Dotnet_Root: '/usr/local/share/dotnet/'
Dotnet_Tools: '~/.dotnet/tools'

Expand Down
6 changes: 3 additions & 3 deletions build/workflow/templates/dotnet-workload-install-windows.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
DotNetVersion: '7.0.102'
UnoCheck_Version: '1.11.0-dev.2'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/146b0b4b23d866bef455494a12ad7ffd2f6f2d20/manifests/uno.ui.manifest.json'
DotNetVersion: '7.0.302'
UnoCheck_Version: '1.13.0'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/c3b289d7bb16a2a2df7f7f7f848d76fe1e74036d/manifests/uno.ui.manifest.json'

steps:

Expand Down
Binary file added doc/assets/shadows-colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/assets/shadows-neumorphism.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion doc/controls-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ The `Uno.Toolkit.UI` library adds the following controls:
- [`DrawerControl`](controls/DrawerControl.md): A container to display additional content, in a hidden pane that can be revealed using a swipe gesture, like a drawer.
- [`DrawerFlyoutPresenter`](controls/DrawerFlyoutPresenter.md): A specialized `ContentPresenter` to be used in the template of a `FlyoutPresenter` to enable gesture support.
- [`LoadingView`](controls/LoadingView.md): A control that indicates that the UI is waiting on a task to complete.
- [`TabBar` and `TabBarItem`](controls/TabBarAndTabBarItem.md): A list of selectable items that can be used to facilitate lateral navigation within an application.
- [`NavigationBar`](controls/NavigationBar.md): A custom control that helps implement navigation logic for your application.
- [`ShadowContainer`](controls/ShadowContainer.md): A content control allowing you to add multiple shadows to your content.
- [`TabBar` and `TabBarItem`](controls/TabBarAndTabBarItem.md): A list of selectable items that can be used to facilitate lateral navigation within an application.

## Helpers
The `Uno.Toolkit.UI` library adds the following helper classes:
Expand Down
288 changes: 288 additions & 0 deletions doc/controls/ShadowContainer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
---
uid: Toolkit.Controls.ShadowContainer
---

## Summary
The `ShadowContainer` provides the possibility to add many-colored shadows to its content.

## Remarks
For now, the control simply adapts its corner radius to the content's corner radius. More complicated shapes, such as text or pictures with alpha, are not supported.

### XAML
```xml
xmlns:utu="using:Uno.Toolkit.UI"
...

<utu:ShadowContainer>
<utu:ShadowContainer.Shadows>
<utu:ShadowCollection>
<utu:Shadow ... />
<utu:Shadow ... />
</utu:ShadowCollection>
</utu:ShadowContainer.Shadows>

<SomeControl />

</utu:ShadowContainer>
```

### Inheritance
Object &#8594; DependencyObject &#8594; UIElement &#8594; FrameworkElement &#8594; Control &#8594; ContentControl > ShadowContainer

### Properties
| Property | Type | Description |
| -------- | ---------------- | ----------- |
Shadows | ShadowCollection | The collection of shadows that will be displayed under your control. A `ShadowCollection` can be stored in a resource dictionary to have a consistent style throughout your app. The `ShadowCollection` implements `INotifyCollectionChanged`.

## Shadow

Dependency object representing a single shadow.

### Shadow Properties
| Property | Type | Description |
| -------- | ---- | ----------- |
IsInner | bool | True if this shadow is an inner shadow (similar to `inset` of `box-shadow` in CSS).
OffsetX | double | The X offset of the shadow.
OffsetY | double | The Y offset of the shadow.
Color | Color | The color of the shadow. It will be multiplied by the `Opacity` property before rendering.
Opacity | double | The opacity of the shadow.
BlurRadius | double | The radius of the blur that will be applied to the shadow **[0..100]**.
Spread | double | The spread will inflate or deflate (if negative) the control shadow size **before** applying the blur.

## Usage

```xml
eriklimakc marked this conversation as resolved.
Show resolved Hide resolved
xmlns:utu="using:Uno.Toolkit.UI"
...

<Page.Resources>
<Color x:Key="UnoColor">#7a67f8</Color>
<Color x:Key="UnoPink">#f85977</Color>

<!-- You can define your shadows in the resource dictionary -->
<ui:ShadowCollection x:Name="ButtonShadows">
<ui:Shadow BlurRadius="15"
OffsetY="8"
Opacity="0.5"
Color="{StaticResource UnoColor}" />
</ui:ShadowCollection>
</Page.Resources>

<ui:ShadowContainer>
<ui:ShadowContainer.Shadows>
<!-- You can define your shadows directly -->
<ui:ShadowCollection x:Name="Shadows">
<ui:Shadow BlurRadius="20"
OffsetX="10"
OffsetY="10"
Opacity="0.5"
Spread="-5"
Color="{StaticResource UnoColor}" />
<ui:Shadow BlurRadius="20"
OffsetX="-10"
OffsetY="-10"
Opacity="0.5"
Spread="-5"
Color="{StaticResource UnoPink}" />
</ui:ShadowCollection>
</ui:ShadowContainer.Shadows>
<StackPanel Width="300"
Padding="16"
Background="White"
BorderThickness="1"
CornerRadius="20"
Spacing="16">

<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="Add many shadows" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="You can either declare shadows directly, or put your ShadowCollection in a resource dictionary." />

<StackPanel Margin="0,16,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="16">

<!-- Reference to the dictionary button shadows -->
<ui:ShadowContainer Shadows="{StaticResource ButtonShadows}">
<Button Background="{StaticResource UnoColor}"
BorderThickness="1"
Content="Add Shadow"
Foreground="White" />
</ui:ShadowContainer>

<!-- Reference to the dictionary button shadows -->
<ui:ShadowContainer Shadows="{StaticResource ButtonShadows}">
<Button Background="{StaticResource UnoColor}"
BorderThickness="1"
Content="Remove Shadow"
Foreground="White" />
</ui:ShadowContainer>
</StackPanel>
</StackPanel>
</ui:ShadowContainer>
```

![2 colored shadows with 2 buttons with single shadows](../assets/shadows-colors.png)

### Neumorphism

[Following neumorphism rules](https://neumorphism.io), choose one background color, 2 shadow colors, and create a cool neumorphism style.
In order to achieve neumorphic depth effects (instead of having a raised element, it will feel as if it was hollow or bulging), set the `IsInner` property of a shadow to `True`. The shadow will then be displayed *inside* the element instead of behind.
This is equivalent to the `inset` property of the CSS `box-shadow`.

```xml
xmlns:utu="using:Uno.Toolkit.UI"
...

<Page.Resources>
<Color x:Key="UnoColor">#7a67f8</Color>

<ui:ShadowCollection x:Key="NeumorphismRaising">
<!-- Bottom right darker violet -->
<ui:Shadow BlurRadius="30"
OffsetX="10"
OffsetY="10"
Opacity="1"
Spread="-5"
Color="#6858d3" />
<!-- Top left lighter violet -->
<ui:Shadow BlurRadius="30"
OffsetX="-10"
OffsetY="-10"
Opacity="1"
Spread="-5"
Color="#8c76ff" />
</ui:ShadowCollection>

<ui:ShadowCollection x:Key="NeumorphismHollow">
<!-- Inner top and left shadow -->
<ui:Shadow BlurRadius="10"
IsInner="True"
OffsetX="5"
OffsetY="5"
Opacity="1"
Spread="0"
Color="#6858d3" />
<!-- Inner bottom and right shadow -->
<ui:Shadow BlurRadius="10"
IsInner="True"
OffsetX="-4"
OffsetY="-4"
Opacity="1"
Spread="0"
Color="#8c76ff" />
</ui:ShadowCollection>

<ui:ShadowCollection x:Key="NeumorphismBulging">
<ui:Shadow BlurRadius="10"
IsInner="True"
OffsetX="-5"
OffsetY="-5"
Opacity="1"
Spread="0"
Color="#6858d3" />
<ui:Shadow BlurRadius="10"
IsInner="True"
OffsetX="4"
OffsetY="4"
Opacity="1"
Spread="0"
Color="#8c76ff" />
</ui:ShadowCollection>
</Page.Resources>

<StackPanel Width="400"
Margin="0,32"
Padding="32"
Background="{StaticResource UnoColor}"
CornerRadius="30">
<ui:ShadowContainer Shadows="{StaticResource NeumorphismRaising}">
<Grid Width="300"
Padding="20"
Background="{StaticResource UnoColor}"
CornerRadius="20">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>

<TextBlock FontSize="15"
Foreground="White"
Text="Neumorphism" />
<TextBlock Grid.Row="1"
FontSize="12"
Foreground="White"
Text="Raising element" />
</Grid>
</ui:ShadowContainer>

<ui:ShadowContainer Margin="0,60,0,0" Shadows="{StaticResource NeumorphismHollow}">
<TextBox Width="200"
Height="40"
Padding="15,10,15,0"
VerticalAlignment="Center"
Background="{StaticResource UnoColor}"
BorderThickness="0"
CornerRadius="20"
Foreground="White"
PlaceholderForeground="LightGray"
PlaceholderText="Hollow element" />
</ui:ShadowContainer>
<ui:ShadowContainer Margin="0,15" Shadows="{StaticResource NeumorphismHollow}">
<TextBox Width="200"
Height="40"
Padding="15,10,15,0"
VerticalContentAlignment="Center"
Background="{StaticResource UnoColor}"
BorderThickness="0"
CornerRadius="20"
Foreground="White"
PlaceholderForeground="LightGray"
PlaceholderText="Hollow element" />
</ui:ShadowContainer>

<ui:ShadowContainer Margin="0,30" Shadows="{StaticResource NeumorphismBulging}">
<Button Width="200"
Height="40"
Background="{StaticResource UnoColor}"
BorderBrush="{StaticResource UnoColor}"
Content="Bulging element"
CornerRadius="15"
Foreground="White" />
</ui:ShadowContainer>

<StackPanel Margin="0,30,0,0"
Padding="24"
HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="16">

<ui:ShadowContainer Shadows="{StaticResource NeumorphismRaising}">
<Button Background="{StaticResource UnoColor}"
BorderThickness="0"
Content="Regular"
Foreground="White" />
</ui:ShadowContainer>

<ui:ShadowContainer Shadows="{StaticResource NeumorphismRaising}">
<Button Width="80"
Height="80"
Background="{StaticResource UnoColor}"
BorderBrush="{StaticResource UnoColor}"
Content="Circular"
CornerRadius="40"
Foreground="White" />
</ui:ShadowContainer>

<ui:ShadowContainer Shadows="{StaticResource NeumorphismRaising}">
<Button Height="60"
Background="{StaticResource UnoColor}"
BorderThickness="0"
Content="Bigger"
CornerRadius="20"
Foreground="White" />
</ui:ShadowContainer>
</StackPanel>
</StackPanel>
```

![neumorphism built with 2 shadows](../assets/shadows-neumorphism.png)
Loading
Loading