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
[TIMOB-16596] Android: Animation anchorPoints not working #10007
Conversation
Generated by 🚫 dangerJS |
@@ -360,7 +360,7 @@ private AnimatorSet buildPropertyAnimators(int x, int y, int w, int h, int paren | |||
for (Operation operation : operations) { | |||
if (operation.anchorX != Ti2DMatrix.DEFAULT_ANCHOR_VALUE | |||
|| operation.anchorY != Ti2DMatrix.DEFAULT_ANCHOR_VALUE) { | |||
setAnchor(w, h, operation.anchorX, operation.anchorY); | |||
setAnchor(w, h, anchorX, anchorY); |
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 the if-condition should be written like the below.
final float EPSILON = Math.ulp(1.0f);
boolean hasAnchorXChanged = (Math.abs(operation.anchorX - anchorX) >= EPSILON);
boolean hasAnchorYChanged = (Math.abs(operation.anchorY - anchorY) >= EPSILON);
if (hasAnchorXChanged || hasAnchorYChanged) {
setAnchor(w, h, anchorX, anchorY);
}
This way if the first time the operations were using DEFAULT_ANCHOR_VALUE
and the anchor was changed to something else, then the operations would be updated instead of locking-in to using the previous values. The above effectively doing operation.anchorX != anchorX
, but with floats.
(I've never played with this code before. So, hopefully I'm understanding things correctly. Am I right?)
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 don't think that's what was intended. The test case has an animation with anchor point that is different by the default one, which is then followed by an animation with the default one. And this will result in playing the first animation twice, because the difference will be less than EPSILON.
I also found out that we can have anchorPoint as a parameter in the creation dictionary of Ti.UI.2DMatrix. And my changes totally ignore that, which is not OK. So I will revisit the code, check what is the priority on iOS and fix it.
@jquick-axway I have updated the PR. Now the animation will use
|
@ypbnv , I see that |
@@ -412,6 +412,10 @@ private AnimatorSet buildPropertyAnimators(int x, int y, int w, int h, int paren | |||
} | |||
} | |||
|
|||
if (anchorX != Ti2DMatrix.DEFAULT_ANCHOR_VALUE && anchorY != Ti2DMatrix.DEFAULT_ANCHOR_VALUE) { | |||
setAnchor(w, h, anchorX, anchorY); | |||
} |
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.
Your if-check should be doing an OR ||
, not an AND &&
.
@ypbnv, can you also remove all of the |
Remove PRE_HONEYCOMB checks. Improve default anchorPoints check.
@jquick-axway , @lokeshchdhry Updated with fix for API 16-19. I don't like the way it is done, but couldn't figure out anything else. I assume this is the reason for it: To me it looks like it was not accounting if the pivot point was explicitly set and since 0 matched with the default values in TransformationInfo class it just ignored it. Also removed unused code and improved the current check for default anchorPoint coordinates. |
// case. | ||
if (PRE_LOLLIPOP && thisAnchorX == 0 && thisAnchorY == 0) { | ||
pivotX++; | ||
pivotY++; |
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.
Pivot is a normalized value between 0.0 and 1.0.
So, if given pivot is (0,0) which is the top-left corner, then adding 1 to both will make it pivot at the bottom-right corner, right?
Perhaps adding epsilon would be better?
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.
On our end - yes, it is between 0.0 and 1.0. In the Android code it is passed as pixels.
view.setPivotX() leads to
https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/view/RenderNode.java#632
It is multiplied by the view's dimensions here:
https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/util/TiAnimationBuilder.java#L1484
and here:
https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/util/TiAnimationBuilder.java#L1488
So in the end it will set the pivot point in the pixel in position (1,1).
Increasing them with EPSILON will work, too. And it will be closer to the expected result.
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.
Ahh... thanks man. I didn't know that. :)
Fix comment typo.
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.
CR: Pass
FR Passed. Animation anchor points works as expected. Studio Ver: 5.1.0.201804230827 |
JIRA: https://jira.appcelerator.org/browse/TIMOB-16596
Description:
Use Animation's anchorPoint property instead of Operation's.
Note: Currently no unit tests can be added for this. They will be included in an upcoming PR addressing other issues with animation that prevents this.
Test case:
In the JIRA ticket.
app.js