Skip to content

Commit

Permalink
[Fabric] Enable ShadowProps for all Fabric Components (#12108)
Browse files Browse the repository at this point in the history
* extract shadow properties to baseComponentView

* Change files

* Change to updateShadowProps

Co-authored-by: Jon Thysell <thysell@gmail.com>

---------

Co-authored-by: Jon Thysell <thysell@gmail.com>
  • Loading branch information
TatianaKapos and jonthysell authored Sep 6, 2023
1 parent fc4ca0a commit cff3261
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "extract shadow properties to baseComponentView",
"packageName": "react-native-windows",
"email": "tatianakapos@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,24 @@ void CompositionBaseComponentView::updateBorderProps(
}
}

void CompositionBaseComponentView::updateShadowProps(
const facebook::react::ViewProps &oldViewProps,
const facebook::react::ViewProps &newViewProps,
winrt::Microsoft::ReactNative::Composition::ISpriteVisual m_visual) noexcept {
// Shadow Properties
if (oldViewProps.shadowOffset != newViewProps.shadowOffset || oldViewProps.shadowColor != newViewProps.shadowColor ||
oldViewProps.shadowOpacity != newViewProps.shadowOpacity ||
oldViewProps.shadowRadius != newViewProps.shadowRadius) {
auto shadow = m_compContext.CreateDropShadow();
shadow.Offset({newViewProps.shadowOffset.width, newViewProps.shadowOffset.height, 0});
shadow.Opacity(newViewProps.shadowOpacity);
shadow.BlurRadius(newViewProps.shadowRadius);
if (newViewProps.shadowColor)
shadow.Color(newViewProps.shadowColor.AsWindowsColor());
m_visual.Shadow(shadow);
}
}

void CompositionBaseComponentView::updateAccessibilityProps(
const facebook::react::ViewProps &oldViewProps,
const facebook::react::ViewProps &newViewProps) noexcept {
Expand Down Expand Up @@ -1288,19 +1306,7 @@ void CompositionViewComponentView::updateProps(

updateAccessibilityProps(oldViewProps, newViewProps);
updateBorderProps(oldViewProps, newViewProps);

// Shadow
if (oldViewProps.shadowOffset != newViewProps.shadowOffset || oldViewProps.shadowColor != newViewProps.shadowColor ||
oldViewProps.shadowOpacity != newViewProps.shadowOpacity ||
oldViewProps.shadowRadius != newViewProps.shadowRadius) {
auto shadow = m_compContext.CreateDropShadow();
shadow.Offset({newViewProps.shadowOffset.width, newViewProps.shadowOffset.height, 0});
shadow.Opacity(newViewProps.shadowOpacity);
shadow.BlurRadius(newViewProps.shadowRadius);
if (newViewProps.shadowColor)
shadow.Color(newViewProps.shadowColor.AsWindowsColor());
m_visual.Shadow(shadow);
}
updateShadowProps(oldViewProps, newViewProps, m_visual);

if (oldViewProps.backfaceVisibility != newViewProps.backfaceVisibility) {
static_assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ struct CompositionBaseComponentView : public IComponentView,
void updateBorderProps(
const facebook::react::ViewProps &oldViewProps,
const facebook::react::ViewProps &newViewProps) noexcept;
void updateShadowProps(
const facebook::react::ViewProps &oldViewProps,
const facebook::react::ViewProps &newViewProps,
winrt::Microsoft::ReactNative::Composition::ISpriteVisual m_visual) noexcept;
void updateAccessibilityProps(
const facebook::react::ViewProps &oldView,
const facebook::react::ViewProps &newViewProps) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void ImageComponentView::updateProps(

ensureVisual();

updateShadowProps(oldImageProps, newImageProps, m_visual);
updateBorderProps(oldImageProps, newImageProps);

if (oldImageProps.backgroundColor != newImageProps.backgroundColor ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void ParagraphComponentView::updateProps(
updateTextAlignment(newViewProps.textAttributes.alignment);
}

updateShadowProps(oldViewProps, newViewProps, m_visual);
updateAccessibilityProps(oldViewProps, newViewProps);
updateBorderProps(oldViewProps, newViewProps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void ScrollViewComponentView::updateProps(
}
*/

updateShadowProps(oldViewProps, newViewProps, m_visual);
updateBorderProps(oldViewProps, newViewProps);
m_props = std::static_pointer_cast<facebook::react::ViewProps const>(props);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
void updateContentVisualSize() noexcept;

facebook::react::Size m_contentSize;
winrt::Microsoft::ReactNative::Composition::IVisual m_visual{nullptr};
winrt::Microsoft::ReactNative::Composition::ISpriteVisual m_visual{nullptr};
winrt::Microsoft::ReactNative::Composition::IScrollVisual m_scrollVisual{nullptr};
winrt::Microsoft::ReactNative::Composition::IScrollVisual::ScrollPositionChanged_revoker
m_scrollPositionChangedRevoker{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void SwitchComponentView::updateProps(
m_drawingSurface = nullptr;
}

updateShadowProps(oldViewProps, newViewProps, m_visual);
updateBorderProps(oldViewProps, newViewProps);
m_props = std::static_pointer_cast<facebook::react::ViewProps const>(props);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ void WindowsTextInputComponentView::updateProps(

ensureVisual();

updateShadowProps(oldTextInputProps, newTextInputProps, m_visual);
updateBorderProps(oldTextInputProps, newTextInputProps);

if (!facebook::react::floatEquality(
Expand Down

0 comments on commit cff3261

Please sign in to comment.