-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
add transformOrigin style property #2106
add transformOrigin style property #2106
Conversation
@lelandrichardson any more work on this? |
👍 |
function _normalizeOrigin(input: Object): Object { | ||
var output = { x: 0, y: 0, z: 0 }; | ||
invariant( | ||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof input === 'object'
?
Linter says that this code is not reachable.
@lelandrichardson could you fix? That is the only noticeable thing that stops this PR from being accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azproduction sorry for not seeing this sooner. I'm happy to fix this or anything else if that's all that's stopping it.
Do we feel like the other 3 issues I brought up are compromises we are willing to make at this time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is important to have transform-origin
CSS-compatible in order to avoid future collisions and misunderstandings.
By default, a layer's anchorPoint is (0.5, 0.5), which lies at the center of the layer
// Obj-C Fix
view.layer.anchorPoint = CGPointMake(0, 0);
Which could be applied somewhere here in React/Views/RCTViewManager.m
Or even we could make a separate property and avoid matrix math on JS-side. This also fixes 3-rd issue.
RCT_CUSTOM_VIEW_PROPERTY(transformOrigin, RCTTransformOrigin, RCTView)
{
view.layer.anchorPoint = json ? [RCTConvert RCTTransformOrigin:json] : defaultView.layer.anchorPoint;
}
// RCTTransformOrigin and [RCTConvert RCTTransformOrigin] to be defined
// defaultView.layer.anchorPoint to be defined as CGPointMake(0, 0)
- We could use
anchorPoint
instead of multiplying matrixes in order to support%
values (with the default value of 0, 0). - Pixel values we could be casted to
%
usingview.frame
.
@vjeux any ideas how to fix it a better way?
Currently struggling to animate around a specific point, this would be very helpful. Currently using a container to reposition the element I'd like to rotate around a point, and animating that container. |
Any updates on this? 👍 |
ping @lelandrichardson |
@satya164 @danleveille I'm happy to bring this work up to date, but I don't want to waste the time if it will never get merged... Right now I think there are too many issues with this property diverting from the web spec. I'm hoping someone from the core team can comment on next steps or whether or not these differences are small enough to move forward with this PR. |
cc @mkonicek |
Maybe @sahrens has some context? |
Closing since no activity on the PR. let's re-open if you wanna work on it again. |
👍 |
There is still a lot of demand for this. Maybe we could just name it rn-transform-origin or something and get it in? Then we don't have to worry too much about deviating from the spec, and we can implement it correctly in the future without a collision. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
Any update on this? |
This PR has been inactive for a long while, and does not seem to be on a path towards getting merged in. If anyone wants to take over, please do send a new PR. |
This PR was being discussed in this issue: #1964
I've decided to submit a PR just so that the conversation can have a bit more context with the code involved, etc.
transform-origin spec
How it works
the transform origin property works by defining a translation matrix
T
which translates to the desired origin, and transforming a transform matrixM
intoM'
by the following formula:M' = TMT^-1
This is accomplished in the
precomputeStyle
method and only introduces new code paths if thetransformOrigin
property is assigned.Known Issues with this PR
transform-origin: 0px 0px
as placing the transform origin at the bottom left of the transformed element, where-as this code putstransformOrigin: { x: 0, y: 0 }
to mean the center of the element (the default origin). This issue is difficult to remedy because inprecomputeStyle
, we don't have any knowledge of the width/height of the element in order to actually calculate what the "bottom left" of the element would be. For similar reasons, this makes it difficult to include other aspects of the CSS spec for this property, such as percentage values, etc.AnimatedValueXYZ
class would need to be created, or the existingAnimatedXY
class should be extended. I've left untouched for now as thez
property of transformOrigin is seldom needed.transform
style property and thetransformOrigin
style property are not independent of one another, which mens that if we are animating one of them, the other must be included in the passed up style props to.setNativeProps
. In order to accomplish this, a small check was added to theAnimatedStyle::getAnimatedValue()
method. I'm open to suggestions on how we could potentially make this cleaner.Example Usage: