Skip to content

Commit f54ebbb

Browse files
authored
fix(ios): Shadow layer origin point update (#10376)
1 parent 39eed52 commit f54ebbb

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

packages/core/ui/core/view/index.ios.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ export class View extends ViewCommon implements ViewDefinition {
169169
CATransaction.setDisableActions(true);
170170

171171
if (nativeView.outerShadowContainerLayer) {
172+
const { x: originX, y: originY }: CGPoint = nativeView.outerShadowContainerLayer.anchorPoint;
172173
nativeView.outerShadowContainerLayer.bounds = nativeView.bounds;
173-
nativeView.outerShadowContainerLayer.position = CGPointMake(frame.origin.x + frame.size.width / 2, frame.origin.y + frame.size.height / 2);
174+
nativeView.outerShadowContainerLayer.position = CGPointMake(frame.origin.x + frame.size.width * originX, frame.origin.y + frame.size.height * originY);
174175
}
175176

176177
CATransaction.setDisableActions(false);
@@ -450,11 +451,27 @@ export class View extends ViewCommon implements ViewDefinition {
450451
}
451452

452453
public updateOriginPoint(originX: number, originY: number) {
454+
const nativeView: NativeScriptUIView = <NativeScriptUIView>this.nativeViewProtected;
453455
const newPoint = CGPointMake(originX, originY);
454-
this.nativeViewProtected.layer.anchorPoint = newPoint;
456+
457+
// Disable CALayer animatable property changes
458+
CATransaction.setDisableActions(true);
459+
460+
nativeView.layer.anchorPoint = newPoint;
455461
if (this._cachedFrame) {
456-
this._setNativeViewFrame(this.nativeViewProtected, this._cachedFrame);
462+
this._setNativeViewFrame(nativeView, this._cachedFrame);
463+
}
464+
465+
// Make sure new origin also applies to outer shadow layers
466+
if (nativeView.outerShadowContainerLayer) {
467+
// This is the new frame after view origin point update
468+
const frame = nativeView.frame;
469+
470+
nativeView.outerShadowContainerLayer.anchorPoint = newPoint;
471+
nativeView.outerShadowContainerLayer.position = CGPointMake(frame.origin.x + frame.size.width * originX, frame.origin.y + frame.size.height * originY);
457472
}
473+
474+
CATransaction.setDisableActions(false);
458475
}
459476

460477
// By default we update the view's presentation layer when setting backgroundColor and opacity properties.

packages/core/ui/styling/background.ios.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,12 @@ function drawBoxShadow(view: View): void {
11251125
}
11261126
}
11271127

1128-
// Since shadow layer is added to view layer's superlayer, we have to be more specific about shadow layer position
11291128
outerShadowContainerLayer.bounds = bounds;
1130-
outerShadowContainerLayer.position = CGPointMake(viewFrame.origin.x + viewFrame.size.width / 2, viewFrame.origin.y + viewFrame.size.height / 2);
1129+
outerShadowContainerLayer.anchorPoint = layer.anchorPoint;
1130+
1131+
// Since shadow uses superlayer's coordinate system, we have to be more specific about shadow layer position
1132+
const { x: originX, y: originY }: CGPoint = outerShadowContainerLayer.anchorPoint;
1133+
outerShadowContainerLayer.position = CGPointMake(viewFrame.origin.x + viewFrame.size.width * originX, viewFrame.origin.y + viewFrame.size.height * originY);
11311134

11321135
// Inherit view visibility values
11331136
outerShadowContainerLayer.opacity = layer.opacity;

0 commit comments

Comments
 (0)