Skip to content

Commit

Permalink
Add very basic box-shadow support (#14028)
Browse files Browse the repository at this point in the history
* Add very basic box-shadow support

* Change files
  • Loading branch information
acoates-ms authored Oct 24, 2024
1 parent 96f969e commit 19b6aba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add very basic box-shadow support",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1245,18 +1245,26 @@ void ComponentView::updateShadowProps(
// Shadow Properties
if (oldViewProps.shadowOffset != newViewProps.shadowOffset || oldViewProps.shadowColor != newViewProps.shadowColor ||
oldViewProps.shadowOpacity != newViewProps.shadowOpacity ||
oldViewProps.shadowRadius != newViewProps.shadowRadius) {
oldViewProps.shadowRadius != newViewProps.shadowRadius || oldViewProps.boxShadow != newViewProps.boxShadow) {
applyShadowProps(newViewProps);
}
}

void ComponentView::applyShadowProps(const facebook::react::ViewProps &viewProps) noexcept {
auto shadow = m_compContext.CreateDropShadow();
shadow.Offset({viewProps.shadowOffset.width, viewProps.shadowOffset.height, 0});
shadow.Opacity(viewProps.shadowOpacity);
shadow.BlurRadius(viewProps.shadowRadius);
if (viewProps.shadowColor)
shadow.Color(theme()->Color(*viewProps.shadowColor));
if (!viewProps.boxShadow.empty()) {
shadow.Offset({viewProps.boxShadow[0].offsetX, viewProps.boxShadow[0].offsetY, 0});
shadow.Opacity(1);
shadow.BlurRadius(viewProps.boxShadow[0].blurRadius);
shadow.Color(theme()->Color(*viewProps.boxShadow[0].color));
} else {
shadow.Offset({viewProps.shadowOffset.width, viewProps.shadowOffset.height, 0});
shadow.Opacity(viewProps.shadowOpacity);
shadow.BlurRadius(viewProps.shadowRadius);
if (viewProps.shadowColor)
shadow.Color(theme()->Color(*viewProps.shadowColor));
}

Visual().as<winrt::Microsoft::ReactNative::Composition::Experimental::ISpriteVisual>().Shadow(shadow);
}

Expand Down

0 comments on commit 19b6aba

Please sign in to comment.